Skip to content

Commit

Permalink
Make sure mypy treats implementations as subtype of their interface
Browse files Browse the repository at this point in the history
Fixes #91
  • Loading branch information
kedder committed Mar 13, 2023
1 parent 478fcce commit 96518e2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mypy_zope/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Type as PyType
from typing import cast

from mypy.typestate import type_state
from mypy.types import (
Type,
Instance,
Expand Down Expand Up @@ -722,6 +723,13 @@ def _apply_interface(self, impl: TypeInfo, iface: TypeInfo) -> None:
if promote not in impl._promote:
impl._promote.append(promote)

# Remember implementation as a subtype of an interface. HACK: we are
# writing to a global variable here, so potentially this might be a
# memory leak. Needs testing with a large codebase.
asmpt = (Instance(impl, []), promote)
type_state.get_assumptions(False).append(asmpt)
type_state.get_assumptions(True).append(asmpt)


def plugin(version: str) -> PyType[Plugin]:
return ZopeInterfacePlugin

0 comments on commit 96518e2

Please sign in to comment.