Skip to content

Commit 2049322

Browse files
committed
synctatic auto-upgrades (Python 3.9->3.10) TODO: add to .git-blame-ignore-revs
1 parent b067988 commit 2049322

File tree

91 files changed

+217
-509
lines changed

Some content is hidden

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

91 files changed

+217
-509
lines changed

yt/_maintenance/backports.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,3 @@ def _generate_next_value_(name, start, count, last_values): # noqa B902
6363
Return the lower-cased version of the member name.
6464
"""
6565
return name.lower()
66-
67-
68-
builtin_zip = zip
69-
if sys.version_info >= (3, 10):
70-
zip = builtin_zip
71-
else:
72-
# this function is deprecated in more_itertools
73-
# because it is superseded by the standard library
74-
from more_itertools import zip_equal
75-
76-
def zip(*args, strict=False):
77-
if strict:
78-
return zip_equal(*args)
79-
else:
80-
return builtin_zip(*args)

yt/_maintenance/deprecation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import warnings
22
from functools import wraps
33
from types import FunctionType
4-
from typing import Optional
54

65

76
def issue_deprecation_warning(
87
msg: str,
98
*,
109
stacklevel: int,
1110
since: str,
12-
removal: Optional[str] = None,
11+
removal: str | None = None,
1312
):
1413
"""
1514
Parameters

yt/_typing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
from typing import Any, Optional, Union
1+
from typing import Any, Optional
22

33
import numpy as np
44
import unyt as un
55

6-
FieldDescT = tuple[str, tuple[str, list[str], Optional[str]]]
6+
FieldDescT = tuple[str, tuple[str, list[str], str | None]]
77
KnownFieldsT = tuple[FieldDescT, ...]
88

99
ParticleType = str
1010
FieldType = str
1111
FieldName = str
1212
FieldKey = tuple[FieldType, FieldName]
1313
ImplicitFieldKey = FieldName
14-
AnyFieldKey = Union[FieldKey, ImplicitFieldKey]
15-
DomainDimensions = Union[tuple[int, ...], list[int], np.ndarray]
14+
AnyFieldKey = FieldKey | ImplicitFieldKey
15+
DomainDimensions = tuple[int, ...] | list[int] | np.ndarray
1616

1717
ParticleCoordinateTuple = tuple[
1818
str, # particle type
1919
tuple[np.ndarray, np.ndarray, np.ndarray], # xyz
20-
Union[float, np.ndarray], # hsml
20+
float | np.ndarray, # hsml
2121
]
2222

2323
# Geometry specific types
2424
AxisName = str
2525
AxisOrder = tuple[AxisName, AxisName, AxisName]
2626

2727
# types that can be converted to un.Unit
28-
Unit = Union[un.Unit, str]
28+
Unit = un.Unit | str
2929

3030
# types that can be converted to un.unyt_quantity
31-
Quantity = Union[un.unyt_quantity, tuple[float, Unit]]
31+
Quantity = un.unyt_quantity | tuple[float, Unit]
3232

3333
# np.ndarray[...] syntax is runtime-valid from numpy 1.22, we quote it until our minimal
3434
# runtime requirement is bumped to, or beyond this version

yt/data_objects/analyzer_objects.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import inspect
2-
import sys
32

43
from yt.utilities.object_registries import analysis_task_registry
54

6-
if sys.version_info < (3, 10):
7-
from yt._maintenance.backports import zip
8-
95

106
class AnalysisTask:
117
def __init_subclass__(cls, *args, **kwargs):

yt/data_objects/construction_data_containers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fileinput
22
import io
33
import os
4-
import sys
54
import warnings
65
import zipfile
76
from functools import partial, wraps
@@ -64,9 +63,6 @@
6463
)
6564
from yt.visualization.color_maps import get_colormap_lut
6665

67-
if sys.version_info < (3, 10):
68-
from yt._maintenance.backports import zip
69-
7066

