Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a __class_getitem__ hook (PEP 585) #173

Merged
merged 4 commits into from
Oct 15, 2021

Conversation

mjpieters
Copy link
Collaborator

This makes it possible to use FrozenClass as a generic in typehinting
without having to use from __future__ import annotations or forward
references.

Closes #172

This makes it possible to use FrozenClass as a generic in typehinting
without having to use `from __future__ import annotations` or forward
references.
@codecov
Copy link

codecov bot commented Dec 2, 2020

Codecov Report

Merging #173 (fbb992d) into main (bb0ef0c) will not change coverage.
The diff coverage is 100.00%.

❗ Current head fbb992d differs from pull request most recent head 48c13b7. Consider uploading reports for the commit 48c13b7 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##              main      #173   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           54        59    +5     
  Branches         6         6           
=========================================
+ Hits            54        59    +5     
Flag Coverage Δ
unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
frozenlist/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb0ef0c...48c13b7. Read the comment docs.

# Python 3.9 PEP 585
__class_getitem__ = classmethod(types.GenericAlias)
except AttributeError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Could you please just return self if GenericAlias doesn't exist?

Another thing is the exception usage here.
The code is 100% correct but if sys.version_info >= (3, 9): provides more information to reader what is the expected version with desired behavior and works much better with mypy and other type checkers.

@asvetlov asvetlov merged commit fd9d610 into aio-libs:main Oct 15, 2021
@mjpieters mjpieters deleted the class_generic branch January 25, 2023 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

subscriptable typing
2 participants