Skip to content

fix: skip missing-super-call when parent method lacks runtime implementation - #5469

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

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

Conversation

@Aayushyaash

Copy link
Copy Markdown
Contributor

Summary

When a subclass overrides a constructor-like method (__init__, __new__, or __init_subclass__) whose parent method has no runtime implementation, such as an @abstractmethod or a Protocol method with an empty or placeholder body (..., pass, or raise NotImplementedError), Pyrefly can report a false-positive missing-super-call error.

Previously, omitting super() triggered missing-super-call, while explicitly calling super() could trigger missing-attribute or abstract-method-call. This occurred because get_super_attribute() rejects access to parent methods without runtime implementations through super_method_needs_impl_reason() (updated in #5216 to return NoAccessReason::SuperMethodNeedsImplementation).

This PR updates check_missing_super_call_for_field() to check self.super_method_needs_impl_reason(&want_field) and skip the super() requirement when the resolved parent method has no runtime implementation. In multiple inheritance scenarios, the check continues across subsequent bases to ensure that concrete parent constructors are still called.

Fixes #5430

  • 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:

  • Overriding an abstract parent method with a ... body without calling super().
  • Overriding an abstract parent method that raises NotImplementedError without calling super().
  • Overriding a Protocol parent method without calling super().
  • Multiple inheritance with both abstract and concrete parents, verifying that omitting super() for the concrete parent is still reported.

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 D128830191. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

============================================================
SUMMARY
============================================================
Total: +0 new errors, -28 fixed errors
By preset: +0/-0 (default), +0/-0 (strict)

Projects with changes (10):
  pip: +0 -3
  psycopg: +0 -2
  mkdocs: +0 -3
  rotki: +0 -5
  pytest: +0 -3
  jax: +0 -2
  scikit-learn: +0 -4
  hydra-zen: +0 -1
  dedupe: +0 -2
  xarray: +0 -3
============================================================

FULL DIFF DETAILS
------------------------------------------------------------

pip (https://github.com/pypa/pip)
- ERROR src/pip/_internal/build_env/noop.py:17:9-17: Method `NoOpBuildEnvironment.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/pip/_internal/build_env/venv.py:33:9-17: Method `VenvBuildEnvironment.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/pip/_internal/build_env/virtual.py:37:9-17: Method `VirtualBuildEnvironment.__init__` does not call the method of the same name in a parent class [missing-super-call]

psycopg (https://github.com/psycopg/psycopg)
- ERROR psycopg/psycopg/adapt.py:38:9-17: Method `Dumper.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR psycopg/psycopg/adapt.py:128:9-17: Method `Loader.__init__` does not call the method of the same name in a parent class [missing-super-call]

mkdocs (https://github.com/mkdocs/mkdocs)
- ERROR mkdocs/structure/nav.py:49:9-17: Method `Section.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR mkdocs/structure/nav.py:98:9-17: Method `Link.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR mkdocs/structure/pages.py:36:9-17: Method `Page.__init__` does not call the method of the same name in a parent class [missing-super-call]

rotki (https://github.com/rotki/rotki)
- ERROR rotkehlchen/chain/ethereum/modules/eth2/eth2.py:76:9-17: Method `Eth2.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR rotkehlchen/chain/ethereum/modules/liquity/trove.py:77:9-17: Method `Liquity.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR rotkehlchen/chain/ethereum/modules/makerdao/dsr.py:41:9-17: Method `MakerdaoDsr.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR rotkehlchen/chain/ethereum/modules/makerdao/vaults.py:136:9-17: Method `MakerdaoVaults.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR rotkehlchen/chain/ethereum/modules/pickle_finance/main.py:43:9-17: Method `PickleFinance.__init__` does not call the method of the same name in a parent class [missing-super-call]

pytest (https://github.com/pytest-dev/pytest)
- ERROR src/_pytest/capture.py:340:9-17: Method `NoCapture.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/_pytest/capture.py:363:9-17: Method `SysCaptureBase.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/_pytest/capture.py:465:9-17: Method `FDCaptureBase.__init__` does not call the method of the same name in a parent class [missing-super-call]

jax (https://github.com/google/jax)
- ERROR jax/_src/pallas/mosaic/interpret/vector_clock.py:37:7-15: Method `NpVectorClock.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR jax/_src/pallas/mosaic_gpu/interpret/shared_memory.py:430:7-15: Method `GpuClockBundle.__init__` does not call the method of the same name in a parent class [missing-super-call]

scikit-learn (https://github.com/scikit-learn/scikit-learn)
- ERROR sklearn/compose/_column_transformer.py:281:9-17: Method `ColumnTransformer.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR sklearn/ensemble/_base.py:216:9-17: Method `_BaseHeterogeneousEnsemble.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR sklearn/pipeline.py:219:9-17: Method `Pipeline.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR sklearn/pipeline.py:1711:9-17: Method `FeatureUnion.__init__` does not call the method of the same name in a parent class [missing-super-call]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- ERROR src/hydra_zen/typing/_implementations.py:147:9-17: Method `BuildsWithSig.__init__` does not call the method of the same name in a parent class [missing-super-call]

dedupe (https://github.com/dedupeio/dedupe)
- ERROR dedupe/levenshtein.py:12:9-17: Method `LevenshteinIndex.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR dedupe/tfidf.py:15:9-17: Method `TfIdfIndex.__init__` does not call the method of the same name in a parent class [missing-super-call]

xarray (https://github.com/pydata/xarray)
- ERROR xarray/indexes/nd_point_index.py:80:9-17: Method `ScipyKDTreeAdapter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR xarray/namedarray/daskmanager.py:32:9-17: Method `DaskManager.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR xarray/tests/test_parallelcompat.py:69:9-17: Method `DummyChunkManager.__init__` does not call the method of the same name in a parent class [missing-super-call]

@stroxler

Copy link
Copy Markdown
Contributor

Thanks!

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync

meta-codesync Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 6d6dd07.

@Aayushyaash
Aayushyaash deleted the fix-missing-super-call-abstract-parent branch October 31, 2026 20:52
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 when parent method is abstract or protocol method without runtime implementation

2 participants