Skip to content

Commit 4f580f8

Browse files
authored
Update type hints (#41)
This PR updates type hints to more recent (but still Python 3.10-compatible) syntax. Also adds the `pyupgrade` checks to the ruff linter.
1 parent fe6546d commit 4f580f8

4 files changed

Lines changed: 9 additions & 11 deletions

File tree

proofs/fraction_to_float.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import typing
21
from math import gcd
32

43

5-
def find_cd(a: int, b: int) -> typing.List[typing.Tuple[int, int]]:
4+
def find_cd(a: int, b: int) -> list[tuple[int, int]]:
65
"""
76
Given a positive fraction a/b (expressed in lowest terms), find both
87
fractions c/d which are simpler than a/b and which satisfy |ad - bc| = 1.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ addopts = ["--pyargs", "--import-mode=importlib"]
4343
target-version = "py310"
4444

4545
[tool.ruff.lint]
46-
extend-select = ["I", "W"] # isort, pycodestyle warnings
46+
extend-select = ["I", "UP", "W"] # isort, pyupgrade, pycodestyle warnings

src/simplefractions/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848

4949
#: Type that roughly matches "number acceptable by the fractions.Fraction
5050
#: constructor"
51-
FractionCompatible = typing.Union[int, float, decimal.Decimal, numbers.Rational]
51+
FractionCompatible: typing.TypeAlias = int | float | decimal.Decimal | numbers.Rational
5252

5353

5454
def simplest_in_interval(
55-
left: typing.Optional[FractionCompatible] = None,
56-
right: typing.Optional[FractionCompatible] = None,
55+
left: FractionCompatible | None = None,
56+
right: FractionCompatible | None = None,
5757
*,
5858
include_left: bool = False,
5959
include_right: bool = False,
@@ -111,7 +111,7 @@ def simplest_in_interval(
111111

112112
def _interval_rounding_to(
113113
x: float,
114-
) -> typing.Tuple[fractions.Fraction, fractions.Fraction, bool]:
114+
) -> tuple[fractions.Fraction, fractions.Fraction, bool]:
115115
"""
116116
Return the interval of numbers that round to a given float.
117117

src/simplefractions/_simplest_in_interval.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@
105105
"""
106106

107107
import fractions
108-
import typing
109108

110109

111110
def _simplest_in_interval_pos(
112111
r: int, s: int, t: bool, u: int, v: int, w: bool
113-
) -> typing.Tuple[int, int]:
112+
) -> tuple[int, int]:
114113
"""
115114
Simplest fraction in a subinterval of the positive reals.
116115
@@ -147,8 +146,8 @@ def _simplest_in_interval_pos(
147146

148147

149148
def _simplest_in_interval(
150-
left: typing.Optional[fractions.Fraction] = None,
151-
right: typing.Optional[fractions.Fraction] = None,
149+
left: fractions.Fraction | None = None,
150+
right: fractions.Fraction | None = None,
152151
*,
153152
include_left: bool = False,
154153
include_right: bool = False,

0 commit comments

Comments
 (0)