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

fix: add support for PEP 585 type hinting for 3.9+ #199

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

YunchuWang
Copy link
Contributor

This PR introduces compatibility with PEP 585 type hinting in the Azure Functions Python Worker. PEP 585, introduced in Python 3.9, allows for the use of built-in collection types (like list and dict) as generic type hints, offering a more concise and readable syntax.

addressing Azure/azure-functions-python-worker#1034

@YunchuWang YunchuWang marked this pull request as ready for review December 20, 2023 22:39
@YunchuWang YunchuWang marked this pull request as draft December 20, 2023 22:40
Copy link

codecov bot commented Dec 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0ca53b3) 92.97% compared to head (94739ae) 92.98%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #199      +/-   ##
==========================================
+ Coverage   92.97%   92.98%   +0.01%     
==========================================
  Files          56       56              
  Lines        3187     3194       +7     
  Branches      649      651       +2     
==========================================
+ Hits         2963     2970       +7     
  Misses        137      137              
  Partials       87       87              
Flag Coverage Δ
unittests 92.89% <77.77%> (-0.05%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@YunchuWang YunchuWang marked this pull request as ready for review January 2, 2024 16:10
@hallvictoria hallvictoria self-requested a review as a code owner August 12, 2024 18:13
@hallvictoria hallvictoria changed the title Add Support for PEP 585 Type Hinting in Azure Functions Python Worker fix: add support for PEP 585 type hinting for 3.9+ Aug 12, 2024
"""
origin = get_origin(annotation)
if sys.version_info >= (3, 9):
is_iterable_anno = (origin is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is typing_inspect.is_generic_type(annotation) not included in >3.9?

Copy link
Contributor

Choose a reason for hiding this comment

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

is_generic_type will fail for the list type -- this is a method we defined. get_origin expands on our definition of is_generic_type but includes the built-in collection types. get_origin supports the generic types and returns a non-None value where is_generic_type would return true

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.

3 participants