(🐞) No error when assigning an non-concrete type object to a `Callable` variable matching the constructor (`Protocol`, `abstract`)
Open
@sobolevn is already working on this.
Since Jul 21, 2022.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from typing import Protocol, Callable
from abc import ABC, abstractmethod
class A(ABC):
@abstractmethod
def f(self) -> None: ...
class P(Protocol):
a: int
ta1 = A
reveal_type(ta1)
reveal_type(ta1()) # error
ta2: type[A] = A # error
reveal_type(ta2)
reveal_type(ta2())
ta3: Callable[[], A] = A # no error
reveal_type(ta3)
reveal_type(ta3())
tp1 = P
reveal_type(tp1)
reveal_type(tp1()) # error
tp2: type[P] = P # error
reveal_type(tp2)
reveal_type(tp2())
tp3: Callable[[], P] = P # no error
reveal_type(tp3)
reveal_type(tp3())
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.