Skip to content

fix invalid-inheritance on a call-expression base class even when the callable returns type[...] (mixin factory) #3931 - #5470

Closed
asukaminato0721 wants to merge 2 commits into
meta:mainfrom
asukaminato0721:3931
Closed

asukaminato0721 wants to merge 2 commits into
meta:mainfrom
asukaminato0721:3931

Conversation

@asukaminato0721

Copy link
Copy Markdown
Collaborator

Summary

Fixes #XXXX

Fixes #3931

Call-expression bases like class C(factory("x")) are now represented as evaluable base-class expressions instead of being rejected syntactically.

The solver now untypes the call result in base-class context, so type[Mixin] becomes a valid Mixin base, and Any-returning factories are tolerated.

Invalid functional namedtuple/NamedTuple bases keep their existing diagnostics.

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

Test Plan

add test

@github-actions

This comment has been minimized.

@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 D128830224. (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: +35 new errors, -105 fixed errors
By preset: +8/-16 (default), +10/-16 (strict)

Projects with changes (5):
  prefect: +0 -1
  comtypes: +2 -2
  steam.py: +2 -1
  zope.interface: +28 -38
  nox: +3 -63
============================================================

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

prefect (https://github.com/PrefectHQ/prefect)
- ERROR src/prefect/__init__.py:37:23-77: Invalid expression form for base class: `TypedDict("_FullRevisionId", {"full-revisionid": str})` [invalid-inheritance]

comtypes (https://github.com/enthought/comtypes)
- ERROR comtypes/test/test_compatibility_tlbparser_VT_I1_assignment.py:149:34-71: Invalid expression form for base class: `create_legacy_automatic_int8_output()` [invalid-inheritance]
+ ERROR comtypes/test/test_compatibility_tlbparser_VT_I1_assignment.py:149:11-33: Class `IByteCompatibilityTest` has unimplemented abstract members: `EchoUint8`, `EchoLpStr`, `ReadCharPointer`, `GetCharacterBytes` [implicit-abstract-class]
- ERROR comtypes/test/test_compatibility_tlbparser_VT_I1_assignment.py:154:18-55: The type of attribute `_IByteCompatibilityTest__com_EchoInt8` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR comtypes/test/test_compatibility_tlbparser_VT_I1_assignment.py:154:13-55: Object of class `IByteCompatibilityTest` has no attribute `_IByteCompatibilityTest__com_EchoInt8` [missing-attribute]

steam.py (https://github.com/Gobot1234/steam.py)
- ERROR steam/types/app.py:171:24-70: Invalid expression form for base class: `TypedDict("", {"class": list[dict[str, Any]]})` [invalid-inheritance]
+ ERROR steam/types/app.py:171:24-33: Expected a callable, got `type[TypedDict]` [not-callable]
+ ERROR steam/types/app.py:171:63-66: Explicit `Any` is not allowed [explicit-any]

zope.interface (https://github.com/zopefoundation/zope.interface)
- ERROR src/zope/interface/tests/test_adapter.py:977:23-45: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
- ERROR src/zope/interface/tests/test_adapter.py:1364:23-45: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
- ERROR src/zope/interface/tests/test_adapter.py:1588:23-45: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
+ ERROR src/zope/interface/tests/test_adapter.py:1588:15-22: Field `changed` has inconsistent types inherited from multiple base classes [inconsistent-inheritance]
- ERROR src/zope/interface/tests/test_adapter.py:1602:23-45: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
+ ERROR src/zope/interface/tests/test_adapter.py:1602:15-22: Field `changed` has inconsistent types inherited from multiple base classes [inconsistent-inheritance]
+ ERROR src/zope/interface/tests/test_adapter.py:1621:9-28: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_adapter.py:1621:13-22: The type of attribute `_required` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_adapter.py:1621:13-22: The type of attribute `_required` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_adapter.py:1622:9-28: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_adapter.py:1622:13-22: The type of attribute `_required` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_adapter.py:1622:13-22: The type of attribute `_required` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_adapter.py:1624:30-43: The type of this argument is unknown [unknown-argument-type]
+ ERROR src/zope/interface/tests/test_adapter.py:1624:30-43: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_adapter.py:1624:34-43: The type of attribute `_required` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_adapter.py:1624:34-43: The type of attribute `_required` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_declarations.py:1745:23-45: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
- ERROR src/zope/interface/tests/test_interface.py:452:18-40: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
+ ERROR src/zope/interface/tests/test_interface.py:452:18-40: Invalid base class: `Never` [invalid-inheritance]
+ ERROR src/zope/interface/tests/test_interface.py:452:18-40: Expected a type form, got instance of `Never` [not-a-type]
- ERROR src/zope/interface/tests/test_interface.py:1248:23-45: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
- ERROR src/zope/interface/tests/test_interface.py:1307:32-54: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
- ERROR src/zope/interface/tests/test_interface.py:1331:32-54: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
- ERROR src/zope/interface/tests/test_registry.py:365:40-62: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
+ ERROR src/zope/interface/tests/test_registry.py:368:17-32: Class member `CompThatChangesAfter1Reg.registerUtility` overrides parent class `Components` in an inconsistent manner [bad-override]
+ ERROR src/zope/interface/tests/test_registry.py:368:17-32: Class member `CompThatChangesAfter1Reg.registerUtility` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- ERROR src/zope/interface/tests/test_registry.py:370:25-40: The type of attribute `registerUtility` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_registry.py:370:25-40: The type of attribute `registerUtility` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:372:26-48: Attribute `_utility_registrations` is implicitly defined by assignment in method `registerUtility`, which is not a constructor [implicitly-defined-attribute]
- ERROR src/zope/interface/tests/test_registry.py:372:51-374:22: This expression's type is partially unknown; it contains an implicit `Any`. Please provide an explicit type annotation. [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_registry.py:370:41-46: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:379:30-62: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_registry.py:379:35-61: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:379:35-61: The type of this argument is unknown [unknown-argument-type]
- ERROR src/zope/interface/tests/test_registry.py:379:40-59: The type of attribute `registeredUtilities` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_registry.py:379:40-59: The type of attribute `registeredUtilities` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:385:30-62: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_registry.py:385:35-61: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:385:35-61: The type of this argument is unknown [unknown-argument-type]
- ERROR src/zope/interface/tests/test_registry.py:385:40-59: The type of attribute `registeredUtilities` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_registry.py:385:40-59: The type of attribute `registeredUtilities` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:390:40-62: Invalid expression form for base class: `self._getTargetClass()` [invalid-inheritance]
+ ERROR src/zope/interface/tests/test_registry.py:393:17-32: Class member `CompThatChangesAfter2Reg.registerUtility` overrides parent class `Components` in an inconsistent manner [bad-override]
+ ERROR src/zope/interface/tests/test_registry.py:393:17-32: Class member `CompThatChangesAfter2Reg.registerUtility` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
- ERROR src/zope/interface/tests/test_registry.py:396:26-48: Attribute `_utility_registrations` is implicitly defined by assignment in method `registerUtility`, which is not a constructor [implicitly-defined-attribute]
- ERROR src/zope/interface/tests/test_registry.py:396:51-398:22: This expression's type is partially unknown; it contains an implicit `Any`. Please provide an explicit type annotation. [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:400:25-40: The type of attribute `registerUtility` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_registry.py:400:25-40: The type of attribute `registerUtility` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_registry.py:400:41-46: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:405:30-62: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_registry.py:405:35-61: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:405:35-61: The type of this argument is unknown [unknown-argument-type]
- ERROR src/zope/interface/tests/test_registry.py:405:40-59: The type of attribute `registeredUtilities` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_registry.py:405:40-59: The type of attribute `registeredUtilities` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:411:30-62: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_registry.py:411:35-61: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:411:35-61: The type of this argument is unknown [unknown-argument-type]
- ERROR src/zope/interface/tests/test_registry.py:411:40-59: The type of attribute `registeredUtilities` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_registry.py:411:40-59: The type of attribute `registeredUtilities` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:417:30-62: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
+ ERROR src/zope/interface/tests/test_registry.py:417:35-61: The type of this argument is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:417:35-61: The type of this argument is unknown [unknown-argument-type]
- ERROR src/zope/interface/tests/test_registry.py:417:40-59: The type of attribute `registeredUtilities` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR src/zope/interface/tests/test_registry.py:417:40-59: The type of attribute `registeredUtilities` is partially unknown; it contains an implicit `Any` [partially-unknown-type]
- ERROR src/zope/interface/tests/test_registry.py:2709:9-24: Class member `UnhashableComponentsTests._getTargetClass` overrides parent class `ComponentsTests` in an inconsistent manner [bad-override]
- ERROR src/zope/interface/tests/test_registry.py:2714:13-69: Invalid expression form for base class: `super(UnhashableComponentsTests, self)._getTargetClass()` [invalid-inheritance]

nox (https://github.com/wntrblm/nox)
- ERROR nox/_cli.py:317:24-28: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/_cli.py:453:28-35: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/command.py:70:12-17: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/command.py:169:16-20: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/command.py:177:20-25: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/command.py:185:20-27: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/command.py:206:20-25: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/command.py:211:24-29: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/command.py:220:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR nox/logger.py:87:62-82: Unused `# type: ignore` comment [unused-type-ignore]
- ERROR nox/logger.py:89:17-29: The type of attribute `isEnabledFor` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/logger.py:90:18-22: The type of attribute `_log` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/logger.py:93:17-29: The type of attribute `isEnabledFor` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/logger.py:94:18-22: The type of attribute `_log` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/logger.py:97:17-29: The type of attribute `isEnabledFor` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/logger.py:98:18-22: The type of attribute `_log` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:113:16-23: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:123:20-27: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:125:20-25: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:347:20-29: The type of attribute `exception` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:521:20-24: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:797:20-27: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:806:24-28: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:982:16-20: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:986:16-23: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:990:16-21: The type of attribute `debug` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:1223:24-31: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:1255:20-25: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:1259:20-29: The type of attribute `exception` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:1346:32-46: The type of `log_function` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR nox/sessions.py:1346:39-46: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:1348:32-82: The type of `log_function` is unknown; it is inferred as an implicit `Any` [unknown-variable-type]
- ERROR nox/sessions.py:1348:39-44: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:1348:78-82: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/sessions.py:1349:9-30: Result of call expression is of type `Unknown | None` and is not used; assign to `_` if this is intentional [unused-call-result]
- ERROR nox/tasks.py:141:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:144:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:149:16-25: The type of attribute `exception` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:207:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR nox/tasks.py:222:30-41: The type of this argument is an explicit `Any` [explicit-any-use]
- ERROR nox/tasks.py:221:24-29: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:222:24-29: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:234:20-25: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:241:20-25: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:249:20-25: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:260:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
+ ERROR nox/tasks.py:276:22-33: The type of this argument is an explicit `Any` [explicit-any-use]
- ERROR nox/tasks.py:275:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:276:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:350:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:387:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:392:16-21: The type of attribute `error` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:418:16-23: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/tasks.py:439:20-27: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:185:16-21: The type of attribute `debug` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:309:16-20: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:325:12-16: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:375:16-23: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:392:16-23: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:405:16-23: The type of attribute `warning` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:465:16-21: The type of attribute `debug` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:481:16-21: The type of attribute `debug` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:677:20-25: The type of attribute `debug` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:684:16-20: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:1060:20-25: The type of attribute `debug` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]
- ERROR nox/virtualenv.py:1096:16-20: The type of attribute `info` is unknown; it is inferred as an implicit `Any` [unknown-attribute-access]

@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 3dce675.

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.

invalid-inheritance on a call-expression base class even when the callable returns type[...] (mixin factory)

2 participants