Consider this imported class and function. I can't edit them and it's not practical to patch them:
# Code I can't change
class Person:
def __init__(self, age: int):
self.age = age
def get_person() -> Person:
return Person(42)
I'm wrapping get_person
with my own function and amending the Person
object. I must call/wrap get_person
as it's not practical to reproduce the logic inside that function.
# My code
def get_person_with_name() -> ???:
person = get_person()
person.name = 'Tim'
return person
How do I type hint the return value of get_person_with_name
to "a Person
object but also with a name attribute"? And how do I do it properly so that type checking and code completion respect the type of the amended object?