[New-bugs-announce] [issue20385] Argument Clinic: Support for __new__ not checking _PyArg_NoKeywords for sub-classes

Tal Einat report at bugs.python.org
Fri Jan 24 22:35:41 CET 2014

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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list