-
Notifications
You must be signed in to change notification settings - Fork 41
Use Mypy #80
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
Merged
Use Mypy #80
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e0cee8a
Move definition of inet_pton into its own file so that the Windows-sp…
wsanchez a893c30
.tox is a directory
wsanchez 03ee5d1
Bring mypy into the tox config
wsanchez 16a83d9
Make mypy happy
wsanchez 45f709a
Unnecessary bare return
wsanchez f6e87a6
Silent flake8 from having opinions about type comments; let mypy comp…
wsanchez ed00543
Add hints to test modules.
wsanchez 6075f05
More hints
wsanchez 461962c
cast bad values to expected types to appease mypy
wsanchez 3567582
Don't try to get coverage on type check section
wsanchez 9c35a80
Don't use lambda functions, which create a coverage problem.
wsanchez fad88c7
Add test for inet_pton
wsanchez f1d1ffa
Has to be an int
wsanchez 65c7306
Try harder to find a bogus family
wsanchez c1f7739
Add type hints
wsanchez e4c0014
Cause mypy to check the Windows code on non-Windows systems.
wsanchez ddd6c7f
Start with a valid number so the incrementing code below gets use bec…
wsanchez f296f0f
not, yo
wsanchez deeca8c
Don't send an invalid address in addition to an invalid family.
wsanchez a6e027e
Do our handling of address_family before WSAStringToAddressA gets a c…
wsanchez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| try: | ||
| from socket import inet_pton | ||
| except ImportError: | ||
| from typing import TYPE_CHECKING | ||
| if TYPE_CHECKING: # pragma: no cover | ||
| pass | ||
| else: | ||
| # based on https://gist.github.com/nnemkin/4966028 | ||
| # this code only applies on Windows Python 2.7 | ||
| import ctypes | ||
| import socket | ||
|
|
||
| class SockAddr(ctypes.Structure): | ||
| _fields_ = [ | ||
| ("sa_family", ctypes.c_short), | ||
| ("__pad1", ctypes.c_ushort), | ||
| ("ipv4_addr", ctypes.c_byte * 4), | ||
| ("ipv6_addr", ctypes.c_byte * 16), | ||
| ("__pad2", ctypes.c_ulong), | ||
| ] | ||
|
|
||
| WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA | ||
| WSAAddressToStringA = ctypes.windll.ws2_32.WSAAddressToStringA | ||
|
|
||
| def inet_pton(address_family, ip_string): | ||
| # type: (int, str) -> bytes | ||
| addr = SockAddr() | ||
| ip_string_bytes = ip_string.encode('ascii') | ||
| addr.sa_family = address_family | ||
| addr_size = ctypes.c_int(ctypes.sizeof(addr)) | ||
|
|
||
| try: | ||
| attribute, size = { | ||
| socket.AF_INET: ("ipv4_addr", 4), | ||
| socket.AF_INET6: ("ipv6_addr", 16), | ||
| }[address_family] | ||
| except KeyError: | ||
| raise socket.error("unknown address family") | ||
|
|
||
| if WSAStringToAddressA( | ||
| ip_string_bytes, address_family, None, | ||
| ctypes.byref(addr), ctypes.byref(addr_size) | ||
| ) != 0: | ||
| raise socket.error(ctypes.FormatError()) | ||
|
|
||
| return ctypes.string_at(getattr(addr, attribute), size) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.