Skip to content

Refactor: Extract inline normalizer closures in json_base.py#721

Merged
fderuiter merged 1 commit intomainfrom
refactor/json-base-normalizers-14322012092737742143
Mar 2, 2026
Merged

Refactor: Extract inline normalizer closures in json_base.py#721
fderuiter merged 1 commit intomainfrom
refactor/json-base-normalizers-14322012092737742143

Conversation

@fderuiter
Copy link
Owner

This PR extracts inline function closures used for normalizing optional types in JsonModel's _get_normalizer method into explicit, private module-level functions.

This change reduces runtime overhead by avoiding repeated closure instantiation in the hot parsing path and drastically reduces the cognitive load of reading the conditional parsing rules.

Tested successfully against existing parsing and modeling test suites with no regressions.


PR created automatically by Jules for task 14322012092737742143 started by @fderuiter

To reduce cognitive load and avoid the overhead of dynamically creating
nested functions (closures) during runtime, the normalizer functions for
optional types (str, int, bool, datetime) have been extracted to private
module-level functions:
- `_optional_str`
- `_optional_int`
- `_optional_bool`
- `_optional_datetime`

This aligns with the Architect manifesto (KISS, Explicit > Implicit).

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
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.

@fderuiter fderuiter marked this pull request as ready for review March 2, 2026 15:39
Copilot AI review requested due to automatic review settings March 2, 2026 15:39
@fderuiter fderuiter merged commit 4540598 into main Mar 2, 2026
13 checks passed
@fderuiter fderuiter deleted the refactor/json-base-normalizers-14322012092737742143 branch March 2, 2026 15:39
Copy link
Contributor

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 refactors JsonModel’s normalization logic by extracting previously inline optional-type normalizer closures in _get_normalizer into private module-level functions, reducing repeated closure creation on the validation hot path.

Changes:

  • Added module-level optional normalizers (_optional_str, _optional_int, _optional_bool, _optional_datetime).
  • Simplified _get_normalizer by selecting either the optional wrapper or the base parser function directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants