astro-sdk icon indicating copy to clipboard operation
astro-sdk copied to clipboard

Use lazy evaluated Type Annotations from PEP 563

Open kaxil opened this issue 1 year ago • 3 comments

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]asint | strand includes https://peps.python.org/pep-0585/ which allows us to writedef f(x: List[str]) -> Nonetodef f(x: list[str]) -> None`

kaxil avatar Aug 12 '22 19:08 kaxil

Also credits to @tatiana she brought it up first in https://github.com/astronomer/astro-sdk/pull/384#discussion_r878956136

kaxil avatar Aug 12 '22 19:08 kaxil

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 avatar Aug 12 '22 20:08 kaxil

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%) :arrow_up:
src/astro/databases/base.py 96.10% <100.00%> (+0.02%) :arrow_up:
src/astro/databases/google/bigquery.py 97.43% <100.00%> (+0.01%) :arrow_up:
src/astro/databases/postgres.py 73.23% <100.00%> (ø)
src/astro/databases/snowflake.py 96.90% <100.00%> (+0.01%) :arrow_up:
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.

codecov[bot] avatar Aug 12 '22 21:08 codecov[bot]

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?

pankajkoti avatar Aug 16 '22 08:08 pankajkoti