Skip to content

Commit 090b844

Browse files
ArmavicaricardoV94
authored andcommitted
Drop Python 3.9 and apply safe Ruff fixes
1 parent 378cb40 commit 090b844

Some content is hidden

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

73 files changed

+495
-533
lines changed

doc/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- python=3.9
6+
- python=3.10
77
- gcc_linux-64
88
- gxx_linux-64
99
- numpy

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: pytensor-dev
77
channels:
88
- conda-forge
99
dependencies:
10-
- python
10+
- python>=3.10
1111
- compilers
1212
- numpy>=1.17.0
1313
- scipy>=0.14

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
1010
[project]
1111
name = "pytensor"
1212
dynamic = ['version']
13-
requires-python = ">=3.9,<3.13"
13+
requires-python = ">=3.10,<3.13"
1414
authors = [{ name = "pymc-devs", email = "[email protected]" }]
1515
description = "Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs."
1616
readme = "README.rst"
@@ -30,7 +30,6 @@ classifiers = [
3030
"Operating System :: Unix",
3131
"Operating System :: MacOS",
3232
"Programming Language :: Python :: 3",
33-
"Programming Language :: Python :: 3.9",
3433
"Programming Language :: Python :: 3.10",
3534
"Programming Language :: Python :: 3.11",
3635
"Programming Language :: Python :: 3.12",
@@ -154,7 +153,7 @@ lines-after-imports = 2
154153

155154

156155
[tool.mypy]
157-
python_version = "3.9"
156+
python_version = "3.10"
158157
ignore_missing_imports = true
159158
no_implicit_optional = true
160159
check_untyped_defs = false

pytensor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def disable_log_handler(logger=pytensor_logger, handler=logging_default_handler)
7676
# isort: on
7777

7878

79-
def as_symbolic(x: Any, name: Optional[str] = None, **kwargs) -> Variable:
79+
def as_symbolic(x: Any, name: str | None = None, **kwargs) -> Variable:
8080
"""Convert `x` into an equivalent PyTensor `Variable`.
8181
8282
Parameters

pytensor/compile/builders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections.abc import Sequence
55
from copy import copy
66
from functools import partial
7-
from typing import Optional, cast
7+
from typing import cast
88

99
import pytensor.tensor as pt
1010
from pytensor import function
@@ -304,9 +304,9 @@ def __init__(
304304
lop_overrides: str = "default",
305305
grad_overrides: str = "default",
306306
rop_overrides: str = "default",
307-
connection_pattern: Optional[list[list[bool]]] = None,
307+
connection_pattern: list[list[bool]] | None = None,
308308
strict: bool = False,
309-
name: Optional[str] = None,
309+
name: str | None = None,
310310
**kwargs,
311311
):
312312
"""

pytensor/compile/compilelock.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import threading
88
from contextlib import contextmanager
9-
from typing import Optional, Union
109

1110
import filelock
1211

@@ -47,9 +46,9 @@ def force_unlock(lock_dir: os.PathLike):
4746

4847
@contextmanager
4948
def lock_ctx(
50-
lock_dir: Optional[Union[str, os.PathLike]] = None,
49+
lock_dir: str | os.PathLike | None = None,
5150
*,
52-
timeout: Optional[float] = None,
51+
timeout: float | None = None,
5352
):
5453
"""Context manager that wraps around FileLock and SoftFileLock from filelock package.
5554

pytensor/compile/debugmode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from itertools import chain
1414
from itertools import product as itertools_product
1515
from logging import Logger
16-
from typing import Optional
1716
from warnings import warn
1817

1918
import numpy as np
@@ -1354,7 +1353,7 @@ def __init__(self, maker, schedule=None):
13541353
self.maker = maker
13551354
super().__init__(scheduler=schedule)
13561355

1357-
def accept(self, fgraph, no_recycling: Optional[list] = None, profile=None):
1356+
def accept(self, fgraph, no_recycling: list | None = None, profile=None):
13581357
if no_recycling is None:
13591358
no_recycling = []
13601359
if self.fgraph is not None and self.fgraph is not fgraph:

pytensor/compile/function/pfunc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from collections.abc import Sequence
77
from copy import copy
8-
from typing import Optional, Union, overload
8+
from typing import overload
99

1010
from pytensor.compile.function.types import Function, UnusedInputError, orig_function
1111
from pytensor.compile.io import In, Out
@@ -105,7 +105,7 @@ def rebuild_collect_shared(
105105

106106

107107
def rebuild_collect_shared(
108-
outputs: Union[Sequence[Variable], Variable, Out, Sequence[Out]],
108+
outputs: Sequence[Variable] | Variable | Out | Sequence[Out],
109109
inputs=None,
110110
replace=None,
111111
updates=None,
@@ -115,7 +115,7 @@ def rebuild_collect_shared(
115115
clone_inner_graphs=False,
116116
) -> tuple[
117117
list[Variable],
118-
Union[list[Variable], Variable, Out, list[Out]],
118+
list[Variable] | Variable | Out | list[Out],
119119
tuple[
120120
dict[Variable, Variable],
121121
dict[SharedVariable, Variable],
@@ -376,7 +376,7 @@ def pfunc(
376376
profile=None,
377377
on_unused_input=None,
378378
output_keys=None,
379-
fgraph: Optional[FunctionGraph] = None,
379+
fgraph: FunctionGraph | None = None,
380380
) -> Function:
381381
"""
382382
Function-constructor for graphs with shared variables.
@@ -484,7 +484,7 @@ def construct_pfunc_ins_and_outs(
484484
no_default_updates=False,
485485
rebuild_strict=True,
486486
allow_input_downcast=None,
487-
fgraph: Optional[FunctionGraph] = None,
487+
fgraph: FunctionGraph | None = None,
488488
):
489489
"""Construct inputs and outputs for `pfunc`.
490490

pytensor/compile/function/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
import warnings
88
from itertools import chain
9-
from typing import TYPE_CHECKING, Optional
9+
from typing import TYPE_CHECKING
1010

1111
import numpy as np
1212

@@ -173,7 +173,7 @@ def std_fgraph(
173173
input_specs: list[SymbolicInput],
174174
output_specs: list[SymbolicOutput],
175175
accept_inplace: bool = False,
176-
fgraph: Optional[FunctionGraph] = None,
176+
fgraph: FunctionGraph | None = None,
177177
features: list[type[Feature]] = [PreserveVariableAttributes],
178178
force_clone=False,
179179
) -> tuple[FunctionGraph, list[SymbolicOutput]]:
@@ -340,7 +340,7 @@ def __init__(
340340
return_none: bool,
341341
output_keys,
342342
maker: "FunctionMaker",
343-
name: Optional[str] = None,
343+
name: str | None = None,
344344
):
345345
"""
346346
Parameters
@@ -1693,7 +1693,7 @@ def orig_function(
16931693
profile=None,
16941694
on_unused_input=None,
16951695
output_keys=None,
1696-
fgraph: Optional[FunctionGraph] = None,
1696+
fgraph: FunctionGraph | None = None,
16971697
) -> Function:
16981698
"""
16991699
Return a Function that will calculate the outputs from the inputs.

pytensor/compile/mode.py

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

66
import logging
77
import warnings
8-
from typing import Literal, Optional, Union
8+
from typing import Literal
99

1010
from pytensor.compile.function.types import Supervisor
1111
from pytensor.configdefaults import config
@@ -260,7 +260,7 @@ def apply(self, fgraph):
260260
# final pass just to make sure
261261
optdb.register("merge3", MergeOptimizer(), "fast_run", "merge", position=100)
262262

263-
_tags: Union[tuple[str, str], tuple]
263+
_tags: tuple[str, str] | tuple
264264

265265
if config.check_stack_trace in ("raise", "warn", "log"):
266266
_tags = ("fast_run", "fast_compile")
@@ -297,8 +297,8 @@ class Mode:
297297

298298
def __init__(
299299
self,
300-
linker: Optional[Union[str, Linker]] = None,
301-
optimizer: Union[str, RewriteDatabaseQuery] = "default",
300+
linker: str | Linker | None = None,
301+
optimizer: str | RewriteDatabaseQuery = "default",
302302
db: RewriteDatabase = None,
303303
):
304304
if linker is None:

pytensor/compile/profiling.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import time
1717
from collections import defaultdict
1818
from contextlib import contextmanager
19-
from typing import TYPE_CHECKING, Any, Optional, Union
19+
from typing import TYPE_CHECKING, Any, Union
2020

2121
import numpy as np
2222

@@ -234,15 +234,15 @@ def reset(self):
234234
# Total time spent in Function.vm.__call__
235235
#
236236

237-
apply_time: Optional[dict[Union["FunctionGraph", Variable], float]] = None
237+
apply_time: dict[Union["FunctionGraph", Variable], float] | None = None
238238

239-
apply_callcount: Optional[dict[Union["FunctionGraph", Variable], int]] = None
239+
apply_callcount: dict[Union["FunctionGraph", Variable], int] | None = None
240240

241-
apply_cimpl: Optional[dict[Apply, bool]] = None
241+
apply_cimpl: dict[Apply, bool] | None = None
242242
# dict from node -> bool (1 if c, 0 if py)
243243
#
244244

245-
message: Optional[str] = None
245+
message: str | None = None
246246
# pretty string to print in summary, to identify this output
247247
#
248248

pytensor/compile/sharedvalue.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import copy
44
from contextlib import contextmanager
55
from functools import singledispatch
6-
from typing import TYPE_CHECKING, Optional
6+
from typing import TYPE_CHECKING
77

88
from pytensor.graph.basic import Variable
99
from pytensor.graph.utils import add_tag_trace
@@ -15,7 +15,7 @@
1515
from pytensor.graph.type import Type
1616

1717

18-
__SHARED_CONTEXT__: Optional[list[Variable]] = None
18+
__SHARED_CONTEXT__: list[Variable] | None = None
1919

2020

2121
@contextmanager
@@ -40,8 +40,8 @@ def __init__(
4040
value,
4141
strict: bool,
4242
allow_downcast=None,
43-
container: Optional[Container] = None,
44-
name: Optional[str] = None,
43+
container: Container | None = None,
44+
name: str | None = None,
4545
):
4646
r"""
4747
Parameters
@@ -90,7 +90,7 @@ def __init__(
9090
if isinstance(__SHARED_CONTEXT__, list):
9191
__SHARED_CONTEXT__.append(self)
9292

93-
self._default_update: Optional[Variable] = None
93+
self._default_update: Variable | None = None
9494

9595
def get_value(self, borrow=False, return_internal_type=False):
9696
"""
@@ -149,7 +149,7 @@ def clone(self, **kwargs):
149149
return cp
150150

151151
@property
152-
def default_update(self) -> Optional[Variable]:
152+
def default_update(self) -> Variable | None:
153153
"""A default update expression for this `Variable`.
154154
155155
If this value is non-``None``, its value will be used as the `update`

pytensor/configparser.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import shlex
44
import sys
55
import warnings
6-
from collections.abc import Sequence
6+
from collections.abc import Callable, Sequence
77
from configparser import (
88
ConfigParser,
99
InterpolationError,
@@ -13,7 +13,6 @@
1313
)
1414
from functools import wraps
1515
from io import StringIO
16-
from typing import Callable, Optional, Union
1716

1817
from pytensor.utils import hash_from_code
1918

@@ -232,10 +231,10 @@ class ConfigParam:
232231

233232
def __init__(
234233
self,
235-
default: Union[object, Callable[[object], object]],
234+
default: object | Callable[[object], object],
236235
*,
237-
apply: Optional[Callable[[object], object]] = None,
238-
validate: Optional[Callable[[object], bool]] = None,
236+
apply: Callable[[object], object] | None = None,
237+
validate: Callable[[object], bool] | None = None,
239238
mutable: bool = True,
240239
):
241240
"""
@@ -289,7 +288,7 @@ def apply(self, value):
289288
return self._apply(value)
290289
return value
291290

292-
def validate(self, value) -> Optional[bool]:
291+
def validate(self, value) -> bool | None:
293292
"""Validates that a parameter values falls into a supported set or range.
294293
295294
Raises

0 commit comments

Comments
 (0)