You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
3.13.0b3: undocumented change in inspect.isroutine() for functools.partial #122087
Prior to 3.13.0b3, it would evaluate to False. In newer versions, it evaluates to True.
A bisect points out that it changed as a result of 49e5740 (i.e. #121086). Neither the commit message, nor the news entry, hints anything about inspect.isroutine() behavior.
Could you please clarify whether the change was intentional? And if it was, could we have it explicitly noted in the documentation?
Reviewing the issue, I suspect functools.partial may need further special-casing in inspect for 3.13 (the addition of the descriptor method doesn't currently change its behaviour, but some of the inspect functions are already treating it as if the 3.14 change was already in effect)
Unfortunately, the only way to add a warning about a partial object being made a method descriptor in the future is to make it a method descriptor. We can make inspect.ismethoddescriptor() lying about partial objects, but this will not help the user code which check the __get__ method directly. I do not know how to break this loop.
What's the expected result in 3.14? Is partial() there expected to be recognized as a routine, and not have a __name__ attribute? Ideally, is there some documentation that explains whether __name__ is expected on all routines or not?
Activity
mgorny commentedon Jul 21, 2024
CC @serhiy-storchaka
hugovk commentedon Jul 21, 2024
I added the release-blocker label to make sure this is addressed one way or another before RC1 on the 30th.
ncoghlan commentedon Jul 22, 2024
Reviewing the issue, I suspect
functools.partialmay need further special-casing ininspectfor 3.13 (the addition of the descriptor method doesn't currently change its behaviour, but some of the inspect functions are already treating it as if the 3.14 change was already in effect)In the backport PR, https://github.com/python/cpython/pull/121092/files#diff-b89cd06e4637abacb73f2500301ff979a67ad7ecbfa7cf151c7243715898d7eaL2558 adjusted
_signature_from_callableto avoid having the addition of__get__change the reported signature, which was enough to keep CI happy, but it appears that doesn't cover the whole of theinspectmodule when it comes topartialobject handling.encukou commentedon Jul 23, 2024
@serhiy-storchaka, will you be able to look at this before rc1?
serhiy-storchaka commentedon Jul 24, 2024
Unfortunately, the only way to add a warning about a partial object being made a method descriptor in the future is to make it a method descriptor. We can make
inspect.ismethoddescriptor()lying aboutpartialobjects, but this will not help the user code which check the__get__method directly. I do not know how to break this loop.mgorny commentedon Jul 24, 2024
What's the expected result in 3.14? Is
partial()there expected to be recognized as a routine, and not have a__name__attribute? Ideally, is there some documentation that explains whether__name__is expected on all routines or not?pythongh-122087: Restore ismethoddescriptor() and isroutine() for par…
pythongh-122087: Add tests for ismethoddescriptor() and isroutine() w…
serhiy-storchaka commentedon Jul 24, 2024
Yes, not all method descriptors (and therefore not all routines) have the
__name__attribute. This always was so, you always should have a fallback.#122218 add a special case for
partialinismethoddescriptor()and tests for 3.13. #122219 adds corresponding tests for main branch.[3.13] gh-122087: Restore ismethoddescriptor() and isroutine() for pa…
gh-122087: Add tests for ismethoddescriptor() and isroutine() with pa…