[issue43923] Can't create generic NamedTuple as of py3.9
New submission from FHTMitchell : As of python 3.9, you now can't have multiple inheritance with `typing.NamedTuple` subclasses. This seems sensible, until you realise that `typing.Generic` works via inheritance. This fails whether or not `from __future__ import annotations` is enabled. example: ``` class Group(NamedTuple, Generic[T]): key: T group: List[T] --- TypeError Traceback (most recent call last) in > 1 class Group(NamedTuple, Generic[T]): 2 key: T 3 group: List[T] 4 ~/.conda/envs/py39/lib/python3.9/typing.py in _namedtuple_mro_entries(bases) 1818 def _namedtuple_mro_entries(bases): 1819 if len(bases) > 1: -> 1820 raise TypeError("Multiple inheritance with NamedTuple is not supported") 1821 assert bases[0] is NamedTuple 1822 return (_NamedTuple,) TypeError: Multiple inheritance with NamedTuple is not supported ``` This worked fine in python 3.7 and 3.8 and as I understand it was one of the motivating cases for pep 560. The change was made as part of bpo-40185: Refactor typing.NamedTuple. Whilst the obvious alternative is "use dataclasses", they don't have the same runtime properties or implications as namedtuples. -- messages: 391705 nosy: FHTMitchell priority: normal severity: normal status: open title: Can't create generic NamedTuple as of py3.9 versions: Python 3.10, Python 3.11, Python 3.9 ___ Python tracker <https://bugs.python.org/issue43923> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43923] Can't create generic NamedTuple as of py3.9
Change by FHTMitchell : -- type: -> behavior ___ Python tracker <https://bugs.python.org/issue43923> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33055] bytes does not implement __bytes__()
New submission from FHTMitchell : Every object which has a corresponding dunder protocol also implements said protocol with one exception: >>> 'hello'.__str__() 'hello' >>> (3.14).__float__() 3.14 >>> (101).__int__() 101 >>> True.__bool__() True >>> iter(range(10)).__iter__() >>> b'hello'.__bytes__() --- AttributeErrorTraceback (most recent call last) > 1 b'hello'.__bytes__() AttributeError: 'bytes' object has no attribute '__bytes__' This was brought up on SO as being inconsistent: https://stackoverflow.com/questions/49236655/bytes-doesnt-have-bytes-method/49237034?noredirect=1#comment85477673_49237034 -- components: Interpreter Core messages: 313653 nosy: FHTMitchell priority: normal severity: normal status: open title: bytes does not implement __bytes__() type: behavior versions: Python 3.6, Python 3.7, Python 3.8 ___ Python tracker <https://bugs.python.org/issue33055> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue31780] Using format spec ',x' displays incorrect error message
New submission from FHTMitchell : Minor issue. Using the ',b', ',o' or ',x' raises the error ValueError("Cannot specify ',' or '_' with 'x'.",) (or equivalently for 'b' and 'o'). However, it is possible to use the format specs '_b', '_o' and '_x' in Python 3.6 due to PEP 515. The following test demonstrates this: >>> i = 1 >>> for base in 'box': ... for sep in ',_': ... try: ... print(f'{i:{sep}{base}}') ... except ValueError as err: ... print(repr(err)) ValueError("Cannot specify ',' or '_' with 'b'.",) 1_1000_0110_1010_ ValueError("Cannot specify ',' or '_' with 'o'.",) 30_3240 ValueError("Cannot specify ',' or '_' with 'x'.",) 1_86a0 -- messages: 304330 nosy: FHTMitchell priority: normal severity: normal status: open title: Using format spec ',x' displays incorrect error message type: behavior versions: Python 3.6 ___ Python tracker <https://bugs.python.org/issue31780> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33555] No SyntaxError raised for `return` with argument inside generator
New submission from FHTMitchell : In python 2.7 if you run the following code you get an error (as you would expect) Python 2.7.14 | packaged by conda-forge | (default, Dec 25 2017, 01:17:32) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): ... yield 1 ... return 2 ... File "", line 3 SyntaxError: 'return' with argument inside generator However, in python 3.6 the error is silently ignored Python 3.6.4 | packaged by conda-forge | (default, Dec 24 2017, 10:11:43) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): ... yield 1 ... return 2 ... >>> for i in f(): ... print(i) ... 1 and still is in 3.7 Python 3.7.0b2 (v3.7.0b2:b0ef5c979b, Feb 28 2018, 02:24:20) [MSC v.1912 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): ... yield 1 ... return 2 ... >>> for i in f(): ... print(i) ... 1 This is a source of confusion https://stackoverflow.com/questions/47831240/why-is-no-value-returned-from-my-generator/ especially since the PEP says it is disallowed: https://www.python.org/dev/peps/pep-0255/#then-why-not-allow-an-expression-on-return-too -- components: Interpreter Core messages: 316912 nosy: FHTMitchell priority: normal severity: normal status: open title: No SyntaxError raised for `return` with argument inside generator type: behavior versions: Python 3.6, Python 3.7 ___ Python tracker <https://bugs.python.org/issue33555> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33555] No SyntaxError raised for `return` with argument inside generator
FHTMitchell added the comment: Apologies if I wasn't clear. I understand that def f(): yield 1 return is valid python. What I'm saying, if you follow the link, is that def f(): yield 1 return 2 # not the argument should not be considered valid python according to PEP 255. This is implemented in python 2 but not in python 3. -- resolution: not a bug -> status: closed -> open ___ Python tracker <https://bugs.python.org/issue33555> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33555] No SyntaxError raised for `return` with argument inside generator
FHTMitchell added the comment: Whoops I understand. Reclosed. -- resolution: -> not a bug status: open -> closed ___ Python tracker <https://bugs.python.org/issue33555> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com