pytype
pytype copied to clipboard
class is mistaken for a module? (invalid-annotation)
pytype version: 2022.02.17
Ran on WSL2 ubuntu
CMD: /usr/bin/python3 -m pytype.single --imports_info /tmp/tmpsak_oti3/imports/hydra.core.player.imports --module-name hydra.core.player -V 3.8 -o /tmp/tmpsak_oti3/pyi/hydra/core/player.pyi --analyze-annotated --nofail --quick /mnt/c/Users/alias/Desktop/src/hydra/hydra/core/player.py
I get this error when trying to type check player.py
File "/mnt/c/Users/alias/Desktop/src/hydra/hydra/core/player.py", line 17, in BasePlayer: Invalid type annotation '<instance of module>' for provider [invalid-annotation]
Not a type
For more details, see https://google.github.io/pytype/errors.html#invalid-annotation
Player.py
from typing import TYPE_CHECKING, Union
from .packets import State
if TYPE_CHECKING:
from .helpers.stream import Stream
from .server import Server
class BasePlayer:
__slots__ = ("name", "connection", "state", "provider")
def __init__(self, stream: "Stream", provider: Union["Server"]): # this is line 17
...
server.py
...
class Server:
...
the project structure
...
├── player.py
└── server
├── __init__.py
├── events.py
├── server.py
└── server_event_listener.py
Note im 100% sure its Server class thats being imported as python itself imports Server class if outside TYPE_CHECKING
clause
ALSO i know that union should include two types, but i just slapped a Union because ill add more types later in the project development + i tried adding another type Union[Server, int]
still same error. I also tried removing the "" still same error.
Its clearly sees Server as a module, idk but my guess is case in-senstive?
also this is the __init__.py
from .server import Server
i think the issue is from here
because .server.server.Server
is accessed by .server.Server
Also generates issues like this
/usr/bin/python3 -m pytype.single --imports_info /tmp/tmpdlc5ymkb/imports/hydra.core.server.server.imports --module-name hydra.core.server.server -V 3.8 -o /tmp/tmpdlc5ymkb/pyi/hydra/core/server/server.pyi --analyze-annotated --nofail --quick /mnt/c/Users/alias/Desktop/src/hydra/hydra/core/server/server.py
File "/mnt/c/Users/alias/Desktop/src/hydra/hydra/core/server/server.py", line 70, in start: Function ServerStartEvent.__init__ was called with the wrong arguments [wrong-arg-types]
Expected: (self, server: hydra.core.server.server.Server)
Actually passed: (self, server: Server)
For more details, see https://google.github.io/pytype/errors.html#wrong-arg-types
where this
if TYPE_CHECKING:
from .server import Server
class ServerStartEvent(Cancellable):
"""Event called when the server side starts up"""
__slots__ = ("server",)
def __init__(self, server: "Server"): ...
this line is generating the error:
# somewhere inside the Server class
start_event = ServerStartEvent(self) # the Error