Skip to content

FIX: honor include_subclasses=False for the registered class itself - #2471

Open
fei (feiiiiii5) wants to merge 1 commit into
microsoft:mainfrom
feiiiiii5:fix/default-subclass-flag
Open

FIX: honor include_subclasses=False for the registered class itself#2471
fei (feiiiiii5) wants to merge 1 commit into
microsoft:mainfrom
feiiiiii5:fix/default-subclass-flag

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Description

GlobalDefaultValues.get_default_value() only probed the exact scope with include_subclasses=True. A default registered with include_subclasses=False was therefore unreachable for every class — including the class it was registered for — because the exact-match probe used the wrong flag and the parent-class fallback loop skips registrations whose flag is False.

The flag is documented as "whether this default should apply to subclasses as well", so a False registration must still apply to the registered class itself while stopping short of inheritance.

Change

The exact-match lookup now tries both registration flags on the (class_type, parameter_name) scope before falling back to the inheritance loop. This also means a False registration no longer needs the fallback loop at all for its own class.

Tests

  • test_global_default_values_no_subclass_still_applies_to_baseFalse registration resolves for the base class, not the child (pre-fix: FAIL — value was unreachable).
  • test_global_default_values_mixed_flags_same_param — base-only False + child True registrations on the same parameter resolve independently (pre-fix: FAIL on the child-visible case).
  • Existing suite: tests/unit/common/test_apply_defaults.py + test_pyrit_default_value.py66 passed; ruff check + format clean.
  • Pre-fix/post-fix verified with git checkout HEAD~1 -- <file>: both new tests fail on the old implementation.

…itself

GlobalDefaultValues.get_default_value() previously only looked up the
exact scope with include_subclasses=True. A default registered with
include_subclasses=False was therefore unreachable for every class -
including the very class it was registered for - because the exact-match
probe used the wrong flag and the parent-class fallback loop skips
registrations whose flag is False.

The flag's documented meaning is 'apply to subclasses as well', so a
False registration must still apply to the registered class itself
while stopping short of inheritance. The lookup now probes both flags
for the exact (class_type, parameter_name) scope before falling back to
the inheritance loop.

Added regression tests: no-subclass default resolves for the base class
but not the child, and mixed-flag registrations on base/child resolve
independently.
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