Skip to content

Commit 9b3168b

Browse files
committed
Update tooling, type checking and linting
1 parent 929ef8a commit 9b3168b

File tree

6 files changed

+448
-449
lines changed

6 files changed

+448
-449
lines changed

.github/workflows/lint-and-test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
lint-docs:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v5
1414
- name: Set up Python 3.13
1515
uses: actions/setup-python@v5
1616
with:
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525
name: Lint code
2626
steps:
27-
- uses: actions/checkout@v4
27+
- uses: actions/checkout@v5
2828
- name: Set up Python 3.13
2929
uses: actions/setup-python@v5
3030
with:
@@ -38,7 +38,7 @@ jobs:
3838
runs-on: ubuntu-latest
3939
name: Lint type annotations
4040
steps:
41-
- uses: actions/checkout@v4
41+
- uses: actions/checkout@v5
4242
- name: Set up Python 3.13
4343
uses: actions/setup-python@v5
4444
with:
@@ -55,7 +55,7 @@ jobs:
5555
matrix:
5656
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
5757
steps:
58-
- uses: actions/checkout@v4
58+
- uses: actions/checkout@v5
5959
- name: Set up Python ${{ matrix.python-version }}
6060
uses: actions/setup-python@v5
6161
with:
@@ -84,7 +84,7 @@ jobs:
8484
needs:
8585
- test
8686
steps:
87-
- uses: actions/checkout@v4
87+
- uses: actions/checkout@v5
8888
- name: Install Hatch
8989
uses: pypa/hatch@install
9090

@@ -109,5 +109,5 @@ jobs:
109109
name: Build & verify package
110110
runs-on: ubuntu-latest
111111
steps:
112-
- uses: actions/checkout@v4
112+
- uses: actions/checkout@v5
113113
- uses: hynek/build-and-inspect-python-package@v2

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.6.9
3+
rev: v0.12.9
44
hooks:
55
- id: ruff
66
- id: ruff-format
77
- repo: https://github.com/pycqa/doc8
8-
rev: v1.1.2
8+
rev: v2.0.0
99
hooks:
1010
- id: doc8

