Skip to content

Commit 918d29f

Browse files
committed
Modernise type hints
1 parent 636e661 commit 918d29f

4 files changed

Lines changed: 9 additions & 14 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@ source = 'https://github.com/mdickinson/simplefractions'
2424
strict = true
2525

2626
[tool.ruff.lint]
27-
extend-select = ["I"]
28-
29-
[tool.setuptools_scm]
30-
version_scheme = 'release-branch-semver'
27+
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)