✨ Implement LaserFrame.__contains__() with DataFrame-style property/column membership - #422
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds DataFrame-like column membership semantics to LaserFrame via a new __contains__ implementation, enabling safe checks like "age" in lf for properties and selected instance attributes.
Changes:
- Implement
LaserFrame.__contains__to returnTruefor registered property names and non-underscored instance attributes, andFalsefor non-strings and underscored/internal instance attributes. - Add a new test suite covering
inbehavior for scalar/vector/array properties, kwargs-set attributes, unknown names, non-string items, and class-level methods/properties. - Document the new membership semantics in
CHANGELOG.rst.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/laser/core/laserframe.py |
Adds __contains__ to provide column-style membership checks against _properties and non-underscored instance attributes. |
tests/test_laserframe.py |
Adds new tests pinning the intended __contains__ contract and preventing regression to the prior super().__contains__ error. |
CHANGELOG.rst |
Describes the new LaserFrame.__contains__ semantics and their intent for callers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4ecc72a to
08c0ca5
Compare
08c0ca5 to
1334156
Compare
| return self._count | ||
|
|
||
| def __contains__(self, item) -> bool: | ||
| # Column-style membership: True for any name LaserFrame's documented access |
There was a problem hiding this comment.
GPT thought the doc string could be tweaked to emphasize the most surprising element of the design (allowing preceding underscores to be treated the regular attributes). I of course understand why we're doing this but GPT thought it's genuinely a little surprising to a python-trained mind.
For your consideration. Otherwise all makes sense.
jonathanhhb
left a comment
There was a problem hiding this comment.
"Request change" is more "consider slight doc string change". Not required.
membership Adds a `__contains__` method that returns `True` for property names and non-underscored kwargs-set attributes, and `False` for underscored backing arrays, internal state, methods, class-level descriptors, and non-string items. Includes ten new tests covering the full contract.
1334156 to
b59b77b
Compare
Rationale
Some "syntactic sugar" that is useful for validation ("my component needs this property to exist on the LaserFrame to work correctly") or customization ("if no one else has added this property, then I will so my component can function correctly").
Adds a
__contains__method that returnsTruefor property names and non-underscored kwargs-set attributes, andFalsefor underscored backingarrays, internal state, methods, class-level descriptors, and non-string items. Includes ten new tests covering the full contract.
Fixes #275