Skip to content

Commit b0ef4bf

Browse files
authored
Move types into source, drop Python 3.4 (#96)
* Move types into source, drop Python 3.4 * Make number_type Optional[str]
1 parent a9e4f73 commit b0ef4bf

17 files changed

+180
-150
lines changed

.travis.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ arch:
33
- amd64
44
- ppc64le
55
python:
6-
- "3.4"
76
- "3.5"
87
- "3.6"
98
- "3.7"
109
- "3.8"
1110
- "3.9"
1211
- "pypy3"
13-
# Disable unsuported version pypy for ppc64le
12+
# Disable unsupported version pypy for ppc64le
1413
jobs:
1514
exclude:
1615
- arch: ppc64le
1716
python: pypy3
1817

18+
matrix:
19+
include:
20+
- python: 3.9
21+
install:
22+
- pip install mypy
23+
script:
24+
- mypy --strict idna/
25+
1926
install:
2027
- pip install .
2128
script:

MANIFEST.in

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
include *.rst
22
include LICENSE.md
33
include idna/py.typed
4-
recursive-include idna *.pyi
54
recursive-include tools *
65
recursive-exclude tools *.pyc
76
recursive-include tests *

idna/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
check_nfc,
1313
decode,
1414
encode,
15-
intranges_contain,
1615
ulabel,
1716
uts46_remap,
1817
valid_contextj,
1918
valid_contexto,
2019
valid_label_length,
2120
valid_string_length,
2221
)
22+
from .intranges import intranges_contain
2323

2424
__all__ = [
2525
"IDNABidiError",

idna/codec.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
from .core import encode, decode, alabel, ulabel, IDNAError
22
import codecs
33
import re
4+
from typing import Tuple, Optional
45

56
_unicode_dots_re = re.compile('[\u002e\u3002\uff0e\uff61]')
67

78
class Codec(codecs.Codec):
89

910
def encode(self, data, errors='strict'):
10-
11+
# type: (str, str) -> Tuple[bytes, int]
1112
if errors != 'strict':
1213
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))
1314

1415
if not data:
15-
return "", 0
16+
return b"", 0
1617

1718
return encode(data), len(data)
1819

1920
def decode(self, data, errors='strict'):
20-
21+
# type: (bytes, str) -> Tuple[str, int]
2122
if errors != 'strict':
2223
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))
2324

@@ -27,12 +28,13 @@ def decode(self, data, errors='strict'):
2728
return decode(data), len(data)
2829

2930
class IncrementalEncoder(codecs.BufferedIncrementalEncoder):
30-
def _buffer_encode(self, data, errors, final):
31+
def _buffer_encode(self, data, errors, final): # type: ignore
32+
# type: (str, str, bool) -> Tuple[str, int]
3133
if errors != 'strict':
3234
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))
3335

3436
if not data:
35-
return ('', 0)
37+
return "", 0
3638

3739
labels = _unicode_dots_re.split(data)
3840
trailing_dot = ''
@@ -55,12 +57,13 @@ def _buffer_encode(self, data, errors, final):
5557
size += len(label)
5658

5759
# Join with U+002E
58-
result = '.'.join(result) + trailing_dot
60+
result_str = '.'.join(result) + trailing_dot # type: ignore
5961
size += len(trailing_dot)
60-
return (result, size)
62+
return result_str, size
6163

6264
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
63-
def _buffer_decode(self, data, errors, final):
65+
def _buffer_decode(self, data, errors, final): # type: ignore
66+
# type: (str, str, bool) -> Tuple[str, int]
6467
if errors != 'strict':
6568
raise IDNAError('Unsupported error handling \"{}\"'.format(errors))
6669

@@ -87,22 +90,26 @@ def _buffer_decode(self, data, errors, final):
8790
size += 1
8891
size += len(label)
8992

90-
result = '.'.join(result) + trailing_dot
93+
result_str = '.'.join(result) + trailing_dot
9194
size += len(trailing_dot)
92-
return (result, size)
95+
return (result_str, size)
9396

9497

9598
class StreamWriter(Codec, codecs.StreamWriter):
9699
pass
97100

101+
98102
class StreamReader(Codec, codecs.StreamReader):
99103
pass
100104

105+
101106
def getregentry():
107+
# type: () -> codecs.CodecInfo
108+
# Compatibility as a search_function for codecs.register()
102109
return codecs.CodecInfo(
103110
name='idna',
104-
encode=Codec().encode,
105-
decode=Codec().decode,
111+
encode=Codec().encode, # type: ignore
112+
decode=Codec().decode, # type: ignore
106113
incrementalencoder=IncrementalEncoder,
107114
incrementaldecoder=IncrementalDecoder,
108115
streamwriter=StreamWriter,

idna/codec.pyi

-27
This file was deleted.

idna/compat.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from .core import *
22
from .codec import *
3+
from typing import Any, Union
34

45
def ToASCII(label):
6+
# type: (str) -> bytes
57
return encode(label)
68

79
def ToUnicode(label):
10+
# type: (Union[bytes, bytearray]) -> str
811
return decode(label)
912

1013
def nameprep(s):
14+
# type: (Any) -> None
1115
raise NotImplementedError('IDNA 2008 does not utilise nameprep protocol')
1216

idna/compat.pyi

-5
This file was deleted.

0 commit comments

Comments
 (0)