New submission from Tal Einat:

To quote issue20294 where Larry Hastings added AC support for __new__ and 
__init__:

"
* __init__ and __new__ always take kwargs.
  * if the function signature doesn't accept keyword arguments,
    it calls _PyArg_NoKeywords().
"

However, due to issue1486663, many classes only do a _PyArg_NoKeywords if the 
type is the original class, but not for sub-classses. Examples are 
_random.Random (in which case I found a workaround) and many itertools classes, 
for which there are also tests that check this.

One possibility is to simply allow these classes to also accept keyword 
arguments. It doesn't break backwards compatibility, and once there are proper 
argument names and doc-strings, why not?

Otherwise, currently I have to make generated __new__ functions accept keyword 
arguments, and then wrap them with a function that checks _PyArg_NoKeywords 
only if the the type is the original class.

----------
components: Build, Demos and Tools
messages: 209122
nosy: larry, taleinat
priority: normal
severity: normal
status: open
title: Argument Clinic: Support for __new__ not checking _PyArg_NoKeywords for 
sub-classes
type: enhancement
versions: Python 3.4

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

Reply via email to