Skip to content

Commit

Permalink
Add type stubs (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Jan 19, 2021
1 parent 8ba8151 commit 2b16336
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 2 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
@@ -1,5 +1,7 @@
include *.rst
include LICENSE.md
include idna/py.typed
recursive-include idna *.pyi
recursive-include tools *
recursive-exclude tools *.pyc
recursive-include tests *
Expand Down
44 changes: 43 additions & 1 deletion idna/__init__.py
@@ -1,2 +1,44 @@
from .package_data import __version__
from .core import *
from .core import (
IDNABidiError,
IDNAError,
InvalidCodepoint,
InvalidCodepointContext,
alabel,
check_bidi,
check_hyphen_ok,
check_initial_combiner,
check_label,
check_nfc,
decode,
encode,
intranges_contain,
ulabel,
uts46_remap,
valid_contextj,
valid_contexto,
valid_label_length,
valid_string_length,
)

__all__ = [
"IDNABidiError",
"IDNAError",
"InvalidCodepoint",
"InvalidCodepointContext",
"alabel",
"check_bidi",
"check_hyphen_ok",
"check_initial_combiner",
"check_label",
"check_nfc",
"decode",
"encode",
"intranges_contain",
"ulabel",
"uts46_remap",
"valid_contextj",
"valid_contexto",
"valid_label_length",
"valid_string_length",
]
27 changes: 27 additions & 0 deletions idna/codec.pyi
@@ -0,0 +1,27 @@
import codecs
from typing import Tuple

class Codec(codecs.Codec):
def encode(self, data: str, errors: str = ...) -> Tuple[bytes, int]: ...
def decode(self, data: bytes, errors: str = ...) -> Tuple[str, int]: ...

class IncrementalEncoder(codecs.BufferedIncrementalEncoder):
def _buffer_encode( # type: ignore
self,
data: str,
errors: str,
final: bool
) -> Tuple[str, int]: ...

class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
def _buffer_decode( # type: ignore
self,
data: str,
errors: str,
final: bool
) -> Tuple[str, int]: ...

class StreamWriter(Codec, codecs.StreamWriter): ...
class StreamReader(Codec, codecs.StreamReader): ...

def getregentry() -> codecs.CodecInfo: ...
5 changes: 5 additions & 0 deletions idna/compat.pyi
@@ -0,0 +1,5 @@
from typing import Any

def ToASCII(label: str) -> bytes: ...
def ToUnicode(label: bytes) -> str: ...
def nameprep(s: Any) -> None: ...
39 changes: 39 additions & 0 deletions idna/core.pyi
@@ -0,0 +1,39 @@
from typing import Union
from .intranges import intranges_contain as intranges_contain # noqa

class IDNAError(UnicodeError): ...
class IDNABidiError(IDNAError): ...
class InvalidCodepoint(IDNAError): ...
class InvalidCodepointContext(IDNAError): ...

def _combining_class(cp: int) -> int: ...
def _is_script(cp: str, script: str) -> bool: ...
def _punycode(s: str) -> bytes: ...
def _unot(s: int) -> str: ...
def valid_label_length(label: Union[str, bytes]) -> bool: ...
def valid_string_length(label: Union[str, bytes], trailing_dot: bool) -> bool: ...
def check_bidi(label: str, check_ltr: bool = ...) -> bool: ...
def check_initial_combiner(label: str) -> bool: ...
def check_hyphen_ok(label: str) -> bool: ...
def check_nfc(label: str) -> None: ...
def valid_contextj(label: str, pos: int) -> bool: ...
def valid_contexto(label: str, pos: int, exception: bool = False) -> bool: ...
def check_label(label: Union[str, bytes, bytearray]) -> None: ...
def alabel(label: str) -> bytes: ...
def ulabel(label: Union[str, bytes, bytearray]) -> str: ...
def uts46_remap(
domain: str, std3_rules: bool = ..., transitional: bool = ...
) -> str: ...
def encode(
s: Union[str, bytes, bytearray],
strict: bool = False,
uts46: bool = False,
std3_rules: bool = False,
transitional: bool = False,
) -> bytes: ...
def decode(
s: Union[str, bytes, bytearray],
strict: bool = ...,
uts46: bool = ...,
std3_rules: bool = ...,
) -> str: ...
6 changes: 6 additions & 0 deletions idna/idnadata.pyi
@@ -0,0 +1,6 @@
from typing import Dict, Tuple

__version__: str
scripts: Dict[str, Tuple[int, ...]]
joining_types: Dict[int, int]
codepoint_classes: Dict[str, Tuple[int, ...]]
6 changes: 6 additions & 0 deletions idna/intranges.pyi
@@ -0,0 +1,6 @@
from typing import List, Tuple

def intranges_from_list(list_: List[int]) -> Tuple[int, ...]: ...
def _encode_range(start: int, end: int) -> int: ...
def _decode_range(r: int) -> Tuple[int, int]: ...
def intranges_contain(int_: int, ranges: Tuple[int, ...]) -> bool: ...
1 change: 1 addition & 0 deletions idna/package_data.pyi
@@ -0,0 +1 @@
__version__: str
Empty file added idna/py.typed
Empty file.
4 changes: 4 additions & 0 deletions idna/uts46data.pyi
@@ -0,0 +1,4 @@
from typing import Tuple, Union

__version__: str
uts46data: Tuple[Union[Tuple[int, str], Tuple[int, str, str]], ...]
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -22,6 +22,8 @@ def main():
arguments = {
'name': 'idna',
'packages': ['idna'],
'package_data': {'idna': ['py.typed', '*.pyi']},
'include_package_data': True,
'version': package_data['__version__'],
'description': 'Internationalized Domain Names in Applications (IDNA)',
'long_description': open("README.rst", encoding="UTF-8").read(),
Expand All @@ -38,7 +40,6 @@ def main():
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down

0 comments on commit 2b16336

Please sign in to comment.