-
Notifications
You must be signed in to change notification settings - Fork 25
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
Plum trying to double-register in doctest/pytest #167
Comments
@nstarman Do you have a MWE? Or could you link to a CI run which exhibits the warning when it shouldn't? I've been investigating redefinition warnings on my end, and have already uncovered a few issues in both Plum and packages using Plum. This seems to have been a very useful addition! |
https://github.com/GalacticDynamics/quaxed/actions/runs/9576983536/job/26404429851 for a CI run. Without line numbers I wasn't able to trace back to confirm. |
Thanks, @nstarman! The methods are registered upon the first function invocation, not when these methods are defined, to deal with types that might not yet exist when the function is defined, e.g. in the case of forward references. With regard to your redefinition warnings, I had a look at the internals of from numbers import Number
from typing import Optional
import numpy as np
from plum import dispatch
@dispatch
def arange1(
start: Number,
/,
stop: Optional[Number] = None,
step: Optional[Number] = None,
):
return np.arange(start, stop)
print(arange1.methods)
@dispatch
def arange2(
start: Number,
stop: Optional[Number] = None,
*,
step: Optional[Number] = None,
):
return np.arange(start, stop)
print(arange2.methods) This gives the following output:
Note that the last two methods in each list have the same signature (keyword arguments don't count). These are exactly which are redefined: from numbers import Number
from typing import Optional
import numpy as np
from plum import dispatch
@dispatch
def arange(
start: Number,
/,
stop: Optional[Number] = None,
step: Optional[Number] = None,
):
return np.arange(start, stop)
@dispatch
def arange(
start: Number,
stop: Optional[Number] = None,
*,
step: Optional[Number] = None,
):
return np.arange(start, stop)
print(arange.methods)
|
Thanks for the diagnosis! |
Thanks! This solves most issues. I'll open a new issue for what it doesn't. |
@nstarman, perfect! As @PhilipVinc suggested, maybe the redefinition warnings are too aggressive and we should provide a mechanism to silence them. I suggested an opt out mechanism for packages, but perhaps making it an option of |
I had two double definitions so this helped me notice them. |
You’re right that this was too big of a change at once. Even though it is turning out to be a useful debug tool, I’m thinking that throwing a warning at every redefinition is too aggressive, as there could be scenarios where redefinitions are intended. I’m considering to make redefinition warnings opt in, in the following way: |
The issue seems to be that plum is trying to register the same function twice! E.g. I'm seeing this and both
impl
have the exact same memory address.Originally posted by @nstarman in #166 (comment)
The text was updated successfully, but these errors were encountered: