Skip to content

Commit

Permalink
Merge pull request #19 from Yorwba/master
Browse files Browse the repository at this point in the history
Only consider snaktype 'value' in entity.getlist (Fixes #18)
  • Loading branch information
dahlia committed Aug 20, 2019
2 parents 9937ff2 + 2276f72 commit 3240c01
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Version 0.7.0
To be released.

- Marked the package as supporting type checking by following :pep:`561`.
- Fixed :exc:`KeyError` from :meth:`Entity.getlist()
<wikidata.entity.Entity.getlist>` if the property is explictly associated
with "no value". [:issue:`18`]


Version 0.6.1
Expand Down
7 changes: 7 additions & 0 deletions tests/entity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,10 @@ def test_entity_repr(fx_unloaded_entity: Entity,
assert repr(fx_unloaded_entity) == '<wikidata.entity.Entity Q1299>'
assert repr(fx_loaded_entity) == \
"<wikidata.entity.Entity Q494290 'Shin Jung-hyeon'>"


def test_entity_getlist_novalue(fx_client: Client):
hong_kong = fx_client.get(EntityId('Q8646'))
locator_map_image = fx_client.get(EntityId('P242'))
# There are 3 snaks for this property, but one has no associated value
assert len(hong_kong.getlist(locator_map_image)) == 2
1 change: 1 addition & 0 deletions tests/fixtures/entities/Q8646.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion wikidata/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def getlist(self, key: 'Entity') -> Sequence[object]:
__import__('pprint').pformat(claims))
decode = self.client.decode_datavalue
return [decode(snak['datatype'], snak['datavalue'])
for snak in (claim['mainsnak'] for claim in claims)]
for snak in (claim['mainsnak'] for claim in claims)
if snak['snaktype'] == 'value']

def iterlists(self) -> Iterator[Tuple['Entity', Sequence[object]]]:
for prop in self:
Expand Down

0 comments on commit 3240c01

Please sign in to comment.