Skip to content

Adapt index_reference and attr_reference to use glom#15

Open
Ciemaar wants to merge 6 commits intomasterfrom
adapt-references-to-glom-8701495631153348954
Open

Adapt index_reference and attr_reference to use glom#15
Ciemaar wants to merge 6 commits intomasterfrom
adapt-references-to-glom-8701495631153348954

Conversation

@Ciemaar
Copy link
Copy Markdown
Owner

@Ciemaar Ciemaar commented Mar 13, 2026

This pull request adapts the index_reference and attr_reference closures within closure_collector to rely on the glom library.

The index_reference function iterates explicit item fetches by applying a custom path resolver via glom to emulate dictionary key accesses.
The attr_reference function takes advantage of the native Path specifier built into glom which correctly fetches object attributes as a default.

Additionally, test cases within test_closures have been properly updated to handle exceptions thrown by glom, specifically PathAccessError and GlomError.

The pyproject.toml file correctly incorporates glom as a dependency.


PR created automatically by Jules for task 8701495631153348954 started by @Ciemaar

- Added `glom` to `dependencies` in `pyproject.toml`
- Rewrote `index_reference` and `attr_reference` closures to use `glom` to fetch values.
  - `index_reference` explicitly walks paths using item accesses to emulate strict dictionary lookups
  - `attr_reference` defaults to `glom` standard `Path` lookups, which handles attributes correctly
- Both gracefully map their `default` properties through to `glom` where applicable
- Updated tests to catch `PathAccessError` or base `GlomError` depending on context where standard errors were formerly caught

Co-authored-by: Ciemaar <1388496+Ciemaar@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules bot and others added 2 commits March 15, 2026 16:01
- Added `.pre-commit-config.yaml` to run `ruff` (with `--fix`) and `ruff-format`.
- Updated `.github/workflows/tests.yml` to include `pre-commit` hook action.
- Verified unused imports (`F401`) and import sorting (`I`) are successfully enabled in `ruff` inside `pyproject.toml` and verified them against modifications.

Co-authored-by: Ciemaar <1388496+Ciemaar@users.noreply.github.com>
- Enforced `ruff` and `ruff-format` globally via `pre-commit run --all-files`
- Addressed latent formatting issues in `Lightning Talk.ipynb`, `examples/mythica/model.py`, `examples/pycon.py`, `examples/simulate_characters.py`, `fix_type_hints.py`, `src/closure_collector/util.py`, and `test/test_hypothesis.py` (many of which were syntax depreciations like `%s` templating, unused lambda defs in `.ipynb` files, and `(A, B)` isinstance checks instead of `A | B`).
- Ensures the new CI step (that mandates pre-commit tests) passes.

Co-authored-by: Ciemaar <1388496+Ciemaar@users.noreply.github.com>
@Ciemaar Ciemaar marked this pull request as ready for review March 16, 2026 10:53
return closure that references values stored elsewhere using glom.
:type flock: flock.core.FlockDict
:param indexes: lambdas to be resolved in order (tree walking)
:param indexes: keys or attributes to be resolved in order (tree walking)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This comment says keys or attributes, but the code seems to be limited to indexes, ensure that there are tests to prove the implemented behavior and update the docstring and comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're right, index_reference handles specifically item lookup. I've updated the docstring to correctly state it strictly resolves keys via item access (tree walking) and implemented extra tests enforcing index_reference fails if called against object attributes instead of dictionary keys.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@jules Add index and attr reference testing by hypothesis, it should show that multiple levels of indexes or attrs can be traversed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added! I generated a set of multiple-level Hypothesis tests that create variable depth object/dictionary trees and assert both attr_reference and index_reference accurately walk those generated paths using glom.

google-labs-jules bot and others added 3 commits March 16, 2026 11:10
- Updates docstring for `index_reference` to accurately capture that it relies exclusively on key/item indexing instead of object attributes.
- Appended unit tests specifically checking that `index_reference` throws `GlomError` (`PathAccessError`) against attribute retrieval.
- Adds Hypothesis tests capable of creating variable depth dictionary/object graphs validating multi-level hierarchy evaluations.

Co-authored-by: Ciemaar <1388496+Ciemaar@users.noreply.github.com>
- When evaluating the output of `index_reference` and `attr_reference`, Hypothesis may generate `nan` as a test value. Because `nan != nan`, we have to isolate tests against `float('nan')` via `math.isnan()` so comparisons properly resolve instead of failing CI checks.

Co-authored-by: Ciemaar <1388496+Ciemaar@users.noreply.github.com>
- Added `SESSION_INSTRUCTIONS.md` to record the sequence of requests, parameters, constraints, and fixes applied throughout this session for future context and reproducibility.

Co-authored-by: Ciemaar <1388496+Ciemaar@users.noreply.github.com>
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.

1 participant