retype
retype copied to clipboard
Class not found in source with @type_check_only
Hello,
I think that classes decorated with @type_check_only
should be allowed even if they are not present in the source file (since they are not available at runtime). Using them currently results in a Class not found in source
error:
foo.pyi
:
from typing import type_check_only
from typing_extensions import Protocol
@type_check_only
class A(Protocol):
def __call__(self, u: str) -> int: ...
def f(a: A) -> int: ...
foo.py
:
def f(a):
return a(u='abc')
retype
outputs error: /path/to/foo.py: Class 'A' not found in source.
I was expecting an output similar to this:
from typing import TYPE_CHECKING
from typing_extensions import Protocol
if TYPE_CHECKING:
class A(Protocol):
def __call__(self, u: str) -> int: ...
def f(a: 'A') -> int:
return a(u='abc')
I think this makes sense, @ambv can confirm for sure. Can you create a PR with the proposed solution?
I am working on a PR!
This project is being retired and archived, so we'll no longer address this.