[issue29847] Path takes and ignores **kwargs

Serhiy Storchaka report at bugs.python.org
Mon Mar 20 15:15:26 EDT 2017


Serhiy Storchaka added the comment:

The support of **kwargs in Path.__new__ is needed if you want to implement a subclass of Path with __init__ accepting keyword arguments (and since Path constructor takes variable number of positional arguments, new arguments should be keyword-only).

>>> import pathlib
>>> class MyPath(pathlib.PosixPath):
...     def __init__(self, *args, spam=False):
...         self.spam = spam
... 
>>> p = MyPath('/', spam=True)
>>> p
MyPath('/')
>>> p.spam
True

Removing **kwargs from Path.__new__ will break the above example.

>>> MyPath('/', spam=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __new__() got an unexpected keyword argument 'spam'

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29847>
_______________________________________


More information about the Python-bugs-list mailing list