[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-10-20 Thread Petr Viktorin


Change by Petr Viktorin :


--
resolution: fixed -> 
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-10-20 Thread Petr Viktorin


Petr Viktorin  added the comment:

Thank you, Stefan!

This should have a test as well.
I'm willing to mentor someone who wants to get into the C-API, otherwise this 
has low priority for me.

--
resolution:  -> fixed
stage: test needed -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-06-10 Thread Stefan Behnel


Stefan Behnel  added the comment:


New changeset 9419158a3e67ba2eadf33215568003ed723b0a98 by Miss Islington (bot) 
in branch '3.9':
bpo-40703: Let PyType_FromSpec() set "type.__module__" only if it is not set 
yet. (GH-20273) (GH-20782)
https://github.com/python/cpython/commit/9419158a3e67ba2eadf33215568003ed723b0a98


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-06-10 Thread Stefan Behnel


Change by Stefan Behnel :


--
stage: patch review -> test needed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-06-10 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 5.0 -> 6.0
pull_requests: +19977
pull_request: https://github.com/python/cpython/pull/20782

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-06-10 Thread Stefan Behnel


Stefan Behnel  added the comment:


New changeset 24b8bad6d30ae4fb37ee686a073adfa5308659f9 by scoder in branch 
'master':
bpo-40703: Let PyType_FromSpec() set "type.__module__" only if it is not set 
yet. (GH-20273)
https://github.com/python/cpython/commit/24b8bad6d30ae4fb37ee686a073adfa5308659f9


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-05-20 Thread hai shi


Change by hai shi :


--
nosy: +shihai1991

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-05-20 Thread Stefan Behnel


Change by Stefan Behnel :


--
keywords: +patch
pull_requests: +19553
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/20273

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40703] PyType_FromSpec*() overwrites the type's "__module__"

2020-05-20 Thread Stefan Behnel


New submission from Stefan Behnel :

The PyType_FromSpec() functions set the type's "__module__" attribute at the 
end:

https://github.com/python/cpython/blob/0509c4547fc95cc32a91ac446a26192c3bfdf157/Objects/typeobject.c#L3154-L3172

There are only two possible cases, either it finds a module name in the spec 
name and sets "__module__" from that, or it outputs a deprecation warning. Both 
behaviours are annoying because they ignore anything that the type already has 
in its dict, e.g. a property entry from the "members" or "getset" structs.

Since this code can't really be moved before the call to "PyType_Ready()" 
(which creates the type's dict and populates it), I think the best fix would be 
to first check if "__module__" is already in the dict and only otherwise take 
care of setting it.

I noticed this when trying to make the "__module__" attribute of Cython's 
coroutine type work with type specs, which should actually return the instance 
specific module name, i.e. the module that defines the coroutine, not the 
module that defines the type. This would normally be solved with an entry in 
"members", but that is discarded by the code above. While this approach means 
that the type does not have its own "__module__" entry, I think the use cases 
of pickling and documentation support it, because they care about the module 
name of the instance, not of the type.

I think working around this behaviour is somewhat easy by creating a new 
descriptor with PyDescr_NewMember() and re-adding it after calling 
PyType_FromSpec*(), so this is something that can just be fixed in Py3.9+.

Relevant tickets: issue 15146 for setting "__module__" and issue 20204 for the 
deprecation warning.

--
components: C API
messages: 369476
nosy: ncoghlan, petr.viktorin, scoder, serhiy.storchaka
priority: normal
severity: normal
status: open
title: PyType_FromSpec*() overwrites the type's "__module__"
type: behavior
versions: Python 3.10, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com