Skip to content

Commit

Permalink
Add getter/setter in BaseEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
LeMyst committed Feb 15, 2022
1 parent 244ca5d commit 337b3c5
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion wikibaseintegrator/entities/baseentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from copy import copy
from typing import TYPE_CHECKING, Any, Dict, List, Union
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

import ujson

Expand Down Expand Up @@ -38,6 +38,46 @@ def __init__(self, api: 'WikibaseIntegrator' = None, lastrevid: int = None, type
self.id = id
self.claims = claims or Claims()

@property
def api(self) -> WikibaseIntegrator:
return self.__api

@api.setter
def api(self, value: WikibaseIntegrator):
self.__api = value

@property
def lastrevid(self) -> Optional[int]:
return self.__lastrevid

@lastrevid.setter
def lastrevid(self, value: Optional[int]):
self.__lastrevid = value

@property
def type(self) -> str:
return self.__type

@type.setter
def type(self, value: str):
self.__type = value

@property
def id(self) -> Optional[str]:
return self.__id

@id.setter
def id(self, value: Optional[str]):
self.__id = value

@property
def claims(self) -> Claims:
return self.__claims

@claims.setter
def claims(self, value: Claims):
self.__claims = value

def add_claims(self, claims: Union[Claim, List], action_if_exists: ActionIfExists = ActionIfExists.APPEND) -> BaseEntity:
if isinstance(claims, Claim):
claims = [claims]
Expand Down

1 comment on commit 337b3c5

@dpriskorn
Copy link
Contributor

@dpriskorn dpriskorn commented on 337b3c5 Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, I did not know how to do this in Python. I'm learning a lot from you! :)
I tried using private variables in OpenAlexBot but pydantic throws errors if I add __ to attributes. :/

Please sign in to comment.