Bug report
Summary
aws-embedded-metrics fails to import on Python 3.8. The library crashes at module load time with TypeError: 'ABCMeta' object is not subscriptable, preventing any application that imports it from starting.
Environment
- Python version: 3.8.x
- aws-embedded-metrics version: 3.5.0 (also reproduced on current
master)
- Platform: SageMaker SKLearn container (miniconda3 Python 3.8)
Steps to reproduce
pip install aws-embedded-metrics
python3.8 -c "from aws_embedded_metrics import metric_scope"
Full traceback
File "aws_embedded_metrics/utils.py", line 33, in <module>
async def _await(awaitable: Awaitable[T]) -> T:
TypeError: 'ABCMeta' object is not subscriptable
Root cause
In aws_embedded_metrics/utils.py, Awaitable is imported from collections.abc:
from collections.abc import Awaitable
It is then used as a generic type annotation at module scope:
async def _await(awaitable: Awaitable[T]) -> T:
Generic subscripting of collections.abc classes (e.g. Awaitable[T]) was only made legal at runtime in Python 3.9 via PEP 585. On Python 3.8, this expression is evaluated eagerly when the module is first imported, raising TypeError because ABCMeta does not implement __class_getitem__.
Proposed fix
change the import to use typing.Awaitable instead of collections.abc.Awaitable:
# Before
from collections.abc import Awaitable
# After
from typing import Awaitable
typing.Awaitable has supported [T] subscripting since Python 3.5.3 and is safe on all supported Python versions.
Additional notes
- The entire import chain (
metric_scope → metrics_logger_factory → metrics_context → utils) fails because the crash occurs at module scope on every import.
Bug report
Summary
aws-embedded-metricsfails to import on Python 3.8. The library crashes at module load time withTypeError: 'ABCMeta' object is not subscriptable, preventing any application that imports it from starting.Environment
master)Steps to reproduce
Full traceback
Root cause
In
aws_embedded_metrics/utils.py,Awaitableis imported fromcollections.abc:It is then used as a generic type annotation at module scope:
Generic subscripting of
collections.abcclasses (e.g.Awaitable[T]) was only made legal at runtime in Python 3.9 via PEP 585. On Python 3.8, this expression is evaluated eagerly when the module is first imported, raisingTypeErrorbecauseABCMetadoes not implement__class_getitem__.Proposed fix
change the import to use
typing.Awaitableinstead ofcollections.abc.Awaitable:typing.Awaitablehas supported[T]subscripting since Python 3.5.3 and is safe on all supported Python versions.Additional notes
metric_scope→metrics_logger_factory→metrics_context→utils) fails because the crash occurs at module scope on every import.