Skip to content
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

Add type stubs #94

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__: str
Empty file added idna/py.typed
Empty file.
4 changes: 4 additions & 0 deletions idna/uts46data.pyi
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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