Skip to content

fix: add missing NETLINK re-exports of linux socket constants - #8555

Merged
AlexWaygood merged 4 commits into
python:masterfrom
kkirsche:fix/7077
Aug 18, 2022
Merged

AlexWaygood merged 4 commits into
python:masterfrom
kkirsche:fix/7077

Conversation

@kkirsche

@kkirsche kkirsche commented Aug 18, 2022 •

Copy link
Copy Markdown
Contributor

fix: #7077

This re-exports the following linux-only (I'm trusting the stubs, haven't verified) constants:

https://github.com/python/typeshed/blob/master/stdlib/_socket.pyi#L522-L538

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread stdlib/socket.pyi
CAN_RAW_RECV_OWN_MSGS as CAN_RAW_RECV_OWN_MSGS,
CAN_RTR_FLAG as CAN_RTR_FLAG,
CAN_SFF_MASK as CAN_SFF_MASK,
NETLINK_ARPD as NETLINK_ARPD,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add NETLINK_CRYPTO?

For what it's worth these are the ones that exist on my Linux system:

In [30]: sorted(k for k in socket.__dict__ if k.startswith("NETLINK_"))
Out[30]: 
['NETLINK_CRYPTO',
 'NETLINK_DNRTMSG',
 'NETLINK_FIREWALL',
 'NETLINK_IP6_FW',
 'NETLINK_NFLOG',
 'NETLINK_ROUTE',
 'NETLINK_USERSOCK',
 'NETLINK_XFRM']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/python/typeshed/runs/7899804531?check_suite_focus=true

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/load_pytd.py", line 262, in resolve_external_types
    mod_ast = mod_ast.Visit(visitors.LookupExternalTypes(
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/parse/node.py", line 99, in Visit
    return _Visit(self, visitor, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/parse/node.py", line 117, in _Visit
    return _VisitNode(node, visitor, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/parse/node.py", line 209, in _VisitNode
    new_child = _VisitNode(child, visitor, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/parse/node.py", line 168, in _VisitNode
    new_child = _VisitNode(child, visitor, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/parse/node.py", line 209, in _VisitNode
    new_child = _VisitNode(child, visitor, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/parse/node.py", line 222, in _VisitNode
    new_node = visitor.Visit(new_node, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/base_visitor.py", line 203, in Visit
    return self.visit_functions[node.__class__.__name__](
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/pytype/pytd/visitors.py", line 473, in VisitNamedType
    raise KeyError(f"No {name} in module {module_name}") from e
KeyError: 'No NETLINK_CRYPT in module _socket'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ohhhh I forgot the O.....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What Linux OS? I believe these are imported from the C headers, so I expect this is going to be flavor-dependent in some cases, though I could be wrong about that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ubuntu 18.04, kernel 5.4.0. Yes, I think it depends on the kernel version and who knows what else. We should include all constants that can appear in realistic systems so people don't get false positives; we can't hope to replicate the exact conditions that determine what constants are available in stubs.

@github-actions

Copy link
Copy Markdown
Contributor

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

@AlexWaygood
AlexWaygood merged commit a8c8178 into python:master Aug 18, 2022
@kkirsche
kkirsche deleted the fix/7077 branch August 18, 2022 20:27
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.

Regression from 310 to 931: Module has no attribute "NETLINK_ROUTE"

3 participants