Skip to content

Commit

Permalink
Added type stub for pytricia library
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJokr committed Apr 3, 2020
1 parent 6442351 commit dee7439
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ignore = W504
max-line-length = 120

[mypy]
mypy_path = ./stubs
show_error_context = True
warn_redundant_casts = True
warn_unused_ignores = True
Expand Down
30 changes: 30 additions & 0 deletions stubs/pytricia.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import TypeVar, overload, Generic, Iterator, List, Tuple, Union
from socket import AF_INET as _AF_INET
from ipaddress import _BaseAddress, _BaseNetwork

_KT = Union[str, int, bytes, Tuple[bytes, int], _BaseAddress, _BaseNetwork]
_KOutT = Union[str, Tuple[bytes, int]]
_VT = TypeVar("_VT")


class PyTricia(Generic[_VT]):
def __init__(self, prefixlen: int = 32, family: int = _AF_INET, raw_output: bool = False) -> None: ...

def __len__(self) -> int: ...
def __contains__(self, key: _KT) -> bool: ...
def __getitem__(self, key: _KT) -> _VT: ...
def __setitem__(self, key: _KT, value: _VT) -> None: ...
def __delitem__(self, key: _KT) -> None: ...
def __iter__(self) -> Iterator[_KOutT]: ...

def has_key(self, key: _KT) -> bool: ...
def keys(self) -> List[_KOutT]: ...
def get(self, key: _KT, default: _VT = None) -> _VT: ...
def get_key(self, key: _KT) -> _KOutT: ...
def delete(self, key: _KT) -> None: ...
@overload
def insert(self, key: _KT, value: _VT) -> None: ...
@overload
def insert(self, key: _KT, prefixlen: int, value: _VT) -> None: ...
def children(self, key: _KT) -> List[_KOutT]: ...
def parent(self, key: _KT) -> List[_KOutT]: ...

0 comments on commit dee7439

Please sign in to comment.