7167
class YTStreamline(YTSelectionContainer1D):
7268
"""

yt/data_objects/data_containers.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import abc
2-
import sys
32
import weakref
43
from collections import defaultdict
54
from contextlib import contextmanager
@@ -29,9 +28,6 @@
2928
from yt.utilities.on_demand_imports import _firefly as firefly
3029
from yt.utilities.parameter_file_storage import ParameterFileStore
3130

32-
if sys.version_info < (3, 10):
33-
from yt._maintenance.backports import zip
34-
3531
if TYPE_CHECKING:
3632
from yt.data_objects.static_output import Dataset
3733

yt/data_objects/derived_quantities.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import numpy as np
42

53
from yt.funcs import camelcase_to_underscore, iter_fields
@@ -13,9 +11,6 @@
1311
from yt.utilities.physical_constants import gravitational_constant_cgs
1412
from yt.utilities.physical_ratios import HUGE
1513

16-
if sys.version_info < (3, 10):
17-
from yt._maintenance.backports import zip
18-
1914

2015
def get_position_fields(field, data):
2116
axis_names = [data.ds.coordinates.axis_name[num] for num in [0, 1, 2]]

yt/data_objects/level_sets/tests/test_clump_finding.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import shutil
3-
import sys
43
import tempfile
54

65
import numpy as np
@@ -13,9 +12,6 @@
1312
from yt.testing import requires_file, requires_module
1413
from yt.utilities.answer_testing.framework import data_dir_load
1514

16-
if sys.version_info < (3, 10):
17-
from yt._maintenance.backports import zip
18-
1915

2016
def test_clump_finding():
2117
n_c = 8

yt/data_objects/profiles.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import numpy as np
42
from more_itertools import collapse
53

@@ -25,9 +23,6 @@
2523
parallel_objects,
2624
)
2725

28-
if sys.version_info < (3, 10):
29-
from yt._maintenance.backports import zip
30-
3126

3227
def _sanitize_min_max_units(amin, amax, finfo, registry):
3328
# returns a copy of amin and amax, converted to finfo's output units

yt/data_objects/static_output.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from functools import cached_property
1414
from importlib.util import find_spec
1515
from stat import ST_CTIME
16-
from typing import Any, Literal, Optional, Union
16+
from typing import Any, Literal, Optional
1717

1818
import numpy as np
1919
import unyt as un
@@ -86,15 +86,13 @@
8686
# to here, and then have it instantiate EnzoDatasets as appropriate.
8787

8888

89-
_cached_datasets: MutableMapping[Union[int, str], "Dataset"] = (
90-
weakref.WeakValueDictionary()
91-
)
89+
_cached_datasets: MutableMapping[int | str, "Dataset"] = weakref.WeakValueDictionary()
9290

9391
# we set this global to None as a place holder
9492
# its actual instantiation is delayed until after yt.__init__
9593
# is completed because we need yt.config.ytcfg to be instantiated first
9694

97-
_ds_store: Optional[ParameterFileStore] = None
95+
_ds_store: ParameterFileStore | None = None
9896

9997

10098
def _setup_ds_store(ytcfg: YTConfig) -> None:
@@ -161,24 +159,24 @@ class Dataset(abc.ABC):
161159
default_field = ("gas", "density")
162160
fluid_types: tuple[FieldType, ...] = ("gas", "deposit", "index")
163161
particle_types: tuple[ParticleType, ...] = ("io",) # By default we have an 'all'
164-
particle_types_raw: Optional[tuple[ParticleType, ...]] = ("io",)
162+
particle_types_raw: tuple[ParticleType, ...] | None = ("io",)
165163
geometry: Geometry = Geometry.CARTESIAN
166164
coordinates = None
167165
storage_filename = None
168-
particle_unions: Optional[dict[ParticleType, ParticleUnion]] = None
169-
known_filters: Optional[dict[ParticleType, ParticleFilter]] = None
166+
particle_unions: dict[ParticleType, ParticleUnion] | None = None
167+
known_filters: dict[ParticleType, ParticleFilter] | None = None
170168
_index_class: type[Index]
171-
field_units: Optional[dict[AnyFieldKey, Unit]] = None
169+
field_units: dict[AnyFieldKey, Unit] | None = None
172170
derived_field_list = requires_index("derived_field_list")
173171
fields = requires_index("fields")
174-
conversion_factors: Optional[dict[str, float]] = None
172+
conversion_factors: dict[str, float] | None = None
175173
# _instantiated represents an instantiation time (since Epoch)
176174
# the default is a place holder sentinel, falsy value
177175
_instantiated: float = 0
178176
_particle_type_counts = None
179177
_proj_type = "quad_proj"
180178
_ionization_label_format = "roman_numeral"
181-
_determined_fields: Optional[dict[str, list[FieldKey]]] = None
179+
_determined_fields: dict[str, list[FieldKey]] | None = None
182180
fields_detected = False
183181

184182
# these are set in self._parse_parameter_file()
@@ -233,8 +231,8 @@ def __init_subclass__(cls, *args, **kwargs):
233231
def __init__(
234232
self,
235233
filename: str,
236-
dataset_type: Optional[str] = None,
237-
units_override: Optional[dict[str, str]] = None,
234+
dataset_type: str | None = None,
235+
units_override: dict[str, str] | None = None,
238236
# valid unit_system values include all keys from unyt.unit_systems.unit_systems_registry + "code"
239237
unit_system: Literal[
240238
"cgs",
@@ -250,7 +248,7 @@ def __init__(
250248
"Any"
251249
] = None, # Any used as a placeholder here
252250
*,
253-
axis_order: Optional[AxisOrder] = None,
251+
axis_order: AxisOrder | None = None,
254252
) -> None:
255253
"""
256254
Base class for generating new output types. Principally consists of
@@ -732,7 +730,7 @@ def setup_deprecated_fields(self):
732730
added.append(("gas", old_name))
733731
self.field_info.find_dependencies(added)
734732

