Skip to content

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

Merged
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
feiiiiii5:fix/default-subclass-flag
Aug 24, 2026
Merged

FIX: honor include_subclasses=False for the registered class itself#2471
Roman Lutz (romanlutz) merged 3 commits 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.

Comment thread pyrit/common/apply_defaults.py
…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.
@feiiiiii5
fei (feiiiiii5) force-pushed the fix/default-subclass-flag branch from 5279cfa to 66a1e17 Compare August 24, 2026 06:15
fei (feiiiiii5) and others added 2 commits August 24, 2026 19:31
…s the old scope

set_default_value() now removes the opposite include_subclasses scope for the
same (class, parameter) before storing, so True-then-False re-registration
lets the newer value win for the registered class and stops subclasses from
inheriting the removed True-scope default (lookup checks the True scope
first). Regression tests cover both flag directions.

Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Aug 24, 2026
Merged via the queue into microsoft:main with commit d503ecf Aug 24, 2026
54 checks passed
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