Skip to content

fix: skip missing-super-call for abstract or protocol method overrides - #5474

Open
Aayushyaash wants to merge 2 commits into
meta:mainfrom
Aayushyaash:fix-missing-super-call-abstract-child
Open

Aayushyaash wants to merge 2 commits into
meta:mainfrom
Aayushyaash:fix-missing-super-call-abstract-child

Conversation

@Aayushyaash

Copy link
Copy Markdown
Contributor

Summary

In an executable .py file, when an abstract class or sub-protocol overrides a constructor-like method (__init__, __new__, or __init_subclass__) to declare or refine a signature with a placeholder body (..., pass, or raise NotImplementedError), Pyrefly reported a false-positive missing-super-call error.

While #5180 skipped .pyi stubs and if TYPE_CHECKING: blocks, overriding methods in runtime .py files were still required to call super(), even when the overriding method itself was an abstract or protocol declaration without a runtime implementation.

This PR updates check_missing_super_call_for_field() to skip the check when the overriding method is abstract or belongs to a Protocol and its body kind is BodyKind::Ellipsis, BodyKind::Trivial, or BodyKind::RaiseNotImplementedError.

Fixes #5431

  • I am a human, and I fully understand the code I am submitting.

Test Plan

Added regression tests in pyrefly/lib/test/class_overrides.rs covering:

  • An abstract child class overriding __init__ with ....
  • An abstract child class overriding __init__ with pass.
  • An abstract child class overriding __init__ with raise NotImplementedError.
  • A sub-protocol overriding a parent protocol's __init__ with ....

Validation:

cargo test -p pyrefly --lib test_missing_super_call
cargo test -p pyrefly --lib test::class_overrides::
python3 test.py --lint --no-test --no-conformance --no-jsonschema --no-extension

@meta-codesync

meta-codesync Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D128855918. (Because this pull request was imported automatically, there will not be any future comments.)

@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. ✅

This branch has not been deployed

No deployments
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.

False positive missing-super-call on abstract or protocol method overrides with placeholder bodies in .py files

1 participant