Skip to content

Commit

Permalink
Merge pull request #41 from clokep/proto-fix
Browse files Browse the repository at this point in the history
Do not add the same interface multiple times to the MRO.
  • Loading branch information
kedder committed Mar 23, 2021
2 parents 1b6ec81 + 9ff4041 commit cdffd15
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/mypy_zope/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,14 @@ def apply_interface(
f"{iface_type.fullname}: {class_info.fullname}"
)

# Make sure implementation is treates subtype of an interface. Pretend
# there is a decorator for the class that will create a "type promotion"
faketi = TypeInfo(SymbolTable(), iface_type.defn, iface_type.module_name)
faketi._promote = Instance(iface_type, [])
class_info.mro.append(faketi)
# Make sure implementation is treated as a subtype of an interface. Pretend
# there is a decorator for the class that will create a "type promotion",
# but ensure this only gets applied a single time per interface.
promote = Instance(iface_type, [])
if not any(ti._promote == promote for ti in class_info.mro):
faketi = TypeInfo(SymbolTable(), iface_type.defn, iface_type.module_name)
faketi._promote = promote
class_info.mro.append(faketi)

def analyze(classdef_ctx: ClassDefContext) -> None:
api = classdef_ctx.api
Expand Down

0 comments on commit cdffd15

Please sign in to comment.