GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-87613: Name the subclass in Argument Clinic `__new__` argument errors by cmaloney · Pull Request #160799 · python/cpython

Conversation

@cmaloney

@cmaloney cmaloney commented Oct 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The tp_new slot is inherited. Because the base type name was embedded in the errors this meant argument errors showed as the base type rather than the subclass. Change them to be the subclass name.

While tp_name would be slightly faster to use it includes the module name like _thread.RLock() which adds confusion. Use _PyType_Name(type) which returns RLock(). Include a test to check.

_PyArg_NoPositional() only short-circuits when args is NULL, which tp_new never gets; use _PyArg_NoPositionalStack() to keep the name lookup off the success path.

The vectorcall cases keep using constant strings since that slot does not inherit.


This is needed to keep parity moving frozenset to Argument Clinic I think in general it makes these error messages a little better for new.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cmaloney @claude
pythongh-87613: Name the subclass in Argument Clinic __new__ argume…
cc0e902
…nt errors

tp_new is inherited, so argument errors from a subclass named the base
type. While `tp_name` would be slightly faster to use it includes the
module name like `_thread.RLock()` which adds confusion. Use
`_PyType_Name(type)` which returns `RLock()`. Include a test to check.

_PyArg_NoPositional() only short-circuits when args is NULL, which
tp_new never gets; use _PyArg_NoPositionalStack() to keep the name
lookup off the success path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cmaloney
cmaloney requested review from AA-Turner and erlend-aasland as code owners October 28, 2026 03:28
@bedevere-app bedevere-app Bot added awaiting review type-feature A feature request or enhancement labels Oct 28, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 28, 2026
Generate vectorcall code to parse arguments using Argument Clinic #87613
Open
@cmaloney

cmaloney commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Changed my mind on this, pure python is the other way and I'd argue AC should match that:

>>> class Base:
...     def __new__(cls, a): ...
... class Sub(Base): pass
... 
... Sub(1, 2)  # Base.__new__() takes 2 positional arguments but 3 were given
... Sub(x=1)   # Base.__new__() got an unexpected keyword argument 'x'
... 
Traceback (most recent call last):
  File "<python-input-0>", line 5, in <module>
    Sub(1, 2)  # Base.__new__() takes 2 positional arguments but 3 were given
    ~~~^^^^^^
TypeError: Base.__new__() takes 2 positional arguments but 3 were given
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney cmaloney closed this Oct 28, 2026
@cmaloney
cmaloney deleted the clinic_new_tp_name branch October 28, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@cmaloney
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.