735-
def _setup_coordinate_handler(self, axis_order: Optional[AxisOrder]) -> None:
733+
def _setup_coordinate_handler(self, axis_order: AxisOrder | None) -> None:
736734
# backward compatibility layer:
737735
# turning off type-checker on a per-line basis
738736
cls: type[CoordinateHandler]
@@ -947,7 +945,7 @@ def _setup_particle_types(self, ptypes=None):
947945

948946
def _get_field_info(
949947
self,
950-
field: Union[FieldKey, ImplicitFieldKey, DerivedField],
948+
field: FieldKey | ImplicitFieldKey | DerivedField,
951949
/,
952950
) -> DerivedField:
953951
field_info, candidates = self._get_field_info_helper(field)
@@ -1008,7 +1006,7 @@ def _are_ambiguous(candidates: list[FieldKey]) -> bool:
10081006

10091007
def _get_field_info_helper(
10101008
self,
1011-
field: Union[FieldKey, ImplicitFieldKey, DerivedField],
1009+
field: FieldKey | ImplicitFieldKey | DerivedField,
10121010
/,
10131011
) -> tuple[DerivedField, list[FieldKey]]:
10141012
self.index
@@ -1280,8 +1278,8 @@ def _assign_unit_system(
12801278
# is mks-like: i.e., it has a current with the same
12811279
# dimensions as amperes.
12821280
mks_system = False
1283-
mag_unit: Optional[unyt_quantity] = getattr(self, "magnetic_unit", None)
1284-
mag_dims: Optional[set[Symbol]]
1281+
mag_unit: unyt_quantity | None = getattr(self, "magnetic_unit", None)
1282+
mag_dims: set[Symbol] | None
12851283
if mag_unit is not None:
12861284
mag_dims = mag_unit.units.dimensions.free_symbols
12871285
else:
@@ -2057,9 +2055,9 @@ class ParticleFile:
20572055
filename: str
20582056
file_id: int
20592057

2060-
start: Optional[int] = None
2061-
end: Optional[int] = None
2062-
total_particles: Optional[defaultdict[str, int]] = None
2058+
start: int | None = None
2059+
end: int | None = None
2060+
total_particles: defaultdict[str, int] | None = None
20632061

20642062
def __init__(self, ds, io, filename, file_id, range=None):
20652063
self.ds = ds

0 commit comments

Comments
 (0)