Skip to content

Commit 27d385d

Browse files
committed
Upgrade syntax
1 parent 65fb491 commit 27d385d

File tree

5 files changed

+19
-25
lines changed

5 files changed

+19
-25
lines changed

src/gotranx/atoms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class State(Atom):
126126

127127
value: float | sp.core.Number = attr.ib()
128128

129-
def to_TimeDependentState(self, t: sp.Symbol) -> "TimeDependentState":
129+
def to_TimeDependentState(self, t: sp.Symbol) -> TimeDependentState:
130130
return TimeDependentState(
131131
name=self.name,
132132
value=self.value,
@@ -288,7 +288,7 @@ def singularities(self, lookup: dict[str, Atom]) -> frozenset[Singularity]:
288288
)
289289
return frozenset(singularity_list)
290290

291-
def remove_singularities(self, lookup: dict[str, Atom]) -> "Assignment":
291+
def remove_singularities(self, lookup: dict[str, Atom]) -> Assignment:
292292
"""Remove singularities from the assignment
293293
294294
Parameters
@@ -354,7 +354,7 @@ def resolve_expression(self, symbols: dict[str, sp.Symbol]) -> Assignment:
354354
comment=self.comment,
355355
)
356356

357-
def to_intermediate(self) -> "Intermediate":
357+
def to_intermediate(self) -> Intermediate:
358358
"""Convert the Assignment to an Intermediate"""
359359
return Intermediate(
360360
name=self.name,
@@ -368,7 +368,7 @@ def to_intermediate(self) -> "Intermediate":
368368
comment=self.comment,
369369
)
370370

371-
def to_state_derivative(self, state: State) -> "StateDerivative":
371+
def to_state_derivative(self, state: State) -> StateDerivative:
372372
"""Convert the Assignment to a StateDerivative
373373
374374
Parameters
@@ -389,7 +389,7 @@ def to_state_derivative(self, state: State) -> "StateDerivative":
389389
comment=self.comment,
390390
)
391391

392-
def simplify(self) -> "Assignment":
392+
def simplify(self) -> Assignment:
393393
"""Simplify the expression of the assignment using sympy's
394394
simplify function. This function returns a new Assignment
395395
object with the simplified expression.

src/gotranx/cli/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
from pathlib import Path
33
import warnings
44

5-
try:
6-
from typing import Annotated
7-
except ImportError:
8-
from typing_extensions import Annotated # type: ignore
95

106
import typer
117

@@ -106,11 +102,11 @@ def convert(
106102
"-v",
107103
help="Verbose output",
108104
),
109-
scheme: Annotated[
105+
scheme: typing.Annotated[
110106
typing.Optional[typing.List[Scheme]],
111107
typer.Option(help="Numerical scheme for solving the ODE"),
112108
] = None,
113-
stiff_states: Annotated[
109+
stiff_states: typing.Annotated[
114110
typing.Optional[typing.List[str]],
115111
typer.Option("-s", "--stiff-states", help="Stiff states for the hybrid rush larsen scheme"),
116112
] = None,
@@ -266,11 +262,11 @@ def ode2py(
266262
"-v",
267263
help="Verbose output",
268264
),
269-
scheme: Annotated[
265+
scheme: typing.Annotated[
270266
typing.List[Scheme],
271267
typer.Option(help="Numerical scheme for solving the ODE"),
272268
] = [],
273-
stiff_states: Annotated[
269+
stiff_states: typing.Annotated[
274270
typing.List[str],
275271
typer.Option("-s", "--stiff-states", help="Stiff states for the hybrid rush larsen scheme"),
276272
] = [],
@@ -370,11 +366,11 @@ def ode2c(
370366
"-v",
371367
help="Verbose output",
372368
),
373-
scheme: Annotated[
369+
scheme: typing.Annotated[
374370
typing.List[Scheme],
375371
typer.Option(help="Numerical scheme for solving the ODE"),
376372
] = [],
377-
stiff_states: Annotated[
373+
stiff_states: typing.Annotated[
378374
typing.List[str],
379375
typer.Option("-s", "--stiff-states", help="Stiff states for the hybrid rush larsen scheme"),
380376
] = [],

src/gotranx/ode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from functools import cached_property
55
from pathlib import Path
66
from graphlib import TopologicalSorter
7-
from typing import Iterable
8-
from typing import Sequence
7+
from collections.abc import Iterable
8+
from collections.abc import Sequence
99
from typing import TypeVar
1010
from typing import cast
1111
from typing import Any

src/gotranx/parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ def load_grammar() -> str:
1414
str
1515
The grammar
1616
"""
17-
with open(_here / "ode.lark", "r") as f:
18-
text = f.read()
19-
return text
17+
18+
return (_here / "ode.lark").read_text()
2019

2120

2221
class Parser(Lark):

src/gotranx/transformer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from collections import defaultdict
44
from typing import NamedTuple
5-
from typing import Type
65
from typing import TypeVar
76

87
import lark
@@ -144,15 +143,15 @@ def find_components(
144143

145144
def lark_list_to_parameters(
146145
s: list[None | lark.tree.Tree | lark.lexer.Token],
147-
cls: Type[T],
146+
cls: type[T],
148147
) -> tuple[T, ...]:
149148
"""Convert a list of lark trees to parameters
150149
151150
Parameters
152151
----------
153152
s : list[None | lark.tree.Tree | lark.lexer.Token]
154153
The list
155-
cls : Type[T]
154+
cls : type[T]
156155
The class of the parameters
157156
158157
Returns
@@ -173,7 +172,7 @@ def lark_list_to_parameters(
173172
def tree2parameter(
174173
s: lark.Tree,
175174
components: tuple[str, ...],
176-
cls: Type[T],
175+
cls: type[T],
177176
) -> T:
178177
"""Convert a lark tree to a parameter
179178
@@ -183,7 +182,7 @@ def tree2parameter(
183182
The tree
184183
components : tuple[str, ...]
185184
The components
186-
cls : Type[T]
185+
cls : type[T]
187186
The class of the parameter
188187
189188
Returns

0 commit comments

Comments
 (0)