Josh Rosenberg <shadowranger+pyt...@gmail.com> added the comment:

Blech. Just remembered _field_types is a *class* attribute, not an instance 
attribute, so it (just) can't be a plain property on NamedTuple itself.

And because NamedTuple is super-weird (AFAICT, class X(typing.NamedTuple): pass 
defines a class where the class is not a subclass of typing.NamedTuple, nor are 
its instances instances of NamedTuple, it's just wrapping an invocation of 
collections.namedtuple, which directly subclasses tuple with no metaclass 
involvement), and making a "class property" of the type we'd need requires a 
metaclass (which for tuple subclasses isn't an option), serious hackery or both 
( https://stackoverflow.com/q/5189699/364696 ), it's probably not worth the 
effort to provide this warning. The only way to do it, AFAICT, would be to give 
the root tuple class a metaclass to provide the _field_types property, and 
that's a non-starter given it would, among other things, probably slow every 
single use of tuples just to provide the warning for this one niche case.

Boo.

----------

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

Reply via email to