Skip to content

Commit 7e6df71

Browse files
authored
Address type issues found by ty (#225)
1 parent 6ebfaab commit 7e6df71

4 files changed

Lines changed: 67 additions & 64 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ jobs:
3232
python-version: ${{ matrix.python-version }}
3333
allow-prereleases: true
3434
- name: Install dependencies
35-
run: python -m pip install ruff mypy
35+
run: python -m pip install ruff mypy ty
3636
- name: Check code style with ruff
3737
run: |
3838
ruff format --check idna
3939
ruff check idna tests
4040
- name: Check types with mypy
4141
run: mypy --strict idna
42+
- name: Check types with ty
43+
run: ty check idna tests
4244

4345
build:
4446
strategy:

idna/codec.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class Codec(codecs.Codec):
11-
def encode(self, data: str, errors: str = "strict") -> Tuple[bytes, int]:
11+
def encode(self, data: str, errors: str = "strict") -> Tuple[bytes, int]: # ty: ignore[invalid-method-override]
1212
if errors != "strict":
1313
raise IDNAError('Unsupported error handling "{}"'.format(errors))
1414

@@ -17,7 +17,7 @@ def encode(self, data: str, errors: str = "strict") -> Tuple[bytes, int]:
1717

1818
return encode(data), len(data)
1919

20-
def decode(self, data: bytes, errors: str = "strict") -> Tuple[str, int]:
20+
def decode(self, data: bytes, errors: str = "strict") -> Tuple[str, int]: # ty: ignore[invalid-method-override]
2121
if errors != "strict":
2222
raise IDNAError('Unsupported error handling "{}"'.format(errors))
2323

@@ -28,7 +28,7 @@ def decode(self, data: bytes, errors: str = "strict") -> Tuple[str, int]:
2828

2929

3030
class IncrementalEncoder(codecs.BufferedIncrementalEncoder):
31-
def _buffer_encode(self, data: str, errors: str, final: bool) -> Tuple[bytes, int]:
31+
def _buffer_encode(self, data: str, errors: str, final: bool) -> Tuple[bytes, int]: # ty: ignore[invalid-method-override]
3232
if errors != "strict":
3333
raise IDNAError('Unsupported error handling "{}"'.format(errors))
3434

@@ -62,7 +62,7 @@ def _buffer_encode(self, data: str, errors: str, final: bool) -> Tuple[bytes, in
6262

6363

6464
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
65-
def _buffer_decode(self, data: Any, errors: str, final: bool) -> Tuple[str, int]:
65+
def _buffer_decode(self, data: Any, errors: str, final: bool) -> Tuple[str, int]: # ty: ignore[invalid-method-override]
6666
if errors != "strict":
6767
raise IDNAError('Unsupported error handling "{}"'.format(errors))
6868

idna/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False
342342
status = uts46row[1]
343343
replacement: Optional[str] = None
344344
if len(uts46row) == 3:
345-
replacement = uts46row[2]
345+
replacement = uts46row[2] # ty: ignore[index-out-of-bounds]
346346
if status == "V" or (status == "D" and not transitional) or (status == "3" and not std3_rules and replacement is None):
347347
output += char
348348
elif replacement is not None and (

tests/test_idna.py

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,80 @@
22

33
import unittest
44
import warnings
5+
from typing import List, Tuple
56

67
import idna
78

89

910
class IDNATests(unittest.TestCase):
1011
def setUp(self):
11-
self.tld_strings = [
12-
["\u6d4b\u8bd5", b"xn--0zwm56d"],
13-
["\u092a\u0930\u0940\u0915\u094d\u0937\u093e", b"xn--11b5bs3a9aj6g"],
14-
["\ud55c\uad6d", b"xn--3e0b707e"],
15-
["\u09ad\u09be\u09b0\u09a4", b"xn--45brj9c"],
16-
["\u09ac\u09be\u0982\u09b2\u09be", b"xn--54b7fta0cc"],
17-
[
12+
self.tld_strings: List[Tuple[str, bytes]] = [
13+
("\u6d4b\u8bd5", b"xn--0zwm56d"),
14+
("\u092a\u0930\u0940\u0915\u094d\u0937\u093e", b"xn--11b5bs3a9aj6g"),
15+
("\ud55c\uad6d", b"xn--3e0b707e"),
16+
("\u09ad\u09be\u09b0\u09a4", b"xn--45brj9c"),
17+
("\u09ac\u09be\u0982\u09b2\u09be", b"xn--54b7fta0cc"),
18+
(
1819
"\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435",
1920
b"xn--80akhbyknj4f",
20-
],
21-
["\u0441\u0440\u0431", b"xn--90a3ac"],
22-
["\ud14c\uc2a4\ud2b8", b"xn--9t4b11yi5a"],
23-
[
21+
),
22+
("\u0441\u0440\u0431", b"xn--90a3ac"),
23+
("\ud14c\uc2a4\ud2b8", b"xn--9t4b11yi5a"),
24+
(
2425
"\u0b9a\u0bbf\u0b99\u0bcd\u0b95\u0baa\u0bcd\u0baa\u0bc2\u0bb0\u0bcd",
2526
b"xn--clchc0ea0b2g2a9gcd",
26-
],
27-
["\u05d8\u05e2\u05e1\u05d8", b"xn--deba0ad"],
28-
["\u4e2d\u56fd", b"xn--fiqs8s"],
29-
["\u4e2d\u570b", b"xn--fiqz9s"],
30-
["\u0c2d\u0c3e\u0c30\u0c24\u0c4d", b"xn--fpcrj9c3d"],
31-
["\u0dbd\u0d82\u0d9a\u0dcf", b"xn--fzc2c9e2c"],
32-
["\u6e2c\u8a66", b"xn--g6w251d"],
33-
["\u0aad\u0abe\u0ab0\u0aa4", b"xn--gecrj9c"],
34-
["\u092d\u093e\u0930\u0924", b"xn--h2brj9c"],
35-
["\u0622\u0632\u0645\u0627\u06cc\u0634\u06cc", b"xn--hgbk6aj7f53bba"],
36-
["\u0baa\u0bb0\u0bbf\u0b9f\u0bcd\u0b9a\u0bc8", b"xn--hlcj6aya9esc7a"],
37-
["\u0443\u043a\u0440", b"xn--j1amh"],
38-
["\u9999\u6e2f", b"xn--j6w193g"],
39-
["\u03b4\u03bf\u03ba\u03b9\u03bc\u03ae", b"xn--jxalpdlp"],
40-
["\u0625\u062e\u062a\u0628\u0627\u0631", b"xn--kgbechtv"],
41-
["\u53f0\u6e7e", b"xn--kprw13d"],
42-
["\u53f0\u7063", b"xn--kpry57d"],
43-
["\u0627\u0644\u062c\u0632\u0627\u0626\u0631", b"xn--lgbbat1ad8j"],
44-
["\u0639\u0645\u0627\u0646", b"xn--mgb9awbf"],
45-
["\u0627\u06cc\u0631\u0627\u0646", b"xn--mgba3a4f16a"],
46-
["\u0627\u0645\u0627\u0631\u0627\u062a", b"xn--mgbaam7a8h"],
47-
["\u067e\u0627\u06a9\u0633\u062a\u0627\u0646", b"xn--mgbai9azgqp6j"],
48-
["\u0627\u0644\u0627\u0631\u062f\u0646", b"xn--mgbayh7gpa"],
49-
["\u0628\u06be\u0627\u0631\u062a", b"xn--mgbbh1a71e"],
50-
["\u0627\u0644\u0645\u063a\u0631\u0628", b"xn--mgbc0a9azcg"],
51-
["\u0627\u0644\u0633\u0639\u0648\u062f\u064a\u0629", b"xn--mgberp4a5d4ar"],
52-
["\u10d2\u10d4", b"xn--node"],
53-
["\u0e44\u0e17\u0e22", b"xn--o3cw4h"],
54-
["\u0633\u0648\u0631\u064a\u0629", b"xn--ogbpf8fl"],
55-
["\u0440\u0444", b"xn--p1ai"],
56-
["\u062a\u0648\u0646\u0633", b"xn--pgbs0dh"],
57-
["\u0a2d\u0a3e\u0a30\u0a24", b"xn--s9brj9c"],
58-
["\u0645\u0635\u0631", b"xn--wgbh1c"],
59-
["\u0642\u0637\u0631", b"xn--wgbl6a"],
60-
["\u0b87\u0bb2\u0b99\u0bcd\u0b95\u0bc8", b"xn--xkc2al3hye2a"],
61-
["\u0b87\u0ba8\u0bcd\u0ba4\u0bbf\u0baf\u0bbe", b"xn--xkc2dl3a5ee0h"],
62-
["\u65b0\u52a0\u5761", b"xn--yfro4i67o"],
63-
["\u0641\u0644\u0633\u0637\u064a\u0646", b"xn--ygbi2ammx"],
64-
["\u30c6\u30b9\u30c8", b"xn--zckzah"],
65-
["\u049b\u0430\u0437", b"xn--80ao21a"],
66-
["\u0645\u0644\u064a\u0633\u064a\u0627", b"xn--mgbx4cd0ab"],
67-
["\u043c\u043e\u043d", b"xn--l1acc"],
68-
["\u0633\u0648\u062f\u0627\u0646", b"xn--mgbpl2fh"],
27+
),
28+
("\u05d8\u05e2\u05e1\u05d8", b"xn--deba0ad"),
29+
("\u4e2d\u56fd", b"xn--fiqs8s"),
30+
("\u4e2d\u570b", b"xn--fiqz9s"),
31+
("\u0c2d\u0c3e\u0c30\u0c24\u0c4d", b"xn--fpcrj9c3d"),
32+
("\u0dbd\u0d82\u0d9a\u0dcf", b"xn--fzc2c9e2c"),
33+
("\u6e2c\u8a66", b"xn--g6w251d"),
34+
("\u0aad\u0abe\u0ab0\u0aa4", b"xn--gecrj9c"),
35+
("\u092d\u093e\u0930\u0924", b"xn--h2brj9c"),
36+
("\u0622\u0632\u0645\u0627\u06cc\u0634\u06cc", b"xn--hgbk6aj7f53bba"),
37+
("\u0baa\u0bb0\u0bbf\u0b9f\u0bcd\u0b9a\u0bc8", b"xn--hlcj6aya9esc7a"),
38+
("\u0443\u043a\u0440", b"xn--j1amh"),
39+
("\u9999\u6e2f", b"xn--j6w193g"),
40+
("\u03b4\u03bf\u03ba\u03b9\u03bc\u03ae", b"xn--jxalpdlp"),
41+
("\u0625\u062e\u062a\u0628\u0627\u0631", b"xn--kgbechtv"),
42+
("\u53f0\u6e7e", b"xn--kprw13d"),
43+
("\u53f0\u7063", b"xn--kpry57d"),
44+
("\u0627\u0644\u062c\u0632\u0627\u0626\u0631", b"xn--lgbbat1ad8j"),
45+
("\u0639\u0645\u0627\u0646", b"xn--mgb9awbf"),
46+
("\u0627\u06cc\u0631\u0627\u0646", b"xn--mgba3a4f16a"),
47+
("\u0627\u0645\u0627\u0631\u0627\u062a", b"xn--mgbaam7a8h"),
48+
("\u067e\u0627\u06a9\u0633\u062a\u0627\u0646", b"xn--mgbai9azgqp6j"),
49+
("\u0627\u0644\u0627\u0631\u062f\u0646", b"xn--mgbayh7gpa"),
50+
("\u0628\u06be\u0627\u0631\u062a", b"xn--mgbbh1a71e"),
51+
("\u0627\u0644\u0645\u063a\u0631\u0628", b"xn--mgbc0a9azcg"),
52+
("\u0627\u0644\u0633\u0639\u0648\u062f\u064a\u0629", b"xn--mgberp4a5d4ar"),
53+
("\u10d2\u10d4", b"xn--node"),
54+
("\u0e44\u0e17\u0e22", b"xn--o3cw4h"),
55+
("\u0633\u0648\u0631\u064a\u0629", b"xn--ogbpf8fl"),
56+
("\u0440\u0444", b"xn--p1ai"),
57+
("\u062a\u0648\u0646\u0633", b"xn--pgbs0dh"),
58+
("\u0a2d\u0a3e\u0a30\u0a24", b"xn--s9brj9c"),
59+
("\u0645\u0635\u0631", b"xn--wgbh1c"),
60+
("\u0642\u0637\u0631", b"xn--wgbl6a"),
61+
("\u0b87\u0bb2\u0b99\u0bcd\u0b95\u0bc8", b"xn--xkc2al3hye2a"),
62+
("\u0b87\u0ba8\u0bcd\u0ba4\u0bbf\u0baf\u0bbe", b"xn--xkc2dl3a5ee0h"),
63+
("\u65b0\u52a0\u5761", b"xn--yfro4i67o"),
64+
("\u0641\u0644\u0633\u0637\u064a\u0646", b"xn--ygbi2ammx"),
65+
("\u30c6\u30b9\u30c8", b"xn--zckzah"),
66+
("\u049b\u0430\u0437", b"xn--80ao21a"),
67+
("\u0645\u0644\u064a\u0633\u064a\u0627", b"xn--mgbx4cd0ab"),
68+
("\u043c\u043e\u043d", b"xn--l1acc"),
69+
("\u0633\u0648\u062f\u0627\u0646", b"xn--mgbpl2fh"),
6970
]
7071

7172
def testIDNTLDALabels(self):
72-
for ulabel, alabel in self.tld_strings:
73-
self.assertEqual(alabel, idna.alabel(ulabel))
73+
for u, a in self.tld_strings:
74+
self.assertEqual(a, idna.alabel(u))
7475

7576
def testIDNTLDULabels(self):
76-
for ulabel, alabel in self.tld_strings:
77-
self.assertEqual(ulabel, idna.ulabel(alabel))
77+
for u, a in self.tld_strings:
78+
self.assertEqual(u, idna.ulabel(a))
7879

7980
def test_valid_label_length(self):
8081
self.assertTrue(idna.valid_label_length("a" * 63))

0 commit comments

Comments
 (0)