Skip to content

DOC: fix issue with __new__ usage in subclassing doc. - #14395

Merged
charris merged 2 commits into
numpy:masterfrom
rgommers:doc-subcl
Sep 4, 2019
Merged

charris merged 2 commits into
numpy:masterfrom
rgommers:doc-subcl

Conversation

@rgommers

Copy link
Copy Markdown
Member

Closes gh-14386.

@charris

charris commented Aug 29, 2019

Copy link
Copy Markdown
Member

Maybe worth a comment? There may be potential confusion between generic python objects and the Python object type. I'm not even clear on how to express the difference. Something like

# The object type __new__ method takes a single argument.

Comment thread numpy/doc/subclassing.py
print('Cls in __new__:', cls)
print('Args in __new__:', args)
return object.__new__(cls, *args)
# The `object` type __new__ method takes a single argument.

@eric-wieser eric-wieser Aug 29, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

Suggested change
# The `object` type __new__ method takes a single argument.
# The `object` type __new__ method takes no additional arguments.

Normally you wouldn't count cls / self as one of the arguments

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe just # do not forward any arguments to object.__new__

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python's error message disagrees with you:
TypeError: object.__new__() takes exactly one argument (the type to instantiate)

@Aa88s

This comment has been minimized.

@charris
charris merged commit af76d3b into numpy:master Sep 4, 2019
@charris

charris commented Sep 4, 2019

Copy link
Copy Markdown
Member

Rewording doesn't make enough difference to keep this open. Thanks Ralf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug in documentation example code for subclassing ndarray

6 participants