Skip to content

Commit 4cfd370

Browse files
committed
MNT: auto upgrade code base to Python 3.9
1 parent 8ec65d1 commit 4cfd370

File tree

71 files changed

+268
-338
lines changed

Some content is hidden

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

71 files changed

+268
-338
lines changed

tests/unpin_requirements.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
22
import sys
3-
from typing import List
43

54
import tomli_w
65

@@ -12,7 +11,7 @@
1211
PINNED_VERSION_REGEXP = re.compile(r",?(<|<=|==)([0-9a-z]+\.?)+")
1312

1413

15-
def unpin_requirements(requirements: List[str]) -> List[str]:
14+
def unpin_requirements(requirements: list[str]) -> list[str]:
1615
return [re.sub(PINNED_VERSION_REGEXP, "", _) for _ in requirements]
1716

1817

yt/_maintenance/deprecation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import warnings
22
from functools import wraps
33
from types import FunctionType
4-
from typing import Dict, Optional
4+
from typing import Optional
55

66

77
def issue_deprecation_warning(
@@ -45,7 +45,7 @@ def issue_deprecation_warning(
4545
warnings.warn(msg, DeprecationWarning, stacklevel=stacklevel)
4646

4747

48-
def future_positional_only(positions2names: Dict[int, str], /, **depr_kwargs):
48+
def future_positional_only(positions2names: dict[int, str], /, **depr_kwargs):
4949
"""Warn users when using a future positional-only argument as keyword.
5050
Note that positional-only arguments are available from Python 3.8
5151
See https://www.python.org/dev/peps/pep-0570/

yt/_typing.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
from typing import List, Optional, Tuple, Union
1+
from typing import Optional, Union
22

33
import unyt as un
44
from numpy import ndarray
55

6-
FieldDescT = Tuple[str, Tuple[str, List[str], Optional[str]]]
7-
KnownFieldsT = Tuple[FieldDescT, ...]
6+
FieldDescT = tuple[str, tuple[str, list[str], Optional[str]]]
7+
KnownFieldsT = tuple[FieldDescT, ...]
88

99
ParticleType = str
1010
FieldType = str
1111
FieldName = str
12-
FieldKey = Tuple[FieldType, FieldName]
12+
FieldKey = tuple[FieldType, FieldName]
1313
ImplicitFieldKey = FieldName
1414
AnyFieldKey = Union[FieldKey, ImplicitFieldKey]
15-
DomainDimensions = Union[Tuple[int, ...], List[int], ndarray]
15+
DomainDimensions = Union[tuple[int, ...], list[int], ndarray]
1616

17-
ParticleCoordinateTuple = Tuple[
17+
ParticleCoordinateTuple = tuple[
1818
str, # particle type
19-
Tuple[ndarray, ndarray, ndarray], # xyz
19+
tuple[ndarray, ndarray, ndarray], # xyz
2020
Union[float, ndarray], # hsml
2121
]
2222

2323
# Geometry specific types
2424
AxisName = str
25-
AxisOrder = Tuple[AxisName, AxisName, AxisName]
25+
AxisOrder = tuple[AxisName, AxisName, AxisName]
2626

2727
# types that can be converted to un.Unit
2828
Unit = Union[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 = Union[un.unyt_quantity, tuple[float, Unit]]

yt/data_objects/data_containers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import weakref
33
from collections import defaultdict
44
from contextlib import contextmanager
5-
from typing import TYPE_CHECKING, List, Optional, Tuple
5+
from typing import TYPE_CHECKING, Optional
66

77
import numpy as np
88

@@ -66,14 +66,14 @@ class YTDataContainer(abc.ABC):
6666

6767
_chunk_info = None
6868
_num_ghost_zones = 0
69-
_con_args: Tuple[str, ...] = ()
69+
_con_args: tuple[str, ...] = ()
7070
_skip_add = False
71-
_container_fields: Tuple[AnyFieldKey, ...] = ()
72-
_tds_attrs: Tuple[str, ...] = ()
73-
_tds_fields: Tuple[str, ...] = ()
71+
_container_fields: tuple[AnyFieldKey, ...] = ()
72+
_tds_attrs: tuple[str, ...] = ()
73+
_tds_fields: tuple[str, ...] = ()
7474
_field_cache = None
7575
_index = None
76-
_key_fields: List[str]
76+
_key_fields: list[str]
7777

7878
def __init__(self, ds: Optional["Dataset"], field_parameters) -> None:
7979
"""

yt/data_objects/index_subobjects/grid_patch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import weakref
2-
from typing import List
32

43
import numpy as np
54

@@ -270,7 +269,7 @@ def retrieve_ghost_zones(self, n_zones, fields, all_levels=False, smoothed=False
270269

271270
def get_vertex_centered_data(
272271
self,
273-
fields: List[FieldKey],
272+
fields: list[FieldKey],
274273
smoothed: bool = True,
275274
no_ghost: bool = False,
276275
):

yt/data_objects/index_subobjects/octree_subset.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from contextlib import contextmanager
22
from functools import cached_property
33
from itertools import product, repeat
4-
from typing import Tuple
54

65
import numpy as np
76
from unyt import unyt_array
@@ -39,7 +38,7 @@ class OctreeSubset(YTSelectionContainer):
3938
_num_ghost_zones = 0
4039
_type_name = "octree_subset"
4140
_skip_add = True
42-
_con_args: Tuple[str, ...] = ("base_region", "domain", "ds")
41+
_con_args: tuple[str, ...] = ("base_region", "domain", "ds")
4342
_domain_offset = 0
4443
_cell_count = -1
4544
_block_order = "C"

yt/data_objects/particle_filters.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import copy
22
from contextlib import contextmanager
3-
from typing import Dict
43

54
from yt.fields.field_info_container import NullFunc, TranslationFunc
65
from yt.funcs import mylog
76
from yt.utilities.exceptions import YTIllDefinedFilter
87

98
# One to one mapping
10-
filter_registry: Dict[str, "ParticleFilter"] = {}
9+
filter_registry: dict[str, "ParticleFilter"] = {}
1110

1211

1312
class DummyFieldInfo:

yt/data_objects/selection_objects/data_selection_objects.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import uuid
55
from collections import defaultdict
66
from contextlib import contextmanager
7-
from typing import Tuple
87

98
import numpy as np
109
from more_itertools import always_iterable
@@ -1398,7 +1397,7 @@ def _get_bbox(self):
13981397
"""
13991398
return self.ds.domain_left_edge, self.ds.domain_right_edge
14001399

1401-
def get_bbox(self) -> Tuple[unyt_array, unyt_array]:
1400+
def get_bbox(self) -> tuple[unyt_array, unyt_array]:
14021401
"""
14031402
Return the bounding box for this data container.
14041403
"""

yt/data_objects/static_output.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@
1414
from stat import ST_CTIME
1515
from typing import (
1616
Any,
17-
DefaultDict,
18-
Dict,
19-
List,
2017
Literal,
2118
Optional,
22-
Set,
23-
Tuple,
24-
Type,
2519
Union,
2620
)
2721

@@ -89,11 +83,7 @@
8983
else:
9084
from typing_extensions import assert_never
9185

92-
if sys.version_info >= (3, 9):
93-
from collections.abc import MutableMapping
94-
else:
95-
from typing import MutableMapping
96-
86+
from collections.abc import MutableMapping
9787

9888
# We want to support the movie format in the future.
9989
# When such a thing comes to pass, I'll move all the stuff that is constant up
@@ -178,26 +168,26 @@ def ireq(self, value):
178168
class Dataset(abc.ABC):
179169
default_fluid_type = "gas"
180170
default_field = ("gas", "density")
181-
fluid_types: Tuple[FieldType, ...] = ("gas", "deposit", "index")
182-
particle_types: Tuple[ParticleType, ...] = ("io",) # By default we have an 'all'
183-
particle_types_raw: Optional[Tuple[ParticleType, ...]] = ("io",)
171+
fluid_types: tuple[FieldType, ...] = ("gas", "deposit", "index")
172+
particle_types: tuple[ParticleType, ...] = ("io",) # By default we have an 'all'
173+
particle_types_raw: Optional[tuple[ParticleType, ...]] = ("io",)
184174
geometry: Geometry = Geometry.CARTESIAN
185175
coordinates = None
186176
storage_filename = None
187-
particle_unions: Optional[Dict[ParticleType, ParticleUnion]] = None
188-
known_filters: Optional[Dict[ParticleType, ParticleFilter]] = None
189-
_index_class: Type[Index]
190-
field_units: Optional[Dict[AnyFieldKey, Unit]] = None
177+
particle_unions: Optional[dict[ParticleType, ParticleUnion]] = None
178+
known_filters: Optional[dict[ParticleType, ParticleFilter]] = None
179+
_index_class: type[Index]
180+
field_units: Optional[dict[AnyFieldKey, Unit]] = None
191181
derived_field_list = requires_index("derived_field_list")
192182
fields = requires_index("fields")
193-
conversion_factors: Optional[Dict[str, float]] = None
183+
conversion_factors: Optional[dict[str, float]] = None
194184
# _instantiated represents an instantiation time (since Epoch)
195185
# the default is a place holder sentinel, falsy value
196186
_instantiated: float = 0
197187
_particle_type_counts = None
198188
_proj_type = "quad_proj"
199189
_ionization_label_format = "roman_numeral"
200-
_determined_fields: Optional[Dict[str, List[FieldKey]]] = None
190+
_determined_fields: Optional[dict[str, list[FieldKey]]] = None
201191
fields_detected = False
202192

203193
# these are set in self._parse_parameter_file()
@@ -253,7 +243,7 @@ def __init__(
253243
self,
254244
filename: str,
255245
dataset_type: Optional[str] = None,
256-
units_override: Optional[Dict[str, str]] = None,
246+
units_override: Optional[dict[str, str]] = None,
257247
# valid unit_system values include all keys from unyt.unit_systems.unit_systems_registry + "code"
258248
unit_system: Literal[
259249
"cgs",
@@ -281,7 +271,7 @@ def __init__(
281271
return
282272
self.dataset_type = dataset_type
283273
self.conversion_factors = {}
284-
self.parameters: Dict[str, Any] = {}
274+
self.parameters: dict[str, Any] = {}
285275
self.region_expression = self.r = RegionExpression(self)
286276
self.known_filters = self.known_filters or {}
287277
self.particle_unions = self.particle_unions or {}
@@ -751,7 +741,7 @@ def setup_deprecated_fields(self):
751741
def _setup_coordinate_handler(self, axis_order: Optional[AxisOrder]) -> None:
752742
# backward compatibility layer:
753743
# turning off type-checker on a per-line basis
754-
cls: Type[CoordinateHandler]
744+
cls: type[CoordinateHandler]
755745

756746
if isinstance(self.geometry, tuple): # type: ignore [unreachable]
757747
issue_deprecation_warning( # type: ignore [unreachable]
@@ -973,7 +963,7 @@ def _get_field_info(
973963
# https://github.com/yt-project/yt/issues/3381
974964
return field_info
975965

976-
def _are_ambiguous(candidates: List[FieldKey]) -> bool:
966+
def _are_ambiguous(candidates: list[FieldKey]) -> bool:
977967
if len(candidates) < 2:
978968
return False
979969

@@ -996,7 +986,7 @@ def _are_ambiguous(candidates: List[FieldKey]) -> bool:
996986
elif all(ft in self.particle_types for ft in ftypes):
997987
ptypes = ftypes
998988

999-
sub_types_list: List[Set[str]] = []
989+
sub_types_list: list[set[str]] = []
1000990
for pt in ptypes:
1001991
if pt in self.particle_types_raw:
1002992
sub_types_list.append({pt})
@@ -1026,7 +1016,7 @@ def _get_field_info_helper(
10261016
self,
10271017
field: Union[FieldKey, ImplicitFieldKey, DerivedField],
10281018
/,
1029-
) -> Tuple[DerivedField, List[FieldKey]]:
1019+
) -> tuple[DerivedField, list[FieldKey]]:
10301020
self.index
10311021

10321022
ftype: str
@@ -1041,7 +1031,7 @@ def _get_field_info_helper(
10411031
raise YTFieldNotParseable(field)
10421032

10431033
if ftype == "unknown":
1044-
candidates: List[FieldKey] = [
1034+
candidates: list[FieldKey] = [
10451035
(ft, fn) for ft, fn in self.field_info if fn == fname
10461036
]
10471037

@@ -1297,7 +1287,7 @@ def _assign_unit_system(
12971287
# dimensions as amperes.
12981288
mks_system = False
12991289
mag_unit: Optional[unyt_quantity] = getattr(self, "magnetic_unit", None)
1300-
mag_dims: Optional[Set[Symbol]]
1290+
mag_dims: Optional[set[Symbol]]
13011291
if mag_unit is not None:
13021292
mag_dims = mag_unit.units.dimensions.free_symbols
13031293
else:
@@ -2075,7 +2065,7 @@ class ParticleFile:
20752065

20762066
start: Optional[int] = None
20772067
end: Optional[int] = None
2078-
total_particles: Optional[DefaultDict[str, int]] = None
2068+
total_particles: Optional[defaultdict[str, int]] = None
20792069

20802070
def __init__(self, ds, io, filename, file_id, range=None):
20812071
self.ds = ds

yt/data_objects/time_series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import weakref
66
from abc import ABC, abstractmethod
77
from functools import wraps
8-
from typing import Optional, Type
8+
from typing import Optional
99

1010
import numpy as np
1111
from more_itertools import always_iterable
@@ -146,7 +146,7 @@ class DatasetSeries:
146146
# this annotation should really be Optional[Type[Dataset]]
147147
# but we cannot import the yt.data_objects.static_output.Dataset
148148
# class here without creating a circular import for now
149-
_dataset_cls: Optional[Type] = None
149+
_dataset_cls: Optional[type] = None
150150

151151
def __init_subclass__(cls, *args, **kwargs):
152152
super().__init_subclass__(*args, **kwargs)

yt/fields/derived_field.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import contextlib
22
import inspect
33
import re
4-
from typing import Iterable, Optional, Union
4+
from collections.abc import Iterable
5+
from typing import Optional, Union
56

67
from more_itertools import always_iterable
78

yt/fields/domain_context.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import abc
2-
from typing import Tuple
32

43
from yt._typing import FieldKey
54

@@ -12,8 +11,8 @@ def __init__(cls, name, b, d):
1211
type.__init__(cls, name, b, d)
1312
domain_context_registry[name] = cls
1413

15-
_known_fluid_fields: Tuple[FieldKey, ...]
16-
_known_particle_fields: Tuple[FieldKey, ...]
14+
_known_fluid_fields: tuple[FieldKey, ...]
15+
_known_particle_fields: tuple[FieldKey, ...]
1716

1817
def __init__(self, ds):
1918
self.ds = ds

yt/fields/field_detector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import defaultdict
2-
from typing import Tuple, Union
2+
from typing import Union
33

44
import numpy as np
55

@@ -101,7 +101,7 @@ def _reshape_vals(self, arr):
101101
return arr
102102
return arr.reshape(self.ActiveDimensions, order="C")
103103

104-
def __missing__(self, item: Union[Tuple[str, str], str]):
104+
def __missing__(self, item: Union[tuple[str, str], str]):
105105
from yt.fields.derived_field import NullFunc
106106

107107
if not isinstance(item, tuple):
@@ -117,7 +117,7 @@ def __missing__(self, item: Union[Tuple[str, str], str]):
117117
# types not getting correctly identified.
118118
# Note that the *only* way this works is if we also fix our field
119119
# dependencies during checking. Bug #627 talks about this.
120-
_item: Tuple[str, str] = finfo.name
120+
_item: tuple[str, str] = finfo.name
121121
if finfo is not None and finfo._function is not NullFunc:
122122
try:
123123
for param, param_v in permute_params.items():

0 commit comments

Comments
 (0)