Skip to content

Fix false positive for @override function parameters - #420

Open
C1-BA-B1-F3 wants to merge 1 commit into
jendrikseipp:mainfrom
C1-BA-B1-F3:fix/override-false-positive
Open

Fix false positive for @override function parameters#420
C1-BA-B1-F3 wants to merge 1 commit into
jendrikseipp:mainfrom
C1-BA-B1-F3:fix/override-false-positive

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Description

Fixes #410

When a method uses the decorator (from or ), its parameters are incorrectly flagged as unused. This PR fixes the false positive by skipping argument definitions for decorated methods.

Changes

  • Added static method to detect , , and decorators
  • Modified to save/restore for function definitions, ensuring inner functions correctly reset the override state
  • Modified to skip defining function arguments when inside an function

Test Cases

Added 6 test cases covering:

  • from
  • from
  • Async functions with
  • Nested functions (inner function args are still checked)
  • and with
  • Non-override methods still flag unused args

All 291 existing tests pass with no regressions.

When a method uses the @OverRide decorator (from typing or typing_extensions),
its parameters should not be flagged as unused since the method signature must
match the parent class.

Changes:
- Add _has_override_decorator() to detect @OverRide, @typing.override, and @typing_extensions.override
- Track override state in visit() by saving/restoring _override_depth for function definitions
- Skip defining function arguments in visit_arg() when inside an @OverRide function
- Inner functions correctly reset the override state (their args are still checked)

Fixes jendrikseipp#410
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.64%. Comparing base (81fb2ac) to head (4da91a8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #420      +/-   ##
==========================================
+ Coverage   93.46%   93.64%   +0.18%     
==========================================
  Files           9        9              
  Lines         597      614      +17     
==========================================
+ Hits          558      575      +17     
  Misses         39       39              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

False positive: @override function parameters

1 participant