On Fri, 24 Jul 2020 at 00:57, Guido van Rossum <guido@python.org> wrote:
You forgot to show us your definition for LazyType. And, honestly, a lot more context explaining what you're trying to do and why.

But passing ".type_a" to any generic type isn't going to work in mypy, it's always going to be treated as a syntax error.
I just released that even using Annotated in the way I want is not going to work unfortunately, as mypy complains about "type_b"  not being defined when doing this:

Annotated["TypeB", "type_b"]

which is unfortunate
 
Maybe you can play some game with `if TYPE_CHECKING` inside strawberry so that mypy thinks that LazyType is an alias for Annotated, but at runtime it's something else?

I also tried to work with `if TYPE_CHECKING`, but that didn't work as I was getting these errors when reassigning the type with `LazyType = Annotated`

tests/test_cyclic/type_a.py:8: error: Cannot assign to a type
tests/test_cyclic/type_a.py:8: error: Incompatible types in assignment (expression has type "_SpecialForm", variable has type "Type[LazyType]")
tests/test_cyclic/type_a.py:19: error: "LazyType" expects no type arguments, but 2 given
tests/test_cyclic/type_a.py:19: error: Name 'type_b' is not defined

The only thing that seems to get closer to 0 errors is by doing this for LazyType:

TypeName = TypeVar("TypeName")
Module = TypeVar("Module")


@dataclass(frozen=True)
class LazyType(Generic[TypeName, Module]):
    type_name: str
    module: str
    package: Optional[str]

    def __class_getitem__(cls, params):
        type_name, module = params

        package = None

        if module.startswith("."):
            current_frame = inspect.currentframe()
            package = current_frame.f_back.f_globals["__package__"]

        return cls(type_name, module, package)

So adding two generics params to it, even if they are not used :)

But I still get this: 

tests/test_cyclic/type_a.py:13: error: Name 'type_b' is not defined

And I wonder if I can use a plugin to tell mypy to ignore this error, I might try to experiment with this later!


--
Patrick Arminio