Skip to content

Add support for Python 3.12's type aliases#606

Merged
jcrist merged 1 commit intomainfrom
typealias
Dec 8, 2023
Merged

Add support for Python 3.12's type aliases#606
jcrist merged 1 commit intomainfrom
typealias

Conversation

@jcrist
Copy link
Copy Markdown
Owner

@jcrist jcrist commented Dec 8, 2023

This adds support for the new syntactic type aliases added in Python 3.12. A few examples:

type NullableStr = str | None

type Pair[T] = tuple[T, T]

type NullableStrPair = Pair[NullableStr]

msgspec now supports these type aliases, except in cases where the type alias is recursive. For example, the following type isn't supported:

type Link[T] = tuple[T, Link[T] | None]

The internal datastructure we use to store type information was not designed to handle recursive types like these; supporting them will require a larger refactor.

Fixes #579.

This adds support for the new syntactic type aliases added in Python
3.12. A few examples:

```
type NullableStr = str | None

type Pair[T] = tuple[T, T]

type NullableStrPair = Pair[NullableStr]
```

msgspec now supports these type aliases, *except* in cases where the
type alias is recursive. For example, the following type isn't
supported:

```
type Link[T] = tuple[T, Link[T] | None]
```

The internal datastructure we use to store type information was not
designed to handle recursive types like these; supporting them will
require a larger refactor.
@jcrist jcrist merged commit f8d2c1a into main Dec 8, 2023
@jcrist jcrist deleted the typealias branch December 8, 2023 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for typing.TypeAliasType

1 participant