Can I define the type of a variable from other variable type?
Example: I created USER:
class User(BaseModel):
id: str # Not sure if will be str, int or UUID
tags: Optional[List[str]]
name: str
Now, in other place, I have a function that uses User.id as parameter:
def print_user_id(user_id: str): # If I change type of User.id, I need to update this!
pass
How can I say that the type of user_id
is type(User.id)
?
Like:
def print_user_id(user_id: type(User.id)): # But, If I change type of User.id, I DON`T NEED to update this :)
pass