I am trying to set acceptable built-in types for my class variables. I want to throw an exception if given type is incorrect. Is there any better way than setter with isinstance()?
My first attempt:
class Address:
city: str
building_number: str or int
apartment_number: int
street: str
def __init__(self, city, building_number, apartment_number, street):
self.city = city
self.building_number = building_number
self.apartment_number = apartment_number
self.street = street
Unfortuantely it compiles regardless of type.
My second attempt:
class Address:
def __init__(self, city: str, building_number: str, apartment_number: int, street: str):
self.city = city
self.building_number = building_number
self.apartment_number = apartment_number
self.street = street
This one actually shows the wrong type when creating a class but it compiles without throwing any error or message.

