Skip to content

Add type stub for PySocks #14623

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Add type stub for PySocks #14623

wants to merge 7 commits into from

Conversation

Chocobo1
Copy link

@Chocobo1 Chocobo1 commented Aug 22, 2025

Upstream repository: https://github.com/Anorov/PySocks
Upstream PyPI: https://pypi.org/project/PySocks/

PySocks

PySocks lets you send traffic through SOCKS proxy servers. It is a modern fork of SocksiPy with bug fixes and extra features.

This comment has been minimized.

@Chocobo1 Chocobo1 marked this pull request as ready for review August 22, 2025 09:45

This comment has been minimized.

Copy link
Contributor

@donBarbos donBarbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing! Looks good, just one nit with Any:
Seems you used Any for args and kwargs which can be defined since we know where to pass them (I've shown some cases below), otherwise I suggest using Incomplete since such types can be improved in the future

Copy link
Contributor

@donBarbos donBarbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but I didn't add my suggestions to batch before submitting review and they didn't save :)

@Chocobo1
Copy link
Author

otherwise I suggest using Incomplete since such types can be improved in the future

Seems pre-commit CI don't allow using Incomplete in this case: https://results.pre-commit.ci/run/github/31696383/1755886059.-ECsrHubTY6pAb6L87Fhjw

This comment has been minimized.

@Chocobo1
Copy link
Author

Chocobo1 commented Aug 22, 2025

otherwise I suggest using Incomplete since such types can be improved in the future

Seems pre-commit CI don't allow using Incomplete in this case: https://results.pre-commit.ci/run/github/31696383/1755886059.-ECsrHubTY6pAb6L87Fhjw

It seems to me that to properly annotate args and kwargs is a lot of work:
https://rednafi.com/python/annotate_args_and_kwargs/

If possible I would like to defer that work and submit the stubs in current state. For PySocks, args/kwargs are usually for passing variables to underlying function/socket and it isn't that critical for normal usage. I reckon only a few rare cases would actually use them.
And btw, I saw a few existing stubs that also uses kwargs: Any.

This comment has been minimized.

@donBarbos
Copy link
Contributor

Seems pre-commit CI don't allow using Incomplete in this case: https://results.pre-commit.ci/run/github/31696383/1755886059.-ECsrHubTY6pAb6L87Fhjw

Indeed, parameters are usually left unannotated in such cases because Incomplete alone doesn't make much sense.

I don’t really mind leaving stubs in current state. Then I’ll try to replace args and kwargs myself soon.

This comment has been minimized.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/contrib/socks.py:44: error: Unused "type: ignore" comment  [unused-ignore]
+ src/urllib3/contrib/socks.py:114: error: Argument "proxy_port" to "create_connection" has incompatible type "str | None"; expected "int | None"  [arg-type]
+ src/urllib3/contrib/socks.py:118: error: Argument "timeout" to "create_connection" has incompatible type "float | None"; expected "int | None"  [arg-type]
+ test/contrib/test_socks.py:12: error: Unused "type: ignore" comment  [unused-ignore]
+ test/contrib/test_socks.py:122: error: Module "socks" does not explicitly export attribute "socket"  [attr-defined]

discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "name", "description"  [misc]
+ discord/ext/commands/hybrid.py:629: error: Overlap between argument names and ** TypedDict items: "description", "name"  [misc]

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

Successfully merging this pull request may close these issues.

2 participants