Would something as simple as the below work for you?
At object instantiation, check if too much or too little data was provided, then define a property that will compute the value if necessary?
class Item ():
def __init__(self, id: int =None, name:str= None):
if all ([name, id]):
raise ValueError ("id_ and name cannot be provided together")
elif not any ([name, id]):
raise ValueError ("name or id must be provided for Item instantiation")
else:
self._name = name
self._id = id
@property
def name (self) -> str:
if self._name is None:
#Compute the value and return it
pass #remove this once you figure out your algorithm
else:
return self._name
@property
def id (self) ->int:
if self._id is None:
#Compute the value and return it
pass #remove this once you figure out your algorithm
else:
return self._id
Note that you must also take into consideration what a valid value is. In my provided example case, it is not sufficient if you consider integer 0
a valid id
, and an empty string ""
a valid name
.