[issue45359] TopologicalSorter is not Generic at runtime (but is in typeshed)
Alex Waygood
report at bugs.python.org
Fri Dec 10 03:54:02 EST 2021
Alex Waygood <Alex.Waygood at Gmail.com> added the comment:
Another option for code using Python <3.11, that will work without the `from __future__ import annotations` import, is to do something like this:
```
from graphlib import TopologicalSorter
x: 'TopologicalSorter[str]' = TopologicalSorter({"a": {}, "b": {"a"}})
```
By using a string as the annotation, we give mypy the specificity it needs, but the expression will never need to be resolved at runtime.
----------
nosy: +AlexWaygood
type: behavior -> enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45359>
_______________________________________
More information about the Python-bugs-list
mailing list