[issue43923] Can't create generic NamedTuple as of py3.9

Steven Silvester report at bugs.python.org
Mon Mar 7 17:41:40 EST 2022


Steven Silvester <steven.silvester at gmail.com> added the comment:

The use case that prompted https://github.com/python/cpython/pull/31679 is that we are adding typings to `PyMongo`.  We are late to using typings,  because we only recently dropped Python 2.7 support.  

We have an existing options class that subclasses `NamedTuple`.  We would like to make that class `Generic`, but are currently blocked.  

Our current workaround is to create a separate stub file that uses `class CodecOptions(Tuple, Generic[T])` and explicitly re-declares the `NamedTuple` API.

Switching to `dataclass` would be disruptive, since we still support Python 3.6 and only rely on the standard library.  We would also require a major version update since it would be an API change.

----------
nosy: +Steven Silvester

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43923>
_______________________________________


More information about the Python-bugs-list mailing list