Azure / Azure/azure-functions-python-worker
[FeatureRequest] Support Python 3.9 style hinting using standard collections per PEP 585
- Dominant language
- Python
- Stars
- 357
- Forks
- 116
- Avg merge
- 32m
- Merged PRs (30d)
- 1
Description
The worker supports Python 3.9, however does not work with type hinting using standard collections as specified in [PEP 585](https://peps.python.org/pep-0585/) and [introduced in Python 3.9](https://docs.python.org/3/whatsnew/3.9.html#type-hinting-generics-in-standard-collections).
Pre-PEP 585 style typing, which works:
```python
from typing import List
# `func host start` is happy with this style of type hinting.
def main(events: List[func.EventHubEvent]) -> None:
...
```
New PEP 585 style typing, which doesn't work:
```python
# `func host start` produces error here.
def main(events: list[func.EventHubEvent]) -> None:
...
```
The error produced is:
```python
Worker failed to load function: 'my_function_name' with function id: '12345678-9012-3456-7890-abcdef123456'.
[2022-05-17T08:58:41.245Z] Result: Failure
[2022-05-17T08:58:41.245Z] Exception: TypeError: issubclass() arg 1 must be a class
[2022-05-17T08:58:41.245Z] Stack: File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/azure_functions_worker/dispatcher.py", line 311, in _handle__function_load_request
[2022-05-17T08:58:41.245Z] self._functions.add_function(
[2022-05-17T08:58:41.245Z] File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/azure_functions_worker/functions.py", line 204, in add_function
[2022-05-17T08:58:41.245Z] checks_out = bindings.check_input_type_annotation(
[2022-05-17T08:58:41.245Z] File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/azure_functions_worker/bindings/meta.py", line 44, in check_input_type_annotation
[2022-05-17T08:58:41.245Z] return binding.check_input_type_annotation(pytype)
[2022-05-17T08:58:41.245Z] File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4483/workers/python/3.9/OSX/X64/azure/functions/eventhub.py", line 20, in check_input_type_annotation
[2022-05-17T08:58:41.245Z] or (isinstance(pytype, type) and issubclass(pytype, valid_types))
[2022-05-17T08:58:41.245Z] File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/abc.py", line 123, in __subclasscheck__
[2022-05-17T08:58:41.245Z] return _abc_subclasscheck(cls, subclass)
```
System info, in case it's relevant:
- **OS** - macOS Monterey 12.3.1
- **`func --version`** - 4.0.4483
- **`python --version`** - Python 3.9.12
Contributor guide
Assessment
This issue has not been assessed yet.