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
Basically, if @define is applied to a class def with a dunder attribute name, like __x__, then calling evolve on an instance of this class raises an exception. This is because evolve only removes the first_ leading underscore, whereas the generated __init__(self, x__=..., ...) removes all leading underscores.
The fix is to use lstrip(name, "_") in the evolve function.
I gather that Attribute will be getting an alias member, which evolve() will make use of, rather than doing the stripping on its own. This might fix the problem. At least if define() makes use of that feature without the class def having to use it explicitly.
A test case could be:
@attrs.defineclassC:
__x__: int__y__: int=42__z: int=42# mangled to _C__z.C(0).evolve() # Should not raise an exception
Basically, if
@define
is applied to a class def with a dunder attribute name, like__x__
, then callingevolve
on an instance of this class raises an exception. This is becauseevolve
only removes the first_ leading underscore, whereas the generated__init__(self, x__=..., ...)
removes all leading underscores.The fix is to use
lstrip(name, "_")
in theevolve
function.I gather that
Attribute
will be getting analias
member, whichevolve()
will make use of, rather than doing the stripping on its own. This might fix the problem. At least ifdefine()
makes use of that feature without the class def having to use it explicitly.A test case could be:
See #1060.
The text was updated successfully, but these errors were encountered: