-
Notifications
You must be signed in to change notification settings - Fork 180
add type stubs for static type checking support #228
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
base: develop
Are you sure you want to change the base?
Conversation
Add PEP 561 compliant type stub files to enable static type checkers (Pylance, Pyright, mypy) to resolve dynamically created enums. The sc2.data module creates enums at runtime using enum.Enum() with protobuf descriptors, which are invisible to static analysis tools.
|
Hi @BurnySc2 , Thanks for pushing that commit, your fix for the protobuf enums (using : int) is perfect. To answer your questions: Yes, the Regarding the separate Shipping the stubs directly with this library will immensely help developers by providing clear typing and IntelliSense right out of the box. The practical benefit seems to outweigh the potential for a future conflict, which we can always address later if it actually becomes a problem. |
|
Thanks for your quick feedback. Alright, I'll ship stubs with this package. Once conflicts with other packages come up (my guess is, that it is unlikely that others will put that much effort into stubs), one will have to resolve them. I'll add more stubs for the s2clientprotocol over the next couple days and then would like to ask you to review, if it works properly with your mypy setup (I guess that's what you are using). I'll also ask people from discord to review the PR then. |
|
in client.py, should color: tuple[float, float] be [float, float, float]? |
|
@an-swe I believe I did enough (probably too many) changes related to type hinting and stubs. The mpyq package could need stubs but that doesn't seem that important. Edit: from enum import Enum, IntEnum
class Test1(Enum):
A = 1
B = 2
class Test2(IntEnum):
A = 1
B = 2
print(Test1.A)
print(Test1.A.name)
print(Test1.A.value)
print(Test1.A == 1)
""" Output:
Test1.A
A
1
False
"""
print(Test2.A)
print(Test2.A.name)
print(Test2.A.value)
print(Test2.A == 1)
""" Output:
Test1.A
A
1
True
""" |
|
@BurnySc2 Huge thanks for the effort on this! The stubs look great. Regarding IntEnum: I think that's a great idea, but we probably want to do it in a fresh PR. Since changing to IntEnum affects runtime logic (comparisons against integers), I wouldn't want to risk breaking things inside this already large PR. Aside from the failing CI checks, this looks ready to me. I will try testing this stub change on my IDE later this week. |
|
Related: #168 |
|
@an-swe Hey, any progress on the review? I'd like to merge this within the next 2 weeks. Of course there are holidays now so I can understand if you are busy. |



Add PEP 561 compliant type stub files to enable static type checkers (Pylance, Pyright, mypy) to resolve dynamically created enums.
The sc2.data module creates enums at runtime using enum.Enum() with protobuf descriptors, which are invisible to static analysis tools.