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

Class not found in source with @type_check_only #22

Closed
ilai-deutel opened this issue Oct 11, 2019 · 3 comments
Closed

Class not found in source with @type_check_only #22

ilai-deutel opened this issue Oct 11, 2019 · 3 comments

Comments

@ilai-deutel
Copy link

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')
@gaborbernat
Copy link
Collaborator

I think this makes sense, @ambv can confirm for sure. Can you create a PR with the proposed solution?

@ilai-deutel
Copy link
Author

I am working on a PR!

@gaborbernat
Copy link
Collaborator

This project is being retired and archived, so we'll no longer address this.

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

No branches or pull requests

2 participants