Skip to content

Add Useless-Overload-Body rule#3853

Open
pratved64 wants to merge 3 commits into
facebook:mainfrom
pratved64:feat/useless-overload-body
Open

Add Useless-Overload-Body rule#3853
pratved64 wants to merge 3 commits into
facebook:mainfrom
pratved64:feat/useless-overload-body

Conversation

@pratved64

Copy link
Copy Markdown

Summary

Added a useless-overload-body rule to execute when an overloaded function contains executable body logic. Since, overload bodies are never executed at runtime, executable logic becomes dead code and only placeholder bodies are useful (pass, ..., docstring-only, raise NotImplementedError, return NotImplemented).

Default severity is warn since the dead code will not cause any runtime errors. The valid exemptions to this rule are:

  • Ellipsis (...)
  • pass
  • docstrings
  • raise NotImplementedError
  • return NotImplemented

Fixes #3767

Test Plan

I added a regression test covering executable logic, placeholders and edge cases. Additionally, 2 existing tests were updated to expect this new rule (test_implementation_with_overload, test_overload_with_docstring2). To test changes locally, I ran:

  • cargo test overload: 212 passed
  • The entire test.py suite: 5539 passed

Please note: Initial exploration of the codebase was assisted by a local AI agent

@yangdanny97 yangdanny97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@NathanTempest do you mind merging this one

@NathanTempest

Copy link
Copy Markdown
Contributor

Just resolved the conflicts, LGTM and importing it now.

@NathanTempest

Copy link
Copy Markdown
Contributor

Thank you for working on this @pratved64. The merge conflicts that I resolved are not being applied properly and are causing some internal import errors.

Can you rebase this diff, make sure that the any documentation related to the error kinds are in alphabetical order, resolve the merge conflicts and push the changes so I can try to import again ? Thanks in advance and welcome to the Pyrefly team. We are looking forward to working with you on your future contributions.

@pratved64 pratved64 force-pushed the feat/useless-overload-body branch from 1f3d875 to 4e97202 Compare June 18, 2026 07:26
@github-actions github-actions Bot added size/l and removed size/l labels Jun 18, 2026
@pratved64

Copy link
Copy Markdown
Author

I've rebased with the main branch, resolved merge conflicts and ensured that the errors are in alphabetical order in both the definitions and documentation. Let me know if anything else is needed!

@NathanTempest NathanTempest left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for addressing my follow-ups

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

new rule - useless overload body

3 participants