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
@overload decorator on compiled functions is not tested #96478
try:
_overload_registry[f.__module__][f.__qualname__][f.__code__.co_firstlineno] =funcexceptAttributeError:
# Not a normal function; ignore.raise# pass
test_typing continues to pass as expected. I think it is dangerous, because we can accidentally break something and not notice.
I will send a simple test case to catch this: we should not fail.
f=getattr(func, "__func__", func)
try:
_overload_registry[f.__module__][f.__qualname__][f.__code__.co_firstlineno] =funcexceptAttributeError:
# Not a normal function; ignore.passreturn_overload_dummy
If we wanted to get rid of the side effect, we could maybe change the code to something like this:
f=getattr(func, "__func__", func)
try:
mod, qualname, lineno=f.__module__, f.__qualname__, f.__code__.co_firstlinenoexceptAttributeError:
# Not a normal function; ignore.passelse:
_overload_registry[mod][qualname][lineno] =funcreturn_overload_dummy
But we worked quite hard to make sure that the performance regression introduced by making overloads retrievable at runtime was as small as possible. So I'd want to make sure that this didn't make things any slower.
I don't think that we want to remove this side-effect. get_overloads still works correctly for end users 🤔
Moreover, annotating C functions is not that common. It is more like an exceptional case.
Slowing down regular use-cases is not worth it in my opinion.
I don't think that we want to remove this side-effect. get_overloads still works correctly for end users 🤔
Moreover, annotating C functions is not that common. It is more like an exceptional case. Slowing down regular use-cases is not worth it in my opinion.
Yeah, the possibility of this side effect causing a memory leak is pretty minimal :)
Activity
pythongh-96478: Test `@overload` on C functions
pythongh-96478: Test `@overload` on C functions
pythongh-96478: Test `@overload` on C functions
sobolevn commentedon Sep 1, 2022
Moreover, this has a side-effect:
creates a following entry in
_overload_registry:sobolevn commentedon Sep 1, 2022
This happens because only the last
[f.__code__.co_firstlineno] = funcpart offails with
AttrtibuteError. Others are keys are recorded already by adefaultdict. I don't think it is a big deal, but it is surely interesting.AlexWaygood commentedon Sep 1, 2022
The current code for
overload()is:If we wanted to get rid of the side effect, we could maybe change the code to something like this:
But we worked quite hard to make sure that the performance regression introduced by making overloads retrievable at runtime was as small as possible. So I'd want to make sure that this didn't make things any slower.
sobolevn commentedon Sep 1, 2022
I don't think that we want to remove this side-effect.
get_overloadsstill works correctly for end users 🤔Moreover, annotating C functions is not that common. It is more like an exceptional case.
Slowing down regular use-cases is not worth it in my opinion.
AlexWaygood commentedon Sep 1, 2022
Yeah, the possibility of this side effect causing a memory leak is pretty minimal :)
gh-96478: Test `@overload` on C functions (#96479)
pythongh-96478: Test `@overload` on C functions (pythonGH-96479)
Backport python/cpython#96479
Backport python/cpython#96479 (#73)
pythongh-96478: Fix new test when run in refleak mode
gh-96478: Fix new test when run in refleak mode (#96615)
gh-96478: Test `@overload` on C functions (GH-96479)
pythongh-96478: Fix new test when run in refleak mode (pythonGH-96615)
gh-96478: Fix new test when run in refleak mode (GH-96615)
kumaraditya303 commentedon Sep 30, 2022
Fixed by #96479