pyright
pyright copied to clipboard
TypeVar not assignable to itself in steam.py
Describe the bug I think I've managed to get myself down to the last few type bugs in my library and the last one that's confusing me is a TypeVar that's not assignable to itself when joining types to the return types.
but it is joinable when I use cast even though it should be for the same TypeVar. Unfortunately I can't figure out a minimal repro for it (sorry to keep sending these things I can't find minimal repros for).
Code
-
git clone https://github.com/Gobot1234/steam.py
-
poetry install
- open steam/chat.py scroll to a function involving MemberT
VS Code extension or command-line pyright 1.1.328
This is because you have a snarl of circular dependencies in your code.
- The type
MemberT
has a bound ofMember
. -
Member
is parameterized byGroupT
. -
GroupT
has a bound ofGroup | None
. -
Group
usesGroupChannel
as a type argument. -
GroupChannel
derives fromChat
. -
Chat
derives fromChannel
which is parameterized withChatMessageT
. -
ChatMessageT
has a bound ofGroupMessage | ClanMessage
. -
GroupMessage
derives fromChatMessage
. -
ChatMessage
is parameterized byMemberT
. And we're in a cycle.
Pyright already handles many forms of circular dependencies, but it doesn't handle this one. I'll look for ways to extend the logic to handle this.
I noticed that you're importing a bunch of symbols under a TYPE_CHECKING
conditional check. I'm guessing you did this to try to avoid runtime import circularities. That's just masking the fact that your code is not well layered. I recommend looking for ways to refactor your code so you can eliminate these TYPE_CHECKING
conditions and eliminate circular dependencies. Consider enabling the reportImportCycles
check and eliminating the errors it reports.
I'll see if I can get rid of them going forwards but I feel like there's not much I can do bar put everything in one massive file
I'm going to close this as "won't fix". Try to eliminate the circular dependencies within your code.