[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-20 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: > Would it be worthwhile to show an example of a subclass that overrides or > extends __new__? I think yes. I would actually add few examples what could (and maybe also couldn't) be done with named tuples. --

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-16 Thread Raymond Hettinger
Raymond Hettinger added the comment: Would it be worthwhile to show an example of a subclass that overrides or extends __new__? Elsewhere in Python, the usual technique for changing method defaults is for a subclass to override or extend the method in

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-16 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: > Apart from the fact that it's too late, if you had to do it over again, could it be done as a class decorator? Yes, this could be done as a decorator which would replace the original class with a named tuple after inspecting

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-15 Thread Guido van Rossum
Guido van Rossum added the comment: Apart from the fact that it's too late, if you had to do it over again, could it be done as a class decorator? Anyway, let's keep this issue open but reclassify it as a docs issue. -- ___ Python

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-15 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: I would say it is too late. `typing.NamedTuple` is out there for more than a year and is quite actively used. A search on GitHub shows thousands of files that import `typing.NamedTuple` and a macroscopic fraction of those use it with

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-15 Thread Eric V. Smith
Eric V. Smith added the comment: I once thought of building NamedTuple functionality into dataclasses, either as a parameter to @dataclass or as a new decorator. But it didn't get very far. It would have to return a different class, like NamedTuple does, and this didn't

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-15 Thread Guido van Rossum
Guido van Rossum added the comment: I wonder if it's too late to conclude that NamedTuple in this context should have been a class decorator rather than a base class. With a class decorator it's more understandable that the effect doesn't automatically apply to subclasses.

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-15 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: Yes, this is because subclassing `typing.NamedTuple` is not an actual subclassing, but is just a syntactic sugar for calling `collections.namedtuple`. A discussion about allowing subclassing/extending named tuples previously appeared

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-14 Thread Eric V. Smith
Change by Eric V. Smith : -- nosy: +eric.smith ___ Python tracker ___ ___

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-14 Thread Guido van Rossum
Guido van Rossum added the comment: Thanks Евгений Махмудов for the report! The crux is this: class A(NamedTuple): value: bool = True class B(A): value: bool = False B(True).value # Expected True, but is False B(True)[0] # True as expected If we add NamedTuple

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-14 Thread Ned Deily
Change by Ned Deily : -- nosy: +gvanrossum, levkivskyi ___ Python tracker ___ ___

[issue33077] typing: Unexpected result with value of instance of class inherited from typing.NamedTuple

2018-03-14 Thread Евгений Махмудов
New submission from Евгений Махмудов : Overwriting of default values not working, and used default value of base class. Unittest file if attachment described a problem. -- components: Library (Lib) files: python_test.py messages: 313843 nosy: Евгений