Skip to content

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

Closed
ToBeReplaced wants to merge 1 commit into
MagicStack:masterfrom
ToBeReplaced:pep585
Closed

Add PEP 585 (__class_getitem__ -> GenericAlias) support#89
ToBeReplaced wants to merge 1 commit into
MagicStack:masterfrom
ToBeReplaced:pep585

Conversation

@ToBeReplaced

Copy link
Copy Markdown

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!).

elprans added a commit to elprans/pythoncapi-compat that referenced this pull request Sep 13, 2022
Useful for extensions implementing generic container types, like
`immutables` (see MagicStack/immutables#89).

Co-Authored-By: ToBeReplaced <ToBeReplaced@gmail.com>
#endif


// bpo-39481 added Py_GenericAlias to Python 3.9.0a6.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be added upstream first. I opened python/pythoncapi-compat#45 for that, though if it turns out to be a bad idea we should instead move the ifdef to _map.c

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're obviously correct. I was sloppy and didn't realize the compat layer was upstream. Thanks for reviewing and opening the PR to try to do this properly.

@eltoder

eltoder commented Feb 4, 2023

Copy link
Copy Markdown
Contributor

Hi @ToBeReplaced

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

@elprans

elprans commented Aug 14, 2023

Copy link
Copy Markdown
Member

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

@elprans elprans closed this Aug 14, 2023
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.

Map type arguments aren't introspectible in runtime

3 participants