Skip to content

bpo-44232: Fix type_new() error reporting#26359

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:type_new
May 25, 2021
Merged

bpo-44232: Fix type_new() error reporting#26359
vstinner merged 1 commit into
python:mainfrom
vstinner:type_new

Conversation

@vstinner

@vstinner vstinner commented May 25, 2021

Copy link
Copy Markdown
Member

Fix a regression in type() when a metaclass raises an exception. The
C function type_new() must properly report the exception when a
metaclass constructor raises an exception and the winner class is not
the metaclass.

https://bugs.python.org/issue44232

@vstinner

Copy link
Copy Markdown
Member Author

cc @Fidget-Spinner

@Fidget-Spinner Fidget-Spinner left a comment

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.

LGTM.

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.

I'm not sure if it's worth mentioning in the blurb that this bug only affected people using debug builds. Release build users shouldnt have noticed anything.

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.

I think we should mention it as people use debug build outside Cpython development quite a lot

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't expect anyone to use a Python debug build until I saw https://bugs.python.org/issue44232

IMO it's worth it to document the bugfix since it impacts Django, but likely many more projects.

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.

Wow I need to stop sending messages late at night ;-). I'm really sorry this concern got lost in translation. I wasn't suggesting we get rid of the blurb. I was suggesting we add a line somewhere that says this only affects debug builds and not release ones. Previously I did that for another AssertionError crash in 3.9 - 3.10 because I was afraid people would read the blurb and think their Python is affected.

6a7fb9d

Anyways, I think it's fine if you dont want to. Thanks for fixing this :).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah ok. Well, the change is now merged, I'm fine with the merged NEWS entry :-)

Comment thread Objects/typeobject.c Outdated
Comment on lines 3259 to 3262

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.

Small nit, feel free to ignore

Suggested change
if (*type == NULL) {
return -1;
}
return 1;
return *type == NULL ? -1 : 1;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I prefer to "handle errors explicitly". Well, it's just a personal coding style preference.

@felixxm

felixxm commented May 25, 2021

Copy link
Copy Markdown
Contributor

@vstinner Thanks 👍 I can confirm that this patch works for us.

Fix a regression in type() when a metaclass raises an exception. The
C function type_new() must properly report the exception when a
metaclass constructor raises an exception and the winner class is not
the metaclass.
@vstinner

Copy link
Copy Markdown
Member Author

macOS: test_ssl failed, unrelated to the PR: https://bugs.python.org/issue44237

@vstinner
vstinner merged commit bd199e7 into python:main May 25, 2021
@vstinner
vstinner deleted the type_new branch May 25, 2021 20:28
@vstinner vstinner added the needs backport to 3.10 only security fixes label May 25, 2021
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label May 25, 2021
@bedevere-bot

Copy link
Copy Markdown

GH-26365 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2021
Fix a regression in type() when a metaclass raises an exception. The
C function type_new() must properly report the exception when a
metaclass constructor raises an exception and the winner class is not
the metaclass.
(cherry picked from commit bd199e7)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request May 26, 2021
Fix a regression in type() when a metaclass raises an exception. The
C function type_new() must properly report the exception when a
metaclass constructor raises an exception and the winner class is not
the metaclass.
(cherry picked from commit bd199e7)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants