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
Some socket constants are not enums #65605
Comments
Many constants in the socket module, are not int enums. Examples are socket.CAN_BCM, socket.BTPROTO_RFCOMM, etc. For example when creating a bluetooth socket, you may get the following repr(): >>> socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
<socket.socket fd=3, family=AddressFamily.AF_BLUETOOTH, type=SocketType.SOCK_STREAM, proto=3, laddr=('00:00:00:00:00:00', 0), raddr=('00:00:00:00:00:00', 0)> (notice the integer "proto") |
Enum are for, well, enumerated values, so for values within a finite |
This is why we should have had named constants and not Enums :) But no, nothing in the python Enum implementation restricts it to a value *range*. It is really a collection of named constants. |
I didn't say in the implementation, I said in spirit. Also, the problem is that many such constant can have identical values class Const(IntEnum):
AF_INET = 1
SO_REUSEADDR = 1
print(Const.AF_INET == Const.SO_REUSEADDR)
cf@neobox:~/python/hg/default$ ./python /tmp/test.py
True Really? |
Hmm, I was thinking mostly about protocol numbers. All the BTPROTO_* constants should be part of a given enum (BlueToothProtocol?), the CAN_* constants part of another one. |
To put it slightly differently: Now, for many constants defined in system header files, it's not so I'm not saying it's a bad idea: it actually probably makes sense for |
Ah, I missed the fact that the "family" and "type" properties are re-computed on the fly; I thought the enum values where stored on the socket object. Then it makes it harder to do the same for "proto", since there are family-specific namespaces with colliding values, indeed. >>> socket.IPPROTO_ICMP
1
>>> socket.BTPROTO_HCI
1 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: