-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
"DeprecationWarning: builtin type has no __module__ attribute" when using PyStructSequence_NewType from a module method #124182
Comments
I'm following this issue,maybe you can awaiting message for me. |
I'm not totally sure if this was the original intention, but it seems like |
If that's not how it's supposed to work, I can totally put together a PR to sort it out. |
The warning is triggered by Line 5068 in 4420cf4
r == 0 and there’s no secondary reference , it raises this warning. To get rid of the warning, you could add a __module__ entry when it’s zero, but the value for that key-value pair seems uncertain and makes the rest of the logic pointless. Lines 5069 to 5092 in 4420cf4
|
It's an issue in your extension. The warning means that the type name has no module name. You should replace: PyStructSequence_Desc desc = {"TypeName", "docs", fields, 1}; with: PyStructSequence_Desc desc = {"c_ext.TypeName", "docs", fields, 1}; where |
This comment was marked as duplicate.
This comment was marked as duplicate.
Hi @rruuaanng, please could you try and make fewer comments where they don't add much to the discussion? For example, there's no need to quote Victor's last comment and only ping the OP - it's safe to assume they're subscribed to their own issue. Thanks. |
Fair enough, thanks. I did not think that the type name was more than aesthetics. The only question that remains then is why InitType behaves differently (better?) with it defaulting to builtins (although still not including it in the type's repr). It might also be helpful to mention that the module name must be included in the documentation for the name field. If you think it's fine the way it is then this can be closed. |
PyStructSequence_InitType() and PyStructSequence_InitType2() are legacy APIs for static types, you should use PyStructSequence_NewType() for heap types. |
Does someone want to propose a PR for that? The function is documented in Doc/c-api/tuple.rst. |
The rules seem to be similar to this, so I took that as a base, removed the parts that deal with types that don't belong to a module and mentioned that a dot must be included. |
…onGH-124335) (cherry picked from commit 3287c83) Co-authored-by: ffelixg <[email protected]>
…onGH-124335) (cherry picked from commit 3287c83) Co-authored-by: ffelixg <[email protected]>
Bug report
Bug description:
Below is an example producing the warning. This warning does not occur when the type is created in the module's init function.
When using
PyStructSequence_InitType2
, the resulting type gets"builtin"
as the__module__
attribute and there is no deprecation warning.It's also possible to add a field named
__module__
to prevent the warning. Setting the__module__
attribute after creating the type does not help, the warning gets raised inside thePyStructSequence_NewType
function.I couldn't find anything indicating that I'm not supposed to use
PyStructSequence_NewType
in this way.CPython versions tested on:
3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: