Skip to content

chore(deprecations): scope literal lookup to function bodies#775

Merged
CFenner merged 1 commit into
openviess:masterfrom
lackas:fix/deprecation-checker-scope
Jun 18, 2026
Merged

chore(deprecations): scope literal lookup to function bodies#775
CFenner merged 1 commit into
openviess:masterfrom
lackas:fix/deprecation-checker-scope

Conversation

@lackas

@lackas lackas commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Resolves the 5 long-standing "deprecated features used in code" warnings that the deprecation checker has been reporting on every master push since #707. The Format workflow's validate deprecation database step has been red continuously since the deprecation DB was introduced — but the warnings turn out to all be false positives from the segment-lookup heuristic.

The flagged features

  ventilation.operating.programs.comfort        Used in: PyViCareVentilationDevice.py
  ventilation.operating.programs.eco            Used in: PyViCareVentilationDevice.py
  ventilation.operating.programs.forcedLevelFour  Used in: PyViCareVentilationDevice.py
  ventilation.operating.programs.holiday        Used in: PyViCareVentilationDevice.py
  ventilation.operating.programs.silent         Used in: PyViCareVentilationDevice.py

Why these aren't actually used

PyViCareVentilationDevice.py has exactly one getProperty call against ventilation.operating.programs.*, in getVentilationPrograms():

for program in ['basic', 'intensive', 'reduced', 'standard', 'standby', 'holidayAtHome', 'permanent']:
    if self.getProperty(f"ventilation.operating.programs.{program}") is not None:
        ...

Zero overlap with the flagged features. But the same file has, in the orthogonal getVentilationQuickmodes(), a separate loop that queries the unrelated ventilation.quickmodes.* path:

for quickmode in ['comfort', 'eco', 'forcedLevelFour', 'holiday', 'standby', 'silent']:
    if self.getProperty(f"ventilation.quickmodes.{quickmode}") is not None:

The checker's confirmation step searches for each candidate segment value ('comfort', …) as a string literal anywhere in the same file — so it found them in the quickmodes loop and accepted them as proof that ventilation.operating.programs.comfort is referenced. Same mechanism for the other four.

The fix

find_code_usage() now uses ast.parse to extract each FunctionDef / AsyncFunctionDef body as an independent scope. feature_matches_code() searches only within the scope that contains the getProperty call. Top-level / class-body statements outside any function are scanned as one residual scope so non-function code isn't missed.

Verification

  • python check_deprecations.py --update now exits 0 against master (was 1)
  • The 5 spurious in-code warnings are gone; the 107 past-removal features with no real use now correctly classify under "Past removal date (not used in code)"
  • Confirmed no real positives are silently swept: there's exactly one ventilation.operating.programs.* getProperty call in the whole codebase (the one in getVentilationPrograms), and none of its iteration values are in the DB
  • All 729 PyViCare tests still pass

The deprecation checker's segment-confirmation step searched for wildcard
segment values as string literals across the entire file. That produced
false positives whenever two orthogonal getProperty calls in different
functions shared a token.

Concrete case after openviess#770: ventilation.operating.programs.* was flagged
as in-use because getVentilationPrograms iterates
['basic', 'intensive', 'reduced', ...] (none in the DB), but
getVentilationQuickmodes in the same file iterates
['comfort', 'eco', 'forcedLevelFour', 'holiday', 'silent'] (all in the
DB) — for the unrelated ventilation.quickmodes.* path. The file-wide
literal search joined them, marking the deprecated programs features as
in-code-use even though no code actually queries them.

Switch find_code_usage to extract each function body via ast and scope
the segment lookup to the same function that contains the getProperty
call. Top-level/class-body code is scanned as a single residual scope so
nothing is missed.

All 729 tests stay green; the script now exits 0 against current master
(5 spurious in-code warnings removed).
@CFenner CFenner changed the title fix(deprecations): scope literal lookup to function bodies chore(deprecations): scope literal lookup to function bodies Jun 18, 2026
@CFenner CFenner merged commit 50889f7 into openviess:master Jun 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants