chore(deprecations): scope literal lookup to function bodies#775
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Formatworkflow'svalidate deprecation databasestep 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
Why these aren't actually used
PyViCareVentilationDevice.pyhas exactly onegetPropertycall againstventilation.operating.programs.*, ingetVentilationPrograms():Zero overlap with the flagged features. But the same file has, in the orthogonal
getVentilationQuickmodes(), a separate loop that queries the unrelatedventilation.quickmodes.*path: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 thatventilation.operating.programs.comfortis referenced. Same mechanism for the other four.The fix
find_code_usage()now usesast.parseto extract eachFunctionDef/AsyncFunctionDefbody as an independent scope.feature_matches_code()searches only within the scope that contains thegetPropertycall. 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 --updatenow exits0against master (was1)ventilation.operating.programs.*getProperty call in the whole codebase (the one ingetVentilationPrograms), and none of its iteration values are in the DB