immutables icon indicating copy to clipboard operation
immutables copied to clipboard

Add PEP 585 (__class_getitem__ -> GenericAlias) support

Open ToBeReplaced opened this issue 2 years ago • 0 comments

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:

  • https://github.com/python-attrs/cattrs
  • https://github.com/konradhalas/dacite

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

ToBeReplaced avatar Jul 05 '22 04:07 ToBeReplaced