.ruff_defaults.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ select = [
386386
"S317",
387387
"S318",
388388
"S319",
389-
"S320",
390389
"S321",
391390
"S323",
392391
"S324",
@@ -446,12 +445,12 @@ select = [
446445
"T100",
447446
"T201",
448447
"T203",
449-
"TCH001",
450-
"TCH002",
451-
"TCH003",
452-
"TCH004",
453-
"TCH005",
454-
"TCH010",
448+
"TC001",
449+
"TC002",
450+
"TC003",
451+
"TC004",
452+
"TC005",
453+
"TC010",
455454
"TD004",
456455
"TD005",
457456
"TD006",
@@ -463,9 +462,9 @@ select = [
463462
"TRY003",
464463
"TRY004",
465464
"TRY201",
465+
"TRY203",
466466
"TRY300",
467467
"TRY301",
468-
"TRY302",
469468
"TRY400",
470469
"TRY401",
471470
"UP001",
@@ -502,7 +501,6 @@ select = [
502501
"UP035",
503502
"UP036",
504503
"UP037",
505-
"UP038",
506504
"UP039",
507505
"UP040",
508506
"UP041",

hatch.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ features = [
55
]
66

77
[envs.hatch-static-analysis]
8-
dependencies = ["ruff==0.6.*"]
8+
dependencies = ["ruff==0.12.*"]
99
config-path = ".ruff_defaults.toml"
1010

1111
[envs.hatch-test]
@@ -29,12 +29,12 @@ xml = "coverage xml"
2929

3030
[envs.types]
3131
extra-dependencies = [
32-
"mypy==1.11.*",
32+
"mypy==1.17.*",
3333
]
3434
scripts = { check = "mypy --install-types --non-interactive {args:ulid}" }
3535

3636
[envs.docs]
3737
extra-dependencies = [
38-
"doc8==1.1.*",
38+
"doc8==2.0.*",
3939
]
4040
scripts = { check = "doc8 docs" }

ulid/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from typing import TYPE_CHECKING
1313
from typing import TypeVar
1414

15+
from typing_extensions import Self
16+
1517
from ulid import base32
1618
from ulid import constants
1719

@@ -51,9 +53,6 @@ def wrapped(cls: Any, value: T) -> R:
5153
return wrapped
5254

5355

54-
U = TypeVar("U", bound="ULID")
55-
56-
5756
@functools.total_ordering
5857
class ULID:
5958
"""The :class:`ULID` object consists of a timestamp part of 48 bits and of 80 random bits.
@@ -89,7 +88,7 @@ def __init__(self, value: bytes | None = None) -> None:
8988

9089
@classmethod
9190
@validate_type(datetime)
92-
def from_datetime(cls: type[U], value: datetime) -> U:
91+
def from_datetime(cls, value: datetime) -> Self:
9392
"""Create a new :class:`ULID`-object from a :class:`datetime`. The timestamp part of the
9493
`ULID` will be set to the corresponding timestamp of the datetime.
9594
@@ -103,7 +102,7 @@ def from_datetime(cls: type[U], value: datetime) -> U:
103102

104103
@classmethod
105104
@validate_type(int, float)
106-
def from_timestamp(cls: type[U], value: float) -> U:
105+
def from_timestamp(cls, value: float) -> Self:
107106
"""Create a new :class:`ULID`-object from a timestamp. The timestamp can be either a
108107
`float` representing the time in seconds (as it would be returned by :func:`time.time()`)
109108
or an `int` in milliseconds.
@@ -122,7 +121,7 @@ def from_timestamp(cls: type[U], value: float) -> U:
122121

123122
@classmethod
124123
@validate_type(uuid.UUID)
125-
def from_uuid(cls: type[U], value: uuid.UUID) -> U:
124+
def from_uuid(cls, value: uuid.UUID) -> Self:
126125
"""Create a new :class:`ULID`-object from a :class:`uuid.UUID`. The timestamp part will be
127126
random in that case.
128127
@@ -136,37 +135,37 @@ def from_uuid(cls: type[U], value: uuid.UUID) -> U:
136135

137136
@classmethod
138137
@validate_type(bytes)
139-
def from_bytes(cls: type[U], bytes_: bytes) -> U:
138+
def from_bytes(cls, bytes_: bytes) -> Self:
140139
"""Create a new :class:`ULID`-object from sequence of 16 bytes."""
141140
return cls(bytes_)
142141

143142
@classmethod
144143
@validate_type(str)
145-
def from_hex(cls: type[U], value: str) -> U:
144+
def from_hex(cls, value: str) -> Self:
146145
"""Create a new :class:`ULID`-object from 32 character string of hex values."""
147146
return cls.from_bytes(bytes.fromhex(value))
148147

149148
@classmethod
150149
@validate_type(str)
151-
def from_str(cls: type[U], string: str) -> U:
150+
def from_str(cls, string: str) -> Self:
152151
"""Create a new :class:`ULID`-object from a 26 char long string representation."""
153152
return cls(base32.decode(string))
154153

155154
@classmethod
156155
@validate_type(int)
157-
def from_int(cls: type[U], value: int) -> U:
156+
def from_int(cls, value: int) -> Self:
158157
"""Create a new :class:`ULID`-object from an `int`."""
159158
return cls(int.to_bytes(value, constants.BYTES_LEN, "big"))
160159

161160
@classmethod
162-
def parse(cls: type[U], value: Any) -> U:
161+
def parse(cls, value: Any) -> Self:
163162
"""Create a new :class:`ULID`-object from a given value.
164163
165164
.. note:: This method should only be used when the caller is trying to parse a ULID from
166165
a value when they're unsure what format/primitive type it will be given in.
167166
"""
168167
if isinstance(value, ULID):
169-
return cast(U, value)
168+
return cast(Self, value)
170169
if isinstance(value, uuid.UUID):
171170
return cls.from_uuid(value)
172171
if isinstance(value, str):
@@ -309,6 +308,7 @@ def __get_pydantic_core_schema__(cls, source: Any, handler: GetCoreSchemaHandler
309308
def _pydantic_validate(cls, value: Any, handler: ValidatorFunctionWrapHandler) -> Any:
310309
from pydantic_core import PydanticCustomError
311310

311+
ulid: ULID
312312
try:
313313
if isinstance(value, int):
314314
ulid = cls.from_int(value)

0 commit comments

Comments
 (0)