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
fix: error checking inheritance
when using PEP585 and PEP604 type hints
#3681
fix: error checking inheritance
when using PEP585 and PEP604 type hints
#3681
Conversation
0a0094c
to
8099520
Compare
Improved Annotated and Literal handling
7476b89
to
e79be40
Compare
Watch cython issue cython/cython#2753 Previous implementation can be used after cython 3.0 release
35ba1f8
to
9bfa03a
Compare
648b24d
to
c421630
Compare
please review |
error checking inheritance
when using PEP585 and PEP604 type hints
hi, when this fix is planned to be released please? |
Scheduled for v1.9.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, thank you for the contribution.
Some things to change.
tests/test_typing.py
Outdated
|
||
@pytest.mark.skipif(sys.version_info < (3, 9), reason='PEP585 generics only supported for python 3.9 and above.') | ||
def test_convert_generics(): | ||
assert convert_generics(int) == int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we parameterise these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can but Python does actually run all of the stuff inside of pytest.mark.parametrize
(even if the test should be skipped), so parametrized variables can only be strings, otherwise Python 3.7 and 3.8 tests will fail.
Anyway, I've done the parametrization. It looks a little bit weird (but cleaner), involved eval
magic, and also made me wrote noqa: F401
to suppress flake8
's "unused import" warning. Maybe you have an idea for a better solution?
please update. |
Any updates to this PR? |
I've removed the 1.9.1 milestone as, on reflection, I don't think this is a regression in v1.9. |
I believe this is a regression indirectly because since Python 3.9 introduced PEP585, all of the type hints (such as List, Dict, Tuple, etc.) in the |
Makes sense, I've re-added the milestone and will try to include this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise LGTM.
This looks excellent, thank you so much for the really well thought out PR.
please update. Also, please could you resolve conflicts - should be trivial. |
e91ea65
to
a41c191
Compare
please review |
thanks so much. |
…ints (pydantic#3681) * Add tests * Fix the issue * Add changes file * Improved convert_generics * Add default fallback to convert_generics Improved Annotated and Literal handling * Fix Cython doesn't support generic types (PEP560) Watch cython issue cython/cython#2753 Previous implementation can be used after cython 3.0 release * Add custom type test * Cosmetic fixes Co-authored-by: Samuel Colvin <samcolvin@gmail.com> * Fix typos * Add SelfReferencing test validation Add parametrization to * Fix: parametrization caused test discovery problem * Better explanation for a test case * Better assertions for model creation tests * Rerun CI Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Change Summary
Created
convert_generics
function, which searches forstr
types inside of type hints and replaces them with ForwardRef.Used this function in
ModelField
.Related issue number
fix #2798
fix #3297
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)