Skip to content

Commit ec110d0

Browse files
authored
Merge pull request #262 from kjd/ruff-update
Update to ruff 0.16 and adopt its expanded default rule set
2 parents b54576b + 3187398 commit ec110d0

13 files changed

Lines changed: 64 additions & 55 deletions

File tree

.github/requirements/lint.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was autogenerated by uv via the following command:
2-
# uv pip compile --generate-hashes .github/requirements/lint.in -o .github/requirements/lint.txt
2+
# uv pip compile --generate-hashes --python-version 3.14 .github/requirements/lint.in -o .github/requirements/lint.txt
33
ast-serialize==0.4.0 \
44
--hash=sha256:074032142777e3e6091977dc3c5146a8ca58ae6825b7f64e9a0b604153ddabd8 \
55
--hash=sha256:1026f565a7ab846337c630909089b3346a2fe417bf1552b1581ab01852137407 \
@@ -179,25 +179,25 @@ pathspec==1.1.1 \
179179
--hash=sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a \
180180
--hash=sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189
181181
# via mypy
182-
ruff==0.15.13 \
183-
--hash=sha256:1c26d2f66163deeb6e08d8b39fbbe983ce3c71cea06a6d7591cfd1421793c629 \
184-
--hash=sha256:2471da9bd1068c8c064b5fd9c0c4b6dddffd6369cb1cd68b29993b1709ff1b21 \
185-
--hash=sha256:2e2e39bff6c341f4b577a21b801326fab0b11847f48fcaa83f00a113c9b3cb55 \
186-
--hash=sha256:4044f94208b3b05ba0fc4a4abd0558cf4d6459bd18325eead7fd8cc66f909b41 \
187-
--hash=sha256:444b580fc72fd6887e650acd3e575e18cdc79dbcf42fb4030b491057921f61f8 \
188-
--hash=sha256:6590d009e7cb7ebf36f83dbdd44a3fa48a0994ff6f1cdc1b08006abe58f98dc7 \
189-
--hash=sha256:7064884d442b7d477b4e7473d12da7f08851d2b1982763c5d3f388a19468a1a4 \
190-
--hash=sha256:768494eb08b9cee54e2fd27969966f74db5a57f6eaa7a90fcb3306af34dfc4bd \
191-
--hash=sha256:7ef823f817fcd191dc934e984be9cf4094f808effa16f2542ad8e821ba02bbf2 \
192-
--hash=sha256:8cb74dd33bb2f6613faf7fc03b660053b5ac4f80e706d5788c6335e2a8048d51 \
193-
--hash=sha256:9dbd6f94b434f896308e4d57fb7bfde0d02b99f7a64b3bdab0fdfa6a864203a5 \
194-
--hash=sha256:ae9c17e5eb4430c154e76abc25d79a318190f5a997f38fb6b114416c5319ffc9 \
195-
--hash=sha256:bf3259f3be4d181bda591da5db2571aed6853c6a048157756448020bc6c5cd22 \
196-
--hash=sha256:cc411dfebe5eebe55ce041c6ae080eb7668955e866daa2fbb16692a784f1c4ca \
197-
--hash=sha256:e8d9a8e08013542e94d3220bc5b62cc3e5ef87c5f74bff367d3fac14fab013e6 \
198-
--hash=sha256:f345a13937bd7f09f6f5d19fa0721b0c103e00e7f62bc67089a8e5e037719e0b \
199-
--hash=sha256:f9d89f17f7ba7fb2ed42921f0df75da797a9a5d71bc39049e2c687cf2baf44b7 \
200-
--hash=sha256:fb75f9a3a7e42ffe117d734494e6c5e5cb3565d66e12612cb63d0e572a41a5b6
182+
ruff==0.16.3 \
183+
--hash=sha256:09571e6d1288ed9be475207a3ac04ada404f1cd898104be0f6ab8d7df438575b \
184+
--hash=sha256:0c5710e247a58a4521e66e124ba9a74655b414f61ba3a2e9e3811e11098f48f7 \
185+
--hash=sha256:294b95c4ae0cda9388525c2047778aa758d6b8d4bb876fd4e9eaa3ebc92343eb \
186+
--hash=sha256:2c18c5a101eb540010638cc1ff3c84944d3adb3df62b8d98ca8f22ba484d3413 \
187+
--hash=sha256:388cdf2166642bd9b13d52b5932d3170f34f8abed7e8d9a855f1d84b83645a0a \
188+
--hash=sha256:3d0c7c40c87c2a820509c31ba007968da6e1306468c067b2d82fbfdbcd0e8474 \
189+
--hash=sha256:8457c44f15033c85ddbb77b15d451df9e24e4bd03b628396dd3610cedc3b8f82 \
190+
--hash=sha256:9e0b1da805eb043654645d74d5de1e5ce2edc686e40790d2b86f56d71cc06a84 \
191+
--hash=sha256:9f738c0fdfa8eed0b2ce7fb27ee7258208a92a68d7949e62aa15164bc7b389da \
192+
--hash=sha256:a2d85c02f9b8e165d85e6779184d38c4132de12603dab59c51c28e22584f9e4d \
193+
--hash=sha256:a37bdea0bbe21780f590bf437d6412c8c4e1b6cd010f91a65c2c40c5e5f5f870 \
194+
--hash=sha256:b8ca152da82c1acc1fa8d5874b15951935f0eef46f10e6954c83859011b6178a \
195+
--hash=sha256:c5536e3acfbf9563085aa2be7b13c629c3077e902afc5b941ac44024dbb9f506 \
196+
--hash=sha256:e2ed719e14aa64d895c2ee922594a90a43c861a93f0575a95ff8c47cdbd13eb9 \
197+
--hash=sha256:e76d33a347661a84b5be6d043d0347fdc745dfdcf825a8f4fed64b5e26eebdf2 \
198+
--hash=sha256:e80a7d69ca2a6d1c4d352ec91458cdca6e56c83cdbcabd93e4abe1e53591d948 \
199+
--hash=sha256:fb785f0be25abe69d320415cd4f833b59e17ba7613d9ba6a958023b6bceb0a50 \
200+
--hash=sha256:fe155130631a2471fd2e14a7a664a4dfbd7194b8229c3d7b2a40b21178639081
201201
# via -r .github/requirements/lint.in
202202
ty==0.0.37 \
203203
--hash=sha256:119332095c5974fe1dabfe4fd00c6759eeec5b99f7d7a80b2833feee5a58abdb \

idna/cli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
Invoked via ``python -m idna``. See :func:`main` for the entry point.
44
"""
55

6+
from __future__ import annotations
7+
68
import argparse
79
import sys
8-
from collections.abc import Iterable
910
from itertools import chain
10-
from typing import IO, Optional
11+
from typing import IO, TYPE_CHECKING
1112

1213
from . import IDNAError, decode, encode
1314
from .core import _alabel_prefix, _unicode_dots_re
1415
from .package_data import __version__
1516

17+
if TYPE_CHECKING:
18+
from collections.abc import Iterable
19+
1620

1721
def _looks_like_alabel(s: str) -> bool:
1822
"""Return True if any label in ``s`` carries the ``xn--`` ACE prefix."""
@@ -91,7 +95,7 @@ def _convert_one(domain: str, mode: str, uts46: bool) -> bool:
9195
return True
9296

9397

94-
def main(argv: Optional[list[str]] = None) -> int:
98+
def main(argv: list[str] | None = None) -> int:
9599
"""Entry point for ``python -m idna``.
96100
97101
When more than one domain is supplied (via positional arguments or

idna/codec.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
import codecs
2-
from typing import Any, Optional
4+
from typing import Any
35

46
from .core import IDNAError, _unicode_dots_re, alabel, decode, encode, ulabel
57

@@ -132,7 +134,7 @@ class StreamReader(Codec, codecs.StreamReader):
132134
pass
133135

134136

135-
def search_function(name: str) -> Optional[codecs.CodecInfo]:
137+
def search_function(name: str) -> codecs.CodecInfo | None:
136138
"""Codec search function registered with :mod:`codecs`.
137139
138140
Returns a :class:`codecs.CodecInfo` for the ``"idna2008"`` codec name

idna/compat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from typing import Any, Union
1+
from __future__ import annotations
2+
3+
from typing import Any
24

35
from .core import decode, encode
46

@@ -16,7 +18,7 @@ def ToASCII(label: str) -> bytes:
1618
return encode(label)
1719

1820

19-
def ToUnicode(label: Union[bytes, bytearray]) -> str:
21+
def ToUnicode(label: bytes | bytearray) -> str:
2022
"""Compatibility shim for :rfc:`3490` ``ToUnicode``.
2123
2224
Delegates to :func:`idna.decode` (IDNA 2008). Provided to ease porting

idna/core.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from __future__ import annotations
2+
13
import bisect
24
import re
35
import unicodedata
46
import warnings
5-
from typing import Optional, Union
67

78
from . import idnadata
89
from .intranges import intranges_contain
@@ -25,7 +26,7 @@
2526
_bidi_joiner_r_or_d = frozenset({"R", "D"})
2627

2728

28-
def _joining_type(cp: int) -> Optional[str]:
29+
def _joining_type(cp: int) -> str | None:
2930
for jt, ranges in idnadata.joining_types.items():
3031
if intranges_contain(cp, ranges):
3132
return jt
@@ -67,7 +68,7 @@ def _unot(s: int) -> str:
6768
return f"U+{s:04X}"
6869

6970

70-
def valid_label_length(label: Union[bytes, str]) -> bool:
71+
def valid_label_length(label: bytes | str) -> bool:
7172
"""Check that a label does not exceed the maximum permitted length.
7273
7374
Per :rfc:`1035` (and :rfc:`5891` §4.2.4) a DNS label must not exceed
@@ -82,7 +83,7 @@ def valid_label_length(label: Union[bytes, str]) -> bool:
8283
return len(label) <= 63
8384

8485

85-
def valid_string_length(domain: Union[bytes, str], trailing_dot: bool) -> bool:
86+
def valid_string_length(domain: bytes | str, trailing_dot: bool) -> bool:
8687
"""Check that a full domain name does not exceed the maximum length.
8788
8889
Per :rfc:`1035`, a domain name is limited to 253 octets when no trailing
@@ -136,7 +137,7 @@ def check_bidi(label: str, check_ltr: bool = False) -> bool:
136137
raise IDNABidiError(f"First codepoint in label {label!r} must be directionality L, R or AL")
137138

138139
valid_ending = False
139-
number_type: Optional[str] = None
140+
number_type: str | None = None
140141
for idx, cp in enumerate(label, 1):
141142
direction = unicodedata.bidirectional(cp)
142143

@@ -319,7 +320,7 @@ def valid_contexto(label: str, pos: int, exception: bool = False) -> bool:
319320
return False
320321

321322

322-
def check_label(label: Union[str, bytes, bytearray]) -> None:
323+
def check_label(label: str | bytes | bytearray) -> None:
323324
"""Run the full set of IDNA 2008 validity checks on a single label.
324325
325326
Applies, in order: NFC normalisation (:func:`check_nfc`), hyphen
@@ -409,7 +410,7 @@ def alabel(label: str) -> bytes:
409410
return label_bytes
410411

411412

412-
def ulabel(label: Union[str, bytes, bytearray]) -> str:
413+
def ulabel(label: str | bytes | bytearray) -> str:
413414
"""Convert a single A-label into its U-label form.
414415
415416
Performs the inverse of :func:`alabel`: an ``xn--``-prefixed label is
@@ -482,7 +483,7 @@ def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False
482483
code_point = ord(char)
483484
i = code_point if code_point < 256 else bisect.bisect_right(uts46_starts, code_point) - 1
484485
status = chr(uts46_statuses[i])
485-
replacement: Optional[str] = uts46_replacements[i]
486+
replacement: str | None = uts46_replacements[i]
486487

487488
# UTS #46 §4: V is always valid, D is deviation (kept unless transitional),
488489
# 3 is disallowed-STD3 (kept unmapped if std3_rules is off and no mapping).
@@ -509,7 +510,7 @@ def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False
509510

510511

511512
def encode(
512-
s: Union[str, bytes, bytearray],
513+
s: str | bytes | bytearray,
513514
strict: bool = False,
514515
uts46: bool = False,
515516
std3_rules: bool = False,
@@ -581,7 +582,7 @@ def encode(
581582

582583

583584
def decode(
584-
s: Union[str, bytes, bytearray],
585+
s: str | bytes | bytearray,
585586
strict: bool = False,
586587
uts46: bool = False,
587588
std3_rules: bool = False,

idna/uts46data.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# This file is automatically generated by tools/idna-data
22

3+
from __future__ import annotations
4+
35
from array import array
4-
from typing import Optional
56

67
"""IDNA Mapping Table from UTS46."""
78

89

910
__version__ = "17.0.0"
1011

11-
uts46_starts: "array[int]" = array(
12+
uts46_starts: array[int] = array(
1213
"I",
1314
(
1415
0x0,
@@ -8520,7 +8521,7 @@
85208521
b"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMXVXVXIX"
85218522
)
85228523

8523-
uts46_replacements: tuple[Optional[str], ...] = (
8524+
uts46_replacements: tuple[str | None, ...] = (
85248525
None,
85258526
None,
85268527
None,

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ include = ["tests", "tools", "HISTORY.md"]
4848

4949
[project.optional-dependencies]
5050
all = [
51-
"ruff >= 0.6.2",
51+
"ruff >= 0.16.0",
5252
"mypy >= 1.11.2",
5353
"pytest >= 8.3.2",
5454
]
@@ -57,6 +57,11 @@ all = [
5757
line-length = 127
5858
[tool.ruff.lint]
5959
extend-select = [
60+
# pycodestyle import/statement/runtime errors; these were part of ruff's
61+
# default rule set before 0.16 and are kept explicitly here.
62+
"E4",
63+
"E7",
64+
"E9",
6065
"I", # isort
6166
"B", # flake8-bugbear
6267
"SIM", # flake8-simplify
@@ -65,6 +70,10 @@ extend-select = [
6570
"PIE", # flake8-pie
6671
"RET", # flake8-return
6772
"RUF", # ruff-specific
73+
"PTH", # flake8-use-pathlib
74+
"TC", # flake8-type-checking
75+
"FURB", # refurb
76+
"C4", # flake8-comprehensions
6877
]
6978
ignore = [
7079
# An IDN library legitimately handles confusable / ambiguous Unicode;

tests/test_idna.py

100755100644
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
import unittest
42
import warnings
53

tests/test_idna_cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
import io
42
import subprocess
53
import sys

tests/test_idna_codec.py

100755100644
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
import codecs
42
import io
53
import unittest

0 commit comments

Comments
 (0)