-
Notifications
You must be signed in to change notification settings - Fork 83
Provide *.pyi stubs for mypy #39
Comments
For the existing API it should be rather simple, like this: # Stubs for netifaces (Python 3)
from typing import Any, Mapping, Sequence, Tuple, Union
AF_APPLETALK: int
AF_ASH: int
AF_ATMPVC: int
AF_ATMSVC: int
AF_AX25: int
AF_BLUETOOTH: int
AF_BRIDGE: int
AF_DECnet: int
AF_ECONET: int
AF_FILE: int
AF_INET: int
AF_INET6: int
AF_IPX: int
AF_IRDA: int
AF_ISDN: int
AF_KEY: int
AF_LINK: int
AF_NETBEUI: int
AF_NETLINK: int
AF_NETROM: int
AF_PACKET: int
AF_PPPOX: int
AF_ROSE: int
AF_ROUTE: int
AF_SECURITY: int
AF_SNA: int
AF_UNIX: int
AF_UNSPEC: int
AF_WANPIPE: int
AF_X25: int
address_families: Mapping[int, str]
version: str
def interfaces() -> Sequence[str]: ...
def ifaddresses(interface: str) -> Mapping[int, Sequence[Mapping[str, str]]]: ...
def gateways() -> Mapping[Union[int, str], Union[Sequence[Tuple[str, str, bool]], Mapping[int, Tuple[str, str]]]]: ... |
This stub could be added as |
The alternative would be to donate this stub file to |
Hello? :) |
Sorry, I've been quite busy with other things (not least my personal life, which has all fallen apart). I don't think it's quite as simple as you make out; the address family constants don't necessarily exist (which do depends on the platform you're on), and having not read PEP 561 (yet) I don't know whether declaring their types if they aren't actually in existence is allowable. (As for your first comment, no, I didn't, because I hadn't seen PEP 561, which netifaces predates.) |
My condolences. Shit happens, indeed. Static typing is for checking the code is okay, not for guaranteeing it would work correctly. Also, the general The stubs can use traditional methods like So my suggestion is to have all possible constants listed in the stub and just ignore the fact some of them may be unavailable on some platforms. Or, it may be worth add comments to particular constants like "Available on Linux" or "Unavailable on Linux", that would help the future developers understand, why |
For example, see |
@jstasiak Sure no problem. |
Didn't you think of providing static typing stubs for this library?
The text was updated successfully, but these errors were encountered: