awslabs / awslabs/aws-embedded-metrics-python
v3.5.0 - TypeError: 'ABCMeta' object is not subscriptable on Python 3.8 — `Awaitable[T]` in utils.py incompatible with <3.9
- Dominant language
- Python
- Stars
- 231
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Description
## 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
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`:
```python
from collections.abc import Awaitable
```
It is then used as a generic type annotation at **module scope**:
```python
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](https://peps.python.org/pep-0585/). 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`:
```python
# 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.
Contributor guide
Research direction
Start with aws_embedded_metrics/utils.py and inspect the module-level _await annotation and its Awaitable import. Reproduce the failure with python3.8 -c "from aws_embedded_metrics import metric_scope". Done means the package imports successfully on Python 3.8 without the ABCMeta TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100