-
Notifications
You must be signed in to change notification settings - Fork 24
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
Warning about double-registration #171
Comments
@patrick-kidger, I managed to isolate the problem somewhat and Equinox is involved. Here'a MWE that raises a warning from collections.abc import Mapping
from dataclasses import dataclass
import equinox as eqx
from plum import dispatch
class Class(eqx.Module):
a: float
b: float
@classmethod
@dispatch
def constructor(cls: "type[Class]", obj: Mapping[str, float], /) -> "Class":
return cls(**obj) Emits |
Sorry @patrick-kidger, that may hav been a spurious finding. When I updated equinox this wasn't sourced by equinox any more. |
@nstarman, hmmm, I seem to be unable to reproduce the issue in a fresh environment with Python 3.10: Python 3.10.13 (main, Jan 16 2024, 14:46:45) [Clang 14.0.0 (clang-1400.0.29.202)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.26.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from collections.abc import Mapping
...: from dataclasses import dataclass
...:
...: import equinox as eqx
...: from plum import dispatch
...:
...: class Class(eqx.Module):
...: a: float
...: b: float
...:
...: @classmethod
...: @dispatch
...: def constructor(cls: "type[Class]", obj: Mapping[str, float], /) -> "Class":
...: return cls(**obj)
...:
In [2]: Class.constructor._f.methods
Out[2]:
List of 1 method(s):
[0] constructor(cls: type, obj: collections.abc.Mapping) -> __main__.Class
<function Class.constructor at 0x10a530af0> @ /<ipython-input-1-9a739e5fe7aa>:11 Could it possibly be the case that you accidentally ran the snippet twice in the same session? That would produce a redefinition error: In [1]: from collections.abc import Mapping
...: from dataclasses import dataclass
...:
...: import equinox as eqx
...: from plum import dispatch
...:
...: class Class(eqx.Module):
...: a: float
...: b: float
...:
...: @classmethod
...: @dispatch
...: def constructor(cls: "type[Class]", obj: Mapping[str, float], /) -> "Class":
...: return cls(**obj)
...:
In [2]: Class.constructor._f.methods
Out[2]:
List of 1 method(s):
[0] constructor(cls: type, obj: collections.abc.Mapping) -> __main__.Class
<function Class.constructor at 0x10a530af0> @ /<ipython-input-1-9a739e5fe7aa>:11
In [3]: from collections.abc import Mapping
...: from dataclasses import dataclass
...:
...: import equinox as eqx
...: from plum import dispatch
...:
...: class Class(eqx.Module):
...: a: float
...: b: float
...:
...: @classmethod
...: @dispatch
...: def constructor(cls: "type[Class]", obj: Mapping[str, float], /) -> "Class":
...: return cls(**obj)
...:
/Users/wessel/Desktop/venv/lib/python3.10/site-packages/plum/resolver.py:269: MethodRedefinitionWarning: `Method(function_name='constructor', signature=Signature(type[__main__.Class], collections.abc.Mapping[str, float]), return_type=<class '__main__.Class'>, impl=<function Class.constructor at 0x103b94280>)` overwrites the earlier definition `Method(function_name='constructor', signature=Signature(type[__main__.Class], collections.abc.Mapping[str, float]), return_type=<class '__main__.Class'>, impl=<function Class.constructor at 0x10a530af0>)`.
warnings.warn( |
Oops, I completely missed your last message, @nstarman! Glad that the issue seems to have gone away. :) Is this ready to be closed? |
I'm still getting the issue everywhere in GalacticDynamics/coordinax#128. It's just not (maybe?) caused by Equinox. I'm suspicious of |
Hmm, let's leave it open for now then to see if anything else comes up. I'll try to release the |
Great. I'll probably use that in |
@nstarman |
In GalacticDynamics/coordinax#128 I am trying to build with plum v2.4.3, but I am seeing many MethodRedefinitionWarning warnings about my constructor methods, but the earlier definition it compares against is the same function!
e.g.
where both functions are 0x7fc60876f2e0.
The text was updated successfully, but these errors were encountered: