Skip to content

Conversation

@kenblu24
Copy link
Owner

@kenblu24 kenblu24 commented Sep 9, 2025

  • Moved HookList to utils.py
  • World.population and World.objects are now properties
  • Fixed World.quad not being defined at init time
  • BinaryFOVSensor will skip update if world.quad is None
  • HookLists now properly calls add/delete callbacks on all list modification operations, i.e. extend, insert, setitem, etc.
    • Previously, HookList only notified callbacks on .append
    • HookList.__setitem__ (i.e. population[:] = iterable) calls del_callback on the items being replaced and add_callback on the new items
    • each func in HookList._add_callbacks is called for:
      • HookList.__init__ (if you somehow manage to create a new one with callbacks on it)
      • HookList.append
      • HookList.extend
      • HookList.insert
      • HookList.__iadd__
      • HookList.__imul__
      • HookList.__setitem__
    • each func in HookList._del_callbacks is called for:
      • HookList.pop
      • HookList.remove
      • HookList.__setitem__

@kenblu24 kenblu24 requested a review from Copilot September 9, 2025 14:55
@kenblu24 kenblu24 self-assigned this Sep 9, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR overhauls the HookList API to comprehensively capture all list modification events, moving the implementation to a dedicated utils module and fixing several initialization and callback issues.

Key changes:

  • Moved HookList implementation from World.py to utils/collections.py with enhanced callback support
  • Converted World.population and World.objects to properties with proper HookList backing
  • Fixed World.quad initialization and BinaryFOVSensor handling of None quad values

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/swarmsim/world/World.py Moved HookList to utils, converted population/objects to properties with private backing fields
src/swarmsim/world/RectangularWorld.py Updated method names to snake_case and fixed quad initialization
src/swarmsim/util/collections.py Added comprehensive HookList implementation with full callback support
src/swarmsim/sensors/BinaryFOVSensor.py Added null check for world.quad and updated property reference
demo/population_hook_test.py Updated to use new HookList callback registration methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kenblu24 kenblu24 merged commit a7b8575 into main Sep 9, 2025
2 checks passed
@kenblu24 kenblu24 deleted the hooklist-newapi branch October 25, 2025 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants