Skip to content

Commit

Permalink
change module name types-typedefs (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
galtay authored Mar 28, 2019
1 parent d9fa7f4 commit 057e6ab
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion qwikidata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"""Metadata for this package."""

__package_name__ = "qwikidata"
__version__ = "0.1.2"
__version__ = "0.1.3"
22 changes: 11 additions & 11 deletions qwikidata/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Sequence
from typing import List, Union, overload

from qwikidata import types as types
from qwikidata import typedefs
from qwikidata.snak import WikidataSnak


Expand Down Expand Up @@ -38,7 +38,7 @@ class WikidataReference:
Maps property id to list of :py:class:`.WikidataSnak`
"""

def __init__(self, reference_dict: types.ReferenceDict) -> None:
def __init__(self, reference_dict: typedefs.ReferenceDict) -> None:
self._validate_reference_dict(reference_dict)
self._reference_dict = reference_dict

Expand All @@ -49,7 +49,7 @@ def __init__(self, reference_dict: types.ReferenceDict) -> None:
WikidataSnak(snak_dict) for snak_dict in reference_dict["snaks"][property_id]
]

def _validate_reference_dict(self, reference_dict: types.ReferenceDict) -> None:
def _validate_reference_dict(self, reference_dict: typedefs.ReferenceDict) -> None:
"""Raise excpetions if reference_dict is not valid."""
_REQUIRED_KEYS = ["hash", "snaks", "snaks-order"]
for req_key in _REQUIRED_KEYS:
Expand Down Expand Up @@ -96,14 +96,14 @@ class WikidataQualifier:
"""

def __init__(self, qualifier_dict: types.QualifierDict) -> None:
def __init__(self, qualifier_dict: typedefs.QualifierDict) -> None:
self._validate_qualifier_dict(qualifier_dict)
self._qualifier_dict = qualifier_dict

self.qualifierhash = qualifier_dict["hash"]
self.snak = WikidataSnak(qualifier_dict)

def _validate_qualifier_dict(self, qualifier_dict: types.QualifierDict) -> None:
def _validate_qualifier_dict(self, qualifier_dict: typedefs.QualifierDict) -> None:
"""Raise excpetions if qualifier_dict is not valid."""
_REQUIRED_KEYS = ["hash", "snaktype", "property", "datavalue", "datatype"]
for req_key in _REQUIRED_KEYS:
Expand Down Expand Up @@ -176,12 +176,12 @@ class WikidataClaim:
.. _the wikibase JSON data model docs: https://www.mediawiki.org/wiki/Wikibase/DataModel/JSON
"""

def __init__(self, claim_dict: types.ClaimDict) -> None:
def __init__(self, claim_dict: typedefs.ClaimDict) -> None:
self._validate_claim_dict(claim_dict)
self._claim_dict = claim_dict
self.property_id = self.mainsnak.property_id

self.qualifiers: OrderedDict[types.PropertyId, List[WikidataQualifier]] = OrderedDict()
self.qualifiers: OrderedDict[typedefs.PropertyId, List[WikidataQualifier]] = OrderedDict()
self.qualifiers_order = claim_dict.get("qualifiers-order", [])
if "qualifiers" in claim_dict:
for property_id in self.qualifiers_order:
Expand All @@ -193,7 +193,7 @@ def __init__(self, claim_dict: types.ClaimDict) -> None:
for reference_dict in claim_dict["references"]:
self.references.append(WikidataReference(reference_dict))

def _validate_claim_dict(self, claim_dict: types.ClaimDict) -> None:
def _validate_claim_dict(self, claim_dict: typedefs.ClaimDict) -> None:
"""Raise excpetions if claim_dict is not valid."""
_REQUIRED_KEYS = ["id", "type", "rank", "mainsnak"]
for req_key in _REQUIRED_KEYS:
Expand Down Expand Up @@ -236,14 +236,14 @@ class WikidataClaimGroup(Sequence):
.. _the wikibase JSON data model docs: https://www.mediawiki.org/wiki/Wikibase/DataModel/JSON
"""

def __init__(self, claim_list: types.ClaimList) -> None:
def __init__(self, claim_list: typedefs.ClaimList) -> None:
super(WikidataClaimGroup, self).__init__()
self._validate_claim_list(claim_list)
self._claim_list = claim_list
self._claims = [WikidataClaim(claim_dict) for claim_dict in claim_list]

property_ids = set([claim.mainsnak.property_id for claim in self._claims])
self.property_id: Union[types.PropertyId, None]
self.property_id: Union[typedefs.PropertyId, None]
if len(property_ids) == 1:
self.property_id = property_ids.pop()
elif len(property_ids) == 0:
Expand All @@ -254,7 +254,7 @@ def __init__(self, claim_list: types.ClaimList) -> None:
f"but found multiple property ids {property_ids}"
)

