Skip to content

Handle type aliases in Python 3.12+ correctly. #65

@lojack5

Description

@lojack5

I was going through and updating internal typing used in the library, and ran across this issue:

type MyType = uint8

class Test(Structured):
  a: MyType

Here a won't be detected as a serializable type. The same thing doesn't happen with the older syntax of MyType: TypeAlias = uint8, as it is actually assigned the value of uint8. With the new syntax however, a TypeAlias object is created instead (technically, a typing.TypeAliasType object).

So we'll need to handle this correctly. Some relevant information stored on the TypAliasType object that will be needed:

  • __value__ holds the assigned value of the TypeAlias, this is what will be needed to be examined for serializability checks
  • __name__ holds the name of the TypeAlias, probably not needed
  • __type_params__ holds type parameters (typevars, typevartuples) for generic TypeAlias's.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions