Skip to content

fix: skip missing-super-call checks in TYPE_CHECKING blocks - #5180

Open
Aayushyaash wants to merge 2 commits into
facebook:mainfrom
Aayushyaash:super-call-type-checking
Open

Aayushyaash wants to merge 2 commits into
facebook:mainfrom
Aayushyaash:super-call-type-checking

Conversation

@Aayushyaash

Copy link
Copy Markdown
Contributor

Summary

Methods defined inside if TYPE_CHECKING: blocks are type-checking declarations rather than runtime implementations. Requiring an explicit super() call in these methods can result in false-positive missing-super-call errors.

Previously, check_missing_super_call_for_field() skipped this check for .pyi interface stub files but did not account for methods inside TYPE_CHECKING blocks.

This PR updates the check to skip methods whose toplevel_func_metadata() has flags.is_in_type_checking_block set.

Fixes #5136

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

Test Plan

Added a regression test in pyrefly/lib/test/class_overrides.rs for a method inside a TYPE_CHECKING block that should not report a missing-super-call error.

Validation:

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

@meta-codesync

meta-codesync Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@Aayushyaash
Aayushyaash force-pushed the super-call-type-checking branch from f34a2a8 to 5e3acd7 Compare October 19, 2026 22:56
@github-actions github-actions Bot added size/xs and removed size/xs labels Oct 19, 2026
@github-actions

Copy link
Copy Markdown

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

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

Projects with changes (7):
  pip: +0 -1
  steam.py: +1 -0
  bokeh: +0 -33
  urllib3: +0 -1
  mongo-python-driver: +0 -1
  PyWinCtl: +0 -2
  discord.py: +0 -1
============================================================

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

pip (https://github.com/pypa/pip)
- ERROR src/pip/_vendor/urllib3/_base_connection.py:142:13-21: Method `BaseHTTPSConnection.__init__` does not call the method of the same name in a parent class [missing-super-call]

steam.py (https://github.com/Gobot1234/steam.py)
+ ERROR steam/reaction.py:170:24-38: Unused `# type: ignore` comment [unused-type-ignore]

bokeh (https://github.com/bokeh/bokeh)
- ERROR src/bokeh/models/annotations/geometry.py:87:13-21: Method `AreaVisuals.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/annotations/geometry.py:119:13-21: Method `BoxInteractionHandles.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/callbacks.py:105:13-21: Method `CustomJS.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/expressions.py:246:13-21: Method `XComponent.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/expressions.py:253:13-21: Method `YComponent.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/filters.py:84:13-21: Method `InversionFilter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/filters.py:102:13-21: Method `IntersectionFilter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/filters.py:108:13-21: Method `UnionFilter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/filters.py:114:13-21: Method `DifferenceFilter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/filters.py:120:13-21: Method `SymmetricDifferenceFilter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/formatters.py:735:13-21: Method `DatetimeTickFormatter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/formatters.py:881:13-21: Method `TimedeltaTickFormatter.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/graphs.py:117:13-21: Method `NodeCoordinates.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/graphs.py:127:13-21: Method `EdgeCoordinates.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/graphs.py:134:13-21: Method `EdgePointCoordinates.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/layouts.py:524:13-21: Method `TabPanel.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/nodes.py:165:13-21: Method `Node.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tickers.py:201:13-21: Method `AdaptiveTicker.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tickers.py:261:13-21: Method `DaysTicker.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tickers.py:275:13-21: Method `MonthsTicker.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:423:13-21: Method `PanTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:438:13-21: Method `ClickPanTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:564:13-21: Method `WheelPanTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:618:13-21: Method `WheelZoomTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:856:13-21: Method `TapTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:952:13-21: Method `CrosshairTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:1056:13-21: Method `BoxZoomTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:1126:13-21: Method `ZoomInTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:1141:13-21: Method `ZoomOutTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:1168:13-21: Method `BoxSelectTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/tools.py:1416:13-21: Method `HoverTool.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/widgets/tables.py:575:13-21: Method `TableColumn.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/bokeh/models/widgets/tables.py:640:13-21: Method `DataTable.__init__` does not call the method of the same name in a parent class [missing-super-call]

urllib3 (https://github.com/urllib3/urllib3)
- ERROR src/urllib3/_base_connection.py:142:13-21: Method `BaseHTTPSConnection.__init__` does not call the method of the same name in a parent class [missing-super-call]

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- ERROR bson/codec_options.py:257:13-20: Method `CodecOptions.__new__` does not call the method of the same name in a parent class [missing-super-call]

PyWinCtl (https://github.com/Kalmat/PyWinCtl)
- ERROR src/pywinctl/_pywinctl_win.py:348:17-25: Method `TITLEBARINFO.__init__` does not call the method of the same name in a parent class [missing-super-call]
- ERROR src/pywinctl/_pywinctl_win.py:427:13-21: Method `tagWINDOWINFO.__init__` does not call the method of the same name in a parent class [missing-super-call]

discord.py (https://github.com/Rapptz/discord.py)
- ERROR discord/ext/commands/bot.py:1541:13-21: Method `AutoShardedBot.__init__` does not call the method of the same name in a parent class [missing-super-call]

@Aayushyaash

Copy link
Copy Markdown
Contributor Author

While investigating this, I noticed that missing-super-call also produces false positives in two related cases in check_missing_super_call_for_field:

  1. Parent method has no runtime implementation (@abstractmethod / Protocol): check_missing_super_call_for_field only skips object when checking parent classes, whereas get_super_attribute checks super_method_needs_impl_reason and rejects super() calls to abstract or Protocol methods without implementations (SuperMethodNeedsImplementation, updated in Error on super() calls to abstract methods that only raise NotImplementedError #5216). As a result, the subclass cannot satisfy both checks: omitting super().__init__() triggers missing-super-call, while adding it triggers missing-attribute / abstract-method-call.

  2. Child method has no runtime implementation (@abstractmethod / Protocol): check_missing_super_call_for_field skips .pyi interface files and if TYPE_CHECKING: blocks, but an overriding @abstractmethod or Protocol method with a placeholder body (...) in a .py file is still required to call super(), even though it has no runtime implementation.

I’ve left these cases out of this PR to keep the change focused on #5136 (if TYPE_CHECKING:) and avoid merge conflicts in check_missing_super_call_for_field. I plan to open a follow-up issue and PR for them once this PR lands.

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.

missing-super-call - false positive in if TYPE_CHECKING block

2 participants