Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not add the same interface multiple times to the MRO. #41

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines +252 to +259
Copy link
Contributor

@DMRobertson DMRobertson Sep 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things might have changed a bit since this PR, but I'm a bit confused by how this works.

_promote seems to be List[Instance] (on +258); mypy describes it as List[mypy.types.Types]. But on +256 we compare it to a standalone Instance, not enclosed in a list. So isn't the equality always going to be False?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_promote seems to be List[Instance] (on +258); mypy describes it as List[mypy.types.Types].

Ahh, sorry, I'm commenting on too-old a change. It looks like this changed in #75, see https://github.com/Shoobx/mypy-zope/blame/d3896c754a961fd36797df2bacb710e3b4ec69f8/src/mypy_zope/plugin.py#L685-L701

However I still think that with that change the comparison always returns False?


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