Skip to content

Conversation

@Tpt
Copy link
Contributor

@Tpt Tpt commented Jun 23, 2025

If users register "manually" some elements in the module using #[pymodule] or #[pymodule_init] functions, PyO3 is not able to introspect the full module content and stubs might be incomplete. In this case we properly tag the module as incomplete using the hack suggested in type stubs documentation, this way type checkers like Mypy won't fail on elements not listed in the stub.

@Tpt Tpt force-pushed the tpt/typing-exhaustive branch from 09da583 to 6595f19 Compare June 23, 2025 07:00
@Tpt Tpt force-pushed the tpt/typing-exhaustive branch from 6595f19 to 8bec1c2 Compare July 15, 2025 09:02
@Tpt Tpt force-pushed the tpt/typing-exhaustive branch from 8bec1c2 to fe22538 Compare July 15, 2025 09:28
@Tpt Tpt requested a review from davidhewitt July 18, 2025 10:47
@Tpt Tpt self-assigned this Jul 18, 2025
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, this seems correct to me.

I think we should consider starting guide content for the experimental-inspect feature soon. This in particular seems like a possible surprise for users which we should document.

I wonder if we can also have a way to opt-out of this in the future, by letting users manually supply the symbols which need introspection.

(both can be follow-ups we remember for later)

@davidhewitt davidhewitt added this pull request to the merge queue Jul 18, 2025
@Tpt
Copy link
Contributor Author

Tpt commented Jul 18, 2025

I think we should consider starting guide content for the experimental-inspect feature soon. This in particular seems like a possible surprise for users which we should document.

Noted, indeed.

I wonder if we can also have a way to opt-out of this in the future, by letting users manually supply the symbols which need introspection.

Yes, with maybe an optional argument to the pymodule_init attribute that would alllow the user to inject the extra stubs to make them complete

Merged via the queue into PyO3:main with commit 87c90a0 Jul 18, 2025
46 checks passed
@Tpt Tpt deleted the tpt/typing-exhaustive branch July 18, 2025 15:16
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.

2 participants