Skip to content

Commit 2308656

Browse files
authored
Update to Python 3.11+ syntax (#299)
* nitypes: Run pyupgrade --py311-plus * nitypes: Remove _exceptions.add_note() * nitypes: Remove Python 3.9 array type checks * chore: Reformat code and remove unused imports
1 parent 2aaf8b7 commit 2308656

41 files changed

Lines changed: 97 additions & 152 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/nitypes/_exceptions.py‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
11
from __future__ import annotations
22

33
import reprlib
4-
import sys
54

65
import numpy as np
76
import numpy.typing as npt
87

98

10-
def add_note(exception: Exception, note: str) -> None:
11-
"""Add a note to an exception.
12-
13-
>>> try:
14-
... raise ValueError("Oh no")
15-
... except Exception as e:
16-
... add_note(e, "p.s. This is bad")
17-
... raise
18-
Traceback (most recent call last):
19-
...
20-
ValueError: Oh no
21-
p.s. This is bad
22-
"""
23-
if sys.version_info >= (3, 11):
24-
exception.add_note(note)
25-
else:
26-
message = exception.args[0] + "\n" + note
27-
exception.args = (message,) + exception.args[1:]
28-
29-
309
def invalid_arg_value(
3110
arg_description: str, valid_value_description: str, value: object
3211
) -> ValueError:

‎src/nitypes/bintime/_datetime.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
import datetime as dt
44
from functools import singledispatchmethod
55
from typing import (
6-
TYPE_CHECKING,
76
Any,
8-
ClassVar,
9-
SupportsIndex,
10-
Union,
117
cast,
8+
ClassVar,
129
final,
1310
overload,
11+
Self,
12+
SupportsIndex,
13+
TYPE_CHECKING,
14+
TypeAlias,
15+
Union,
1416
)
1517

1618
import hightime as ht
17-
from typing_extensions import Self, TypeAlias
1819

1920
from nitypes._exceptions import invalid_arg_type, invalid_arg_value
2021
from nitypes.bintime._timedelta import _OTHER_TIMEDELTA_TUPLE, _OtherTimeDelta

‎src/nitypes/bintime/_dtypes.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

3+
from typing import TypeAlias
4+
35
import numpy as np
4-
from typing_extensions import TypeAlias
56

67
CVIAbsoluteTimeBase: TypeAlias = np.void
78
"""Type alias for the base type of :any:`CVIAbsoluteTimeDType`, which is :any:`numpy.void`."""

‎src/nitypes/bintime/_timedelta.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@
66
import operator
77
from decimal import Decimal
88
from functools import singledispatchmethod
9-
from typing import TYPE_CHECKING, Any, ClassVar, SupportsIndex, Union, final, overload
9+
from typing import (
10+
Any,
11+
ClassVar,
12+
final,
13+
overload,
14+
Self,
15+
SupportsIndex,
16+
TYPE_CHECKING,
17+
TypeAlias,
18+
Union,
19+
)
1020

1121
import hightime as ht
12-
from typing_extensions import Self, TypeAlias
1322

1423
from nitypes._arguments import arg_to_int
1524
from nitypes._exceptions import int_out_of_range, invalid_arg_type

‎src/nitypes/complex/_dtypes.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

3+
from typing import TypeAlias
4+
35
import numpy as np
4-
from typing_extensions import TypeAlias
56

67
ComplexInt32Base: TypeAlias = np.void
78
"""Type alias for the base type of :any:`ComplexInt32DType`, which is :any:`numpy.void`."""

‎src/nitypes/scalar.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from __future__ import annotations
1111

1212
from collections.abc import Mapping
13-
from typing import TYPE_CHECKING, Any, Generic, Union
13+
from typing import Any, final, Generic, Self, TYPE_CHECKING, Union
1414

15-
from typing_extensions import Self, TypeVar, final
15+
from typing_extensions import TypeVar
1616

1717
from nitypes._exceptions import invalid_arg_type
1818
from nitypes.waveform._extended_properties import UNIT_DESCRIPTION

‎src/nitypes/time/typing.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
from __future__ import annotations
44

55
import datetime as dt
6-
from typing import TypeVar, Union
6+
from typing import TypeAlias, TypeVar, Union
77

88
import hightime as ht
9-
from typing_extensions import TypeAlias
109

1110
import nitypes.bintime as bt
1211

‎src/nitypes/vector.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from __future__ import annotations
1010

1111
from collections.abc import Iterable, Mapping, MutableSequence, Sequence
12-
from typing import TYPE_CHECKING, Any, Union, overload
12+
from typing import Any, final, overload, Self, TYPE_CHECKING, Union
1313

14-
from typing_extensions import Self, TypeVar, final, override
14+
from typing_extensions import override, TypeVar
1515

1616
from nitypes._exceptions import invalid_arg_type
1717
from nitypes.waveform._extended_properties import UNIT_DESCRIPTION

‎src/nitypes/waveform/_analog.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
from collections.abc import Mapping, Sequence
4-
from typing import Any, SupportsIndex, Union, overload
4+
from typing import Any, final, overload, SupportsIndex, TYPE_CHECKING, Union
55

66
import numpy as np
77
import numpy.typing as npt
8-
from typing_extensions import TYPE_CHECKING, TypeVar, final, override
8+
from typing_extensions import override, TypeVar
99

1010
from nitypes._numpy import long as _np_long, ulong as _np_ulong
1111
from nitypes.time.typing import AnyDateTime, AnyTimeDelta

‎src/nitypes/waveform/_complex.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
from collections.abc import Mapping, Sequence
4-
from typing import Any, SupportsIndex, Union, overload
4+
from typing import Any, final, overload, SupportsIndex, TYPE_CHECKING, Union
55

66
import numpy as np
77
import numpy.typing as npt
8-
from typing_extensions import TYPE_CHECKING, TypeVar, final, override
8+
from typing_extensions import override, TypeVar
99

1010
from nitypes.complex import ComplexInt32Base, ComplexInt32DType, convert_complex
1111
from nitypes.time.typing import AnyDateTime, AnyTimeDelta

0 commit comments

Comments
 (0)