Home > Software engineering >  Using type() with Annotations in python
Using type() with Annotations in python

Time:02-10

I am trying to learn how to use annotations.

I have this class:

class ApiItemPydanticWithTags(ApiItemPydantic):
    tags: str
ApiItemPydanticWithTags.__name__ = "ApiWIthTags"

I want to replicate this class creation with type():

ApiItemPydanticWithTags = type("ApiWIthTags", (ApiItemPydantic,), dict(tags: str = None))

But Obviously, dict(tags: str = None) does not work ...

CodePudding user response:

  •  Tags:  
  • Related