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

Use lazy evaluated Type Annotations from PEP 563 #650

Merged
merged 5 commits into from
Aug 18, 2022

Conversation

kaxil
Copy link
Collaborator

@kaxil kaxil commented Aug 12, 2022

Details: https://peps.python.org/pep-0563/ and https://discuss.python.org/t/type-annotations-pep-649-and-pep-563/11363/20

tl_dr: This PEP lazy evaluates Annotations so they are not evaluated at parse time and allows forward references as well.

This also includes https://peps.python.org/pep-0604/ which allows writing typing.Union[int, str] as int | str and includes https://peps.python.org/pep-0585/ which allows us to write def f(x: List[str]) -> None to def f(x: list[str]) -> None

@kaxil
Copy link
Collaborator Author

kaxil commented Aug 12, 2022

Also credits to @tatiana she brought it up first in #384 (comment)

@kaxil kaxil force-pushed the use-new-annotations branch 2 times, most recently from 0163466 to 9f60b12 Compare August 12, 2022 20:43
@kaxil
Copy link
Collaborator Author

kaxil commented Aug 12, 2022

There are some caveats though as listed in https://mypy.readthedocs.io/en/stable/runtime_troubles.html#future-annotations-import-pep-563.

@uranusjr Is it safe to use this or should we wait till we drop support for Python 3.7 and 3.8?

@kaxil kaxil marked this pull request as draft August 12, 2022 20:46
@codecov
Copy link

codecov bot commented Aug 12, 2022

Codecov Report

Merging #650 (9d6ae36) into main (bd3f51c) will increase coverage by 0.52%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #650      +/-   ##
==========================================
+ Coverage   92.47%   93.00%   +0.52%     
==========================================
  Files          42       42              
  Lines        1701     1715      +14     
  Branches      216      212       -4     
==========================================
+ Hits         1573     1595      +22     
+ Misses        102       98       -4     
+ Partials       26       22       -4     
Impacted Files Coverage Δ
src/astro/constants.py 93.93% <100.00%> (+0.18%) ⬆️
src/astro/databases/base.py 96.10% <100.00%> (+0.02%) ⬆️
src/astro/databases/google/bigquery.py 97.43% <100.00%> (+0.01%) ⬆️
src/astro/databases/postgres.py 73.23% <100.00%> (ø)
src/astro/databases/snowflake.py 96.90% <100.00%> (+0.01%) ⬆️
src/astro/databases/sqlite.py 74.50% <100.00%> (ø)
src/astro/files/base.py 94.33% <100.00%> (ø)
src/astro/files/locations/amazon/s3.py 100.00% <100.00%> (ø)
src/astro/files/locations/base.py 75.67% <100.00%> (ø)
src/astro/files/locations/google/gcs.py 100.00% <100.00%> (ø)
... and 21 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@kaxil kaxil marked this pull request as ready for review August 15, 2022 16:15
@pankajkoti
Copy link
Contributor

pankajkoti commented Aug 16, 2022

There are a couple of suggestions from DeepSource:Python: https://deepsource.io/gh/astronomer/astro-sdk/run/8c8ca0ea-fa9c-48f3-901b-d8e2c8ea476a/python/

They are unrelated to this PR but should we fix them as part of this PR?

Details: https://peps.python.org/pep-0563/ and https://discuss.python.org/t/type-annotations-pep-649-and-pep-563/11363/20

tl_dr: This PEP lazy evaluates Annotations so they are not evaluated at parse time and allows forward references as well.

This also includes https://peps.python.org/pep-0604/ which allows writing typing.Union[int, str]` as `int | str` and includes https://peps.python.org/pep-0585/ which allows us to write `def f(x: List[str]) -> None` to `def f(x: list[str]) -> None`
@utkarsharma2 utkarsharma2 merged commit 7b7e3b1 into main Aug 18, 2022
@utkarsharma2 utkarsharma2 deleted the use-new-annotations branch August 18, 2022 10:12
@utkarsharma2 utkarsharma2 restored the use-new-annotations branch August 18, 2022 12:55
@utkarsharma2 utkarsharma2 deleted the use-new-annotations branch August 18, 2022 13:06
kaxil added a commit that referenced this pull request Aug 18, 2022
Details: https://peps.python.org/pep-0563/ and https://discuss.python.org/t/type-annotations-pep-649-and-pep-563/11363/20

tl_dr: This PEP lazy evaluates Annotations so they are not evaluated at parse time and allows forward references as well.

This also includes https://peps.python.org/pep-0604/ which allows writing §typing.Union[int, str]` as `int | str` and includes https://peps.python.org/pep-0585/ which allows us to write `def f(x: List[str]) -> None` to `def f(x: list[str]) -> None`
kaxil added a commit that referenced this pull request Aug 25, 2022
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.

None yet

5 participants