Skip to content

Add tuple argument to ip_network#8634

Merged
AlexWaygood merged 4 commits into
python:masterfrom
sobolevn:patch-30
Aug 27, 2022
Merged

Add tuple argument to ip_network#8634
AlexWaygood merged 4 commits into
python:masterfrom
sobolevn:patch-30

Conversation

@github-actions

This comment has been minimized.

Comment thread stdlib/ipaddress.pyi Outdated
@github-actions

Copy link
Copy Markdown
Contributor

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

@AlexWaygood AlexWaygood left a comment

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.

I'm a bit uneasy about this change. It's true that it works at runtime, but passing a tuple in here seems to be entirely undocumented and untested, so I feel like it could change at any time without any backwards-compatibility guarantees.

@sobolevn

Copy link
Copy Markdown
Member Author

I don't have any opinion really

@Akuli

Akuli commented Aug 27, 2022

Copy link
Copy Markdown
Collaborator

We should in general type things as the implementation does it, not as documented. I think it applies here too. I also don't see any reason why tests for this function should check with all types that IPv4Network and IPv6Network accept, even though that's the intention; that would make the tests longer without increasing the test coverage.

If someone still feels "uneasy" about this, we could add a test case -- again, nothing too thorough, could be for example the two examples in the issue.

@Akuli

Akuli commented Aug 27, 2022

Copy link
Copy Markdown
Collaborator

And I just realized that adding a test case to typeshed would be pointless, as those don't run at runtime :) I still think we should support this, because it works.

@AlexWaygood

AlexWaygood commented Aug 27, 2022

Copy link
Copy Markdown
Member

I still think we should support this, because it works.

I'm fine with this being merged, just don't necessarily want to be the one to hit "merge" myself :)

I agree that in general, we should follow the implementation rather than the documentation.

@Akuli

Akuli commented Aug 27, 2022

Copy link
Copy Markdown
Collaborator

Passing in a tuple seems to be a common pattern: https://grep.app/search?q=ip_network%28%28

@AlexWaygood AlexWaygood left a comment

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.

I'm convinced.

@AlexWaygood
AlexWaygood merged commit 6d5fd0e into python:master Aug 27, 2022
@sobolevn

Copy link
Copy Markdown
Member Author

🥳

@zed

zed commented Sep 5, 2022

Copy link
Copy Markdown

The discussion here led me to believe that a tuple ip_network argument might be unsupported, so I've looked it up: the two-tuple form for the (ip network) address constructor parameter is documented (supported since Python 3.5) and the corresponding commit has tests too python/cpython@5fb195f

i.e., the two-tuple support won't go away without breaking backward compatibility.

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.

ipaddress.ip_network annotations ban tuple arguments

4 participants