MagicStack / immutables

A high-performance immutable mapping type for Python.
Other
1.14k stars 57 forks source link

Add PEP 585 (__class_getitem__ -> GenericAlias) support #89

Closed ToBeReplaced closed 1 year ago

ToBeReplaced commented 2 years ago

This commit add supports for PEP 585 on Python 3.9+.

This is useful for runtime introspection ( resolves #83 ).

For example, on Python 3.9+:

>>> immutables.Map[str, int]
immutables._map.Map[int, str]

On Python 3.8-:

>>> immutables.Map[str, int]
<class 'immutables.map.Map'>

This does not affect type checkers, as they do not utilize runtime introspection.

This is immediately useful for applications that would like to use type information for (de)serialization. Examples:

Thank you for your work on this library (and PEP, to boot!).

eltoder commented 1 year ago

Hi @ToBeReplaced

Given the response on https://github.com/python/pythoncapi-compat/pull/45, are you going to finish this PR? Happy to pick it up if you don't have time.

elprans commented 1 year ago

Closing as superseded by #101. Thanks for working on this!