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 support for lazy type annotations PEP563 (#112) #126
Conversation
Hi @ydylla
Did you try import sys
@pytest.mark.skipif(sys.version_info < (3, 0),
reason="requires Python3")
def test_function():
... https://docs.pytest.org/en/reorganize-docs/new-docs/user/skipping.html |
Yes I am aware of I also forgot to mention that I added tests for forward references with this. @dataclass
class A:
v: 'B'
@serialize
@deserialize
@dataclass
class B:
v: int
# B is now visible so we can setup A
serialize(A)
deserialize(A) |
@ydylla I found a workaround in pydantic project. Could you check it is applicable to our case? kip_pre_37 = pytest.mark.skipif(sys.version_info < (3, 7), reason='testing >= 3.7 behaviour only')
@skip_pre_37
def test_postponed_annotations(create_module):
module = create_module(
# language=Python
"""
from __future__ import annotations
from pydantic import BaseModel
class Model(BaseModel):
a: int
"""
)
m = module.Model(a='123')
assert m.dict() == {'a': 123} https://github.com/samuelcolvin/pydantic/blob/master/tests/test_forward_ref.py#L8-L24 |
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.
LGTM!
* also move SerdeError to compat.py
Codecov Report
@@ Coverage Diff @@
## master #126 +/- ##
==========================================
- Coverage 89.28% 89.13% -0.15%
==========================================
Files 11 11
Lines 1017 1031 +14
Branches 224 227 +3
==========================================
+ Hits 908 919 +11
- Misses 70 71 +1
- Partials 39 41 +2
Continue to review full report at Codecov.
|
Hi @yukinarit, If you have no objections you can merge this. |
@ydylla Create import sys
if sys.version_info[:2] == (3, 6):
collect_ignore = ["tests/test_lazy_type_evaluation.py"] For more information, please check: https://docs.pytest.org/en/6.2.x/example/pythoncollection.html#customizing-test-collection |
Thanks @yukinarit, |
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.
LGTM!
@ydylla |
Currently, not necessarily. I already use it via git installation. |
Hi @yukinarit,
I added basic support for
from __future__ import annotations
.Do you have any ideas how we could tell pytest to skip test_lazy_type_evaluation.py when using python 3.6 since the annotations future does not exist there?
Closes #112