@@ -46,39 +46,25 @@ class Agent:
46
46
# so, unique_id is unique relative to a model, and counting starts from 1
47
47
_ids = defaultdict (functools .partial (itertools .count , 1 ))
48
48
49
- def __init__ (self , * args , ** kwargs ) -> None :
49
+ def __init__ (self , model : Model , * args , ** kwargs ) -> None :
50
50
"""Create a new agent.
51
51
52
52
Args:
53
53
model (Model): The model instance in which the agent exists.
54
- args: currently ignored, to be fixed in 3.1
55
- kwargs: currently ignored, to be fixed in 3.1
56
- """
57
- # TODO: Cleanup in future Mesa version (3.1+)
58
- match args :
59
- # Case 1: Only the model is provided. The new correct behavior.
60
- case [model ]:
61
- self .model = model
62
- self .unique_id = next (self ._ids [model ])
63
- # Case 2: Both unique_id and model are provided, deprecated
64
- case [_, model ]:
65
- warnings .warn (
66
- "unique ids are assigned automatically to Agents in Mesa 3. The use of custom unique_id is "
67
- "deprecated. Only input a model when calling `super()__init__(model)`. The unique_id inputted is not used." ,
68
- DeprecationWarning ,
69
- stacklevel = 2 ,
70
- )
71
- self .model = model
72
- self .unique_id = next (self ._ids [model ])
73
- # Case 3: Anything else, raise an error
74
- case _:
75
- raise ValueError (
76
- "Invalid arguments provided to initialize the Agent. Only input a model: `super()__init__(model)`."
77
- )
54
+ args: passed on to super
55
+ kwargs: passed on to super
78
56
79
- self .pos : Position | None = None
57
+ Notes:
58
+ to make proper use of python's super, in each class remove the arguments and
59
+ keyword arguments you need and pass on the rest to super
80
60
61
+ """
62
+ super ().__init__ (* args , ** kwargs )
63
+
64
+ self .model : Model = model
81
65
self .model .register_agent (self )
66
+ self .unique_id : int = next (self ._ids [model ])
67
+ self .pos : Position | None = None
82
68
83
69
def remove (self ) -> None :
84
70
"""Remove and delete the agent from the model."""
0 commit comments