Skip to content
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

Add missing ETH_P_ALL identifier to socket #11876

Merged
merged 1 commit into from
May 10, 2024
Merged

Conversation

bytemarx
Copy link
Contributor

@bytemarx bytemarx commented May 8, 2024

It seems #10247/#11219 missed a couple identifiers in the socket stub (the _socket stub seems good, though). This PR adds socket.ETH_P_ALL (https://docs.python.org/3/library/socket.html#socket.ETH_P_ALL).

There's also AF_DIVERT and PF_DIVERT missing from the socket stub, as well, but I've omitted those from this PR for a couple reasons. These are only available on FreeBSD systems, which was correctly noted in the comment above their type annotations in _socket, but the condition to check for this availability is (or at least seems to be) logically incorrect:

if sys.version_info >= (3, 12) and sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":
    # Availability: FreeBSD >= 14.0
    AF_DIVERT: int
    PF_DIVERT: int

The sys.platform documentation shows the correct (or at least a more correct) conditional statement:

if sys.platform.startswith('freebsd'):
    # Availability: FreeBSD >= 14.0
    AF_DIVERT: int
    PF_DIVERT: int

And similarly for the socket stub:

if sys.platform.startswith('freebsd'):
    from _socket import (
        AF_DIVERT as AF_DIVERT,
        PF_DIVERT as PF_DIVERT,
    )

All this essentially to ask if the current check (sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin") is just how typeshed has decided to check for FreeBSD systems, or if it would be preferable to use the sys.platform.startswith('freebsd') check. And, if this would be preferred, should parsing and checking the version be included, as well?

I also don't have a FreeBSD system to personally test with, so wasn't sure if I should let someone on an actual FreeBSD 14 system handle this (although, I suppose it wouldn't be too much trouble to spin up a FreeBSD VM if necessary).

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented May 8, 2024

All this essentially to ask if the current check (sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin") is just how typeshed has decided to check for FreeBSD systems, or if it would be preferable to use the sys.platform.startswith('freebsd') check. And, if this would be preferred, should parsing and checking the version be included, as well?

Unfortunately, only simple platform checks using == and != are allowed at the moment, which is why we use the awkward workaround.

@srittau
Copy link
Collaborator

srittau commented May 8, 2024

For reference, https://typing.readthedocs.io/en/latest/source/stubs.html#version-and-platform-checks documents the currently supported formats. I've also opened python/typing#1732, suggesting to add startswith() checks, but for now the chained together != checks are the best we've got.

@bytemarx
Copy link
Contributor Author

bytemarx commented May 9, 2024

Understood. For now, I'll just add in those missing FreeBSD identifiers using the current platform check syntax with a comment identifying them as FreeBSD constants.

@@ -525,6 +532,9 @@ class AddressFamily(IntEnum):
AF_BLUETOOTH = 32
if sys.platform == "win32" and sys.version_info >= (3, 12):
AF_HYPERV = 34
if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin" and sys.version_info >= (3, 12):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If preferred, can also do this as

if sys.version_info >= (3, 12):
    if sys.platform == "win32":
        AF_HYPERV = 34
    if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin":
        # FreeBSD >= 14.0
        AF_DIVERT = 44

Copy link
Contributor

github-actions bot commented May 9, 2024

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

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks!

@srittau srittau merged commit a10e413 into python:main May 10, 2024
54 checks passed
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