Message388183
While troubleshooting a strange problem (https://github.com/jaraco/keyring/issues/498) where a program worked on Python 3.7+ but failed on Python 3.6, I discovered a somewhat unintuitive behavior. On Python 3.7+, keyword arguments to tuple subclasses are allowed and ignored:
>>> class Foo(tuple): pass
>>> tuple(name='xyz')
TypeError: tuple() takes no keyword arguments
>>> Foo(name='xyz')
()
But on Python 3.6, the keyword parameter causes an error:
$ python3.6 -c "type('Foo', (tuple,), {})(name='xyz')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: 'name' is an invalid keyword argument for this function
I checked out the What's new in Python 3.7 and I see this notice:
Functions bool(), float(), list() and tuple() no longer take keyword arguments. The first argument of int() can now be passed only as positional argument.
Hmm, but in my experience, tuple on Python 3.6 doesn't take keyword arguments either:
importlib_metadata main $ python3.6 -c "tuple(name='xyz')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: 'name' is an invalid keyword argument for this function
So that change may be related, but I'm not sure where or how.
The main place my expectation is violated is in the subclass. Why should a subclass of tuple allow keyword arguments when the parent class does not? I'd expect that the subclass should reject keyword arguments as well.
Less importantly, the What's New doc implies that keyword arguments were accepted in Python 3.6; why aren't they? |
|
Date |
User |
Action |
Args |
2021-03-06 01:37:11 | jaraco | set | recipients:
+ jaraco |
2021-03-06 01:37:11 | jaraco | set | messageid: <1614994631.23.0.248202692536.issue43413@roundup.psfhosted.org> |
2021-03-06 01:37:11 | jaraco | link | issue43413 messages |
2021-03-06 01:37:10 | jaraco | create | |
|