Thanks to visit codestin.com
Credit goes to github.com

Skip to content

(🐞) Modules don't really conform to Protocols do they #16890

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

Closed
KotlinIsland opened this issue Feb 7, 2024 · 3 comments Β· May be fixed by #18095
Closed

(🐞) Modules don't really conform to Protocols do they #16890

KotlinIsland opened this issue Feb 7, 2024 · 3 comments Β· May be fixed by #18095
Labels
bug mypy got something wrong

Comments

@KotlinIsland
Copy link
Contributor

test.py

from typing import Protocol

import test2

class P(Protocol):
    def foo(self) -> None: ...

a: P = test2
reveal_type(type(a).foo)  # Revealed type is "def (self: test.P) -> None"

test2.py

def foo() -> None: ...
@KotlinIsland KotlinIsland added the bug mypy got something wrong label Feb 7, 2024
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 11, 2024

Modules are allowed to conform to protocols! This is a pretty useful feature, Ivan added it in late 2022, is specified in PEP 544

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2024
@KotlinIsland
Copy link
Contributor Author

Modules are allowed to conform to protocols! This is a pretty useful feature, Ivan added it in late 2022

Did you have a look at the example in the OP? Protocols are classes, modules are instances. They don't correctly conform.

@hauntsaninja
Copy link
Collaborator

I did, maybe what should be banned is doing type on Protocol instance...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants