Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion abses/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def steps(self, steps: int) -> None:
Parameters:
steps: Number of steps. If > 0, automatically advances time.
"""
delta = steps - getattr(self, "_steps", 0)
old_steps = self.__dict__.get("_steps", 0)
delta = steps - old_steps
if not isinstance(delta, int):
raise TypeError(f"Steps must be an integer, got {type(steps)}")
Comment on lines 186 to 187
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Type validation checks the wrong variable.

The type check validates delta (the computed difference) rather than the steps parameter. Since delta = steps - old_steps, if steps is a non-integer type, either:

  1. Line 185 raises TypeError during subtraction (if steps is incompatible), or
  2. delta becomes non-int (if steps is float-like), triggering the check on line 186

However, the error message reports type(steps), not type(delta), creating confusion. Validate steps directly before computing delta:

-    old_steps = self.__dict__.get("_steps", 0)
-    delta = steps - old_steps
     if not isinstance(delta, int):
         raise TypeError(f"Steps must be an integer, got {type(steps)}")
+    if not isinstance(steps, int):
+        raise TypeError(f"Steps must be an integer, got {type(steps)}")
+    old_steps = self.__dict__.get("_steps", 0)
+    delta = steps - old_steps
     if delta > 0:
         self.time.go(delta)

Note: The parameter already has a type hint (steps: int), so static type checkers should catch this, but explicit runtime validation at the correct point improves clarity.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
abses/core/model.py around lines 186-187: the runtime type check currently
validates the computed variable `delta` and then raises an error mentioning
`type(steps)`, which is confusing and occurs too late; instead validate the
incoming `steps` parameter before computing `delta` by checking
isinstance(steps, int) and raise a TypeError that reports the actual type(steps)
if it fails, then compute `delta = steps - old_steps` as before.

if delta > 0:
Expand Down
Loading