Skip to content

Commit

Permalink
Add Claim.reset_id() method (#570)
Browse files Browse the repository at this point in the history
fix #472
  • Loading branch information
LeMyst authored Jun 15, 2023
1 parent c42e1ae commit 9e326de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions test/test_wbi_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,10 @@ def test_count_references(self):

def test_get_qualifier_properties(self):
self.assertTrue(len(self.common_item.claims.get(property='P2067')))

def test_claim_reset_id(self):
item = wbi.item.get('Q582')
claim = item.claims.get('P31')[0]
assert claim.id is not None
claim.reset_id()
assert claim.id is None
9 changes: 8 additions & 1 deletion wikibaseintegrator/models/claims.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def __len__(self):
class Claim(BaseModel):
DTYPE = 'claim'

def __init__(self, qualifiers: Optional[Qualifiers] = None, rank: Optional[WikibaseRank] = None, references: Optional[Union[References, List[Union[Claim, List[Claim]]]]] = None, snaktype: WikibaseSnakType = WikibaseSnakType.KNOWN_VALUE) -> None:
def __init__(self, qualifiers: Optional[Qualifiers] = None, rank: Optional[WikibaseRank] = None,
references: Optional[Union[References, List[Union[Claim, List[Claim]]]]] = None, snaktype: WikibaseSnakType = WikibaseSnakType.KNOWN_VALUE) -> None:
"""
:param qualifiers:
Expand Down Expand Up @@ -309,6 +310,12 @@ def has_equal_qualifiers(self, other: Claim) -> bool:

return True

def reset_id(self):
"""
Reset the ID of the current claim
"""
self.id = None

# TODO: rewrite this?
def __contains__(self, item):
if isinstance(item, Claim):
Expand Down

0 comments on commit 9e326de

Please sign in to comment.