Skip to content

[socket] Use Final for constants #14503

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 5 commits into
base: main
Choose a base branch
from

Conversation

donBarbos
Copy link
Contributor

@donBarbos donBarbos commented Jul 31, 2025

PS: I added value only to those Final constants that are not bindings to libc, such as SO_VM_SOCKETS_BUFFER_MIN_SIZE, VMADDR_PORT_ANY, HV_GUID_ZERO, HV_GUID_WILDCARD, etc.

This comment has been minimized.

Copy link
Member

@brianschubert brianschubert left a comment

Choose a reason for hiding this comment

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

Looks good! Just two remarks from spot checks on the default values

@@ -743,10 +743,10 @@ class socket:
def timeout(self) -> float | None: ... # noqa: F811
if sys.platform == "win32":
def __init__(
self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | bytes | None = ...
self, family: int = ..., type: int = ..., proto: int = 0, fileno: SupportsIndex | bytes | None = None
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@donBarbos donBarbos Aug 1, 2025

Choose a reason for hiding this comment

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

in this Python implementation if fileno is not passed then family = AF_INET, type = SOCK_STREAM, proto = 0. so I'm not sure that it is possible to say for sure that these values are -1 by default

In C it is also more similar to the init value than the default value. and C implementation has docstring which shows two options with fileno and without:

"socket(family=AF_INET, type=SOCK_STREAM, proto=0) -> socket object\n\
socket(family=-1, type=-1, proto=-1, fileno=None) -> socket object\n\

I don't like to use family = -1, type = -1, proto = -1 because it doesn't reflect logic, that's why real values are written in documentation

Copy link
Contributor

github-actions bot commented Aug 1, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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