Skip to content

Commit

Permalink
fix lambda closure
Browse files Browse the repository at this point in the history
  • Loading branch information
timoklein committed Oct 28, 2024
1 parent 0d7a30b commit 5c1d3c9
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions navix/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ def __init_subclass__(cls, **kwargs):
default = getattr(cls, f_name, dataclasses.MISSING)
if isinstance(default, Array):
# Create a field with a lambda as default factory to prevent mutable default values
f = dataclasses.field(default_factory=lambda: default)
f = dataclasses.field(default_factory=lambda default=default: default)
f.name = f_name
f.type = f_type
# Remove the field from the dataclass and replace by modified one
setattr(cls, f.name, f)

# BUG: locals() only stores a single value for defaults
if str(cls) == "<class 'navix.states.Event'>":
import ipdb; ipdb.set_trace(context=21)
struct.dataclass(cls, **kwargs) # pytype: disable=wrong-arg-types


Expand Down

0 comments on commit 5c1d3c9

Please sign in to comment.