def _validate_claim_list(self, claim_list: types.ClaimList) -> None:
def _validate_claim_list(self, claim_list: typedefs.ClaimList) -> None:
"""Raise excpetions if claim_list is not valid."""
if not isinstance(claim_list, list):
raise TypeError(f"claim_list must be a list but got {type(claim_list)}.")
Expand Down
20 changes: 10 additions & 10 deletions qwikidata/datavalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import re
from typing import Dict, Union

from qwikidata import types
from qwikidata import typedefs


def _validate_datavalue_dict(datavalue_dict: types.DatavalueDict) -> None:
def _validate_datavalue_dict(datavalue_dict: typedefs.DatavalueDict) -> None:
"""Raise excpetions if datavalue_dict is not valid."""
_REQUIRED_KEYS = ["type", "value"]
for req_key in _REQUIRED_KEYS:
Expand Down Expand Up @@ -58,7 +58,7 @@ class GlobeCoordinate:
`globecoordinate`
"""

def __init__(self, datavalue_dict: types.GlobeCoordinateDatavalueDict) -> None:
def __init__(self, datavalue_dict: typedefs.GlobeCoordinateDatavalueDict) -> None:
_validate_datavalue_dict(datavalue_dict)
self._datavalue_dict = datavalue_dict
self.datatype = datavalue_dict["type"]
Expand Down Expand Up @@ -90,7 +90,7 @@ class MonolingualText:
`monolingualtext`
"""

def __init__(self, datavalue_dict: types.MonolingualTextDatavalueDict) -> None:
def __init__(self, datavalue_dict: typedefs.MonolingualTextDatavalueDict) -> None:
_validate_datavalue_dict(datavalue_dict)
self._datavalue_dict = datavalue_dict
self.datatype = datavalue_dict["type"]
Expand Down Expand Up @@ -131,7 +131,7 @@ class Quantity:
`quantity`
"""

def __init__(self, datavalue_dict: types.QuantityDatavalueDict) -> None:
def __init__(self, datavalue_dict: typedefs.QuantityDatavalueDict) -> None:
_validate_datavalue_dict(datavalue_dict)
self._datavalue_dict = datavalue_dict
self.datatype = datavalue_dict["type"]
Expand All @@ -152,7 +152,7 @@ class String:
`string`
"""

def __init__(self, datavalue_dict: types.StringDatavalueDict) -> None:
def __init__(self, datavalue_dict: typedefs.StringDatavalueDict) -> None:
_validate_datavalue_dict(datavalue_dict)
self._datavalue_dict = datavalue_dict
self.datatype = datavalue_dict["type"]
Expand Down Expand Up @@ -225,7 +225,7 @@ class Time:
`time`
"""

def __init__(self, datavalue_dict: types.TimeDatavalueDict) -> None:
def __init__(self, datavalue_dict: typedefs.TimeDatavalueDict) -> None:
_validate_datavalue_dict(datavalue_dict)
self._datavalue_dict = datavalue_dict
self.datatype = datavalue_dict["type"]
Expand Down Expand Up @@ -295,7 +295,7 @@ class WikibaseEntityId:
`wikibase-entityid`
"""

def __init__(self, datavalue_dict: types.WikibaseEntityIdDatavalueDict) -> None:
def __init__(self, datavalue_dict: typedefs.WikibaseEntityIdDatavalueDict) -> None:
_validate_datavalue_dict(datavalue_dict)
self._datavalue_dict = datavalue_dict
self.datatype = datavalue_dict["type"]
Expand All @@ -319,7 +319,7 @@ class WikibaseUnmappedEntityId:
`wikibase-unmapped-entityid`
"""

def __init__(self, datavalue_dict: types.WikibaseUnmappedEntityIdDatavalueDict) -> None:
def __init__(self, datavalue_dict: typedefs.WikibaseUnmappedEntityIdDatavalueDict) -> None:
_validate_datavalue_dict(datavalue_dict)
self._datavalue_dict = datavalue_dict
self.datatype = datavalue_dict["type"]
Expand Down Expand Up @@ -351,7 +351,7 @@ def __str__(self) -> str:
]


def get_datavalue_from_snak_dict(snak_dict: types.SnakDict) -> Union[WikidataDatavalue, None]:
def get_datavalue_from_snak_dict(snak_dict: typedefs.SnakDict) -> Union[WikidataDatavalue, None]:
"""Return a Wikidata Datavalue from a snak dictionary."""
if snak_dict["snaktype"] == "value":
datavalue_class = _DATAVALUE_TYPE_TO_CLASS[str(snak_dict["datavalue"]["type"])]
Expand Down
Loading

0 comments on commit 057e6ab

Please sign in to comment.