Jacob Hayes <jacob.r.ha...@gmail.com> added the comment:

Thanks for the tips! I've been using this patch in my own code in a early 
imported `__init__.py`:

```
from graphlib import TopologicalSorter
from types import GenericAlias

if not hasattr(TopologicalSorter, "__class_getitem__"):  # pragma: no cover
    TopologicalSorter.__class_getitem__ = classmethod(GenericAlias)  # type: 
ignore
```

Certainly a bit hacky, but aside from no-op on >=3.11 and satisfying mypy, it 
supports runtime type inspection via `get_type_hints` before 3.11 (which 
otherwise still errors for stringized versions). The stringized versions are 
probably a bit simpler/safer for most folks though :)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45359>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to