Skip to content

fix(regression): support embedded submodule #5650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

henryiii
Copy link
Collaborator

@henryiii henryiii commented May 9, 2025

Description

Fix #5649.

Suggested changelog entry:

* Fix a regression in #5584.

@henryiii henryiii force-pushed the henryiii/fix/embeddedsubmod branch from 36effe9 to 1972a8a Compare May 10, 2025 14:38
if (!this_file) {
if (this_file) {
result.attr("__file__") = this_file;
} else if (PyErr_ExceptionMatches(PyExc_SystemError) != 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ugh ... if we have to catch a SystemError here to accommodate submodules, I regret posting this comment on PR #5584.

I think it'll be best to get rid of this #else branch then.

Choose a reason for hiding this comment

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

Python even throws exceptions when iterating over ranges. I would expect Python's low level C error handling to be more lightweight (if one can say that when it comes to python) than what happens if this were translated to a C++ exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should be extremely rare, this is only for embedded submodules, normally it works. I think it's probably fine to leave this way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Up to you, I'm OK if you want to keep it.

What still makes me feel uneasy: the risk of masking unexpected SystemErrors.

Which is of course extremely low, but not zero. (Google experience: anything that can happen, does happen.)

Choose a reason for hiding this comment

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

The function is part of the Stable API and just accesses a dictionary. My two cents: the current implementation is safe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have a link to the implementation handy?

What's on my mind: Why does it raise SystemError, and not AttributeError?

I'd feel more cozy ignoring an AttributeError.

But as I said, I'm fine with this.

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

The function explicitly sets the system error.

Seems like an unfortunate choice, to have it in the same class of exceptions as e.g. out-of-memory, but 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

>>> SystemError.__mro__
(<class 'SystemError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>)
>>> MemoryError.__mro__
(<class 'MemoryError'>, <class 'Exception'>, <class 'BaseException'>, <class 'object'>)

https://docs.python.org/3/library/exceptions.html#SystemError

Raised when the interpreter finds an internal error, but the situation does not look so serious to cause it to abandon all hope.

Doesn’t seem too bad, I think it’s for things like this, exceptions that shouldn’t make it up to the user.

@henryiii henryiii changed the title tests: add test for embedded submodule fix(regression): add test for embedded submodule May 10, 2025
@henryiii henryiii changed the title fix(regression): add test for embedded submodule fix(regression): support embedded submodule May 10, 2025
@henryiii henryiii marked this pull request as ready for review May 10, 2025 19:15
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

A small suggestion.

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.

[BUG]: cannot register submodules for embedded modules
3 participants