13
13
from functools import cached_property
14
14
from importlib .util import find_spec
15
15
from stat import ST_CTIME
16
- from typing import Any , Literal , Optional , Union
16
+ from typing import Any , Literal , Optional
17
17
18
18
import numpy as np
19
19
import unyt as un
86
86
# to here, and then have it instantiate EnzoDatasets as appropriate.
87
87
88
88
89
- _cached_datasets : MutableMapping [Union [int , str ], "Dataset" ] = (
90
- weakref .WeakValueDictionary ()
91
- )
89
+ _cached_datasets : MutableMapping [int | str , "Dataset" ] = weakref .WeakValueDictionary ()
92
90
93
91
# we set this global to None as a place holder
94
92
# its actual instantiation is delayed until after yt.__init__
95
93
# is completed because we need yt.config.ytcfg to be instantiated first
96
94
97
- _ds_store : Optional [ ParameterFileStore ] = None
95
+ _ds_store : ParameterFileStore | None = None
98
96
99
97
100
98
def _setup_ds_store (ytcfg : YTConfig ) -> None :
@@ -161,24 +159,24 @@ class Dataset(abc.ABC):
161
159
default_field = ("gas" , "density" )
162
160
fluid_types : tuple [FieldType , ...] = ("gas" , "deposit" , "index" )
163
161
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" ,)
165
163
geometry : Geometry = Geometry .CARTESIAN
166
164
coordinates = None
167
165
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
170
168
_index_class : type [Index ]
171
- field_units : Optional [ dict [AnyFieldKey , Unit ]] = None
169
+ field_units : dict [AnyFieldKey , Unit ] | None = None
172
170
derived_field_list = requires_index ("derived_field_list" )
173
171
fields = requires_index ("fields" )
174
- conversion_factors : Optional [ dict [str , float ]] = None
172
+ conversion_factors : dict [str , float ] | None = None
175
173
# _instantiated represents an instantiation time (since Epoch)
176
174
# the default is a place holder sentinel, falsy value
177
175
_instantiated : float = 0
178
176
_particle_type_counts = None
179
177
_proj_type = "quad_proj"
180
178
_ionization_label_format = "roman_numeral"
181
- _determined_fields : Optional [ dict [str , list [FieldKey ]]] = None
179
+ _determined_fields : dict [str , list [FieldKey ]] | None = None
182
180
fields_detected = False
183
181
184
182
# these are set in self._parse_parameter_file()
@@ -233,8 +231,8 @@ def __init_subclass__(cls, *args, **kwargs):
233
231
def __init__ (
234
232
self ,
235
233
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 ,
238
236
# valid unit_system values include all keys from unyt.unit_systems.unit_systems_registry + "code"
239
237
unit_system : Literal [
240
238
"cgs" ,
@@ -250,7 +248,7 @@ def __init__(
250
248
"Any"
251
249
] = None , # Any used as a placeholder here
252
250
* ,
253
- axis_order : Optional [ AxisOrder ] = None ,
251
+ axis_order : AxisOrder | None = None ,
254
252
) -> None :
255
253
"""
256
254
Base class for generating new output types. Principally consists of
@@ -732,7 +730,7 @@ def setup_deprecated_fields(self):
732
730
added .append (("gas" , old_name ))
733
731
self .field_info .find_dependencies (added )
734
732
735
- def _setup_coordinate_handler (self , axis_order : Optional [ AxisOrder ] ) -> None :
733
+ def _setup_coordinate_handler (self , axis_order : AxisOrder | None ) -> None :
736
734
# backward compatibility layer:
737
735
# turning off type-checker on a per-line basis
738
736
cls : type [CoordinateHandler ]
@@ -947,7 +945,7 @@ def _setup_particle_types(self, ptypes=None):
947
945
948
946
def _get_field_info (
949
947
self ,
950
- field : Union [ FieldKey , ImplicitFieldKey , DerivedField ] ,
948
+ field : FieldKey | ImplicitFieldKey | DerivedField ,
951
949
/ ,
952
950
) -> DerivedField :
953
951
field_info , candidates = self ._get_field_info_helper (field )
@@ -1008,7 +1006,7 @@ def _are_ambiguous(candidates: list[FieldKey]) -> bool:
1008
1006
1009
1007
def _get_field_info_helper (
1010
1008
self ,
1011
- field : Union [ FieldKey , ImplicitFieldKey , DerivedField ] ,
1009
+ field : FieldKey | ImplicitFieldKey | DerivedField ,
1012
1010
/ ,
1013
1011
) -> tuple [DerivedField , list [FieldKey ]]:
1014
1012
self .index
@@ -1280,8 +1278,8 @@ def _assign_unit_system(
1280
1278
# is mks-like: i.e., it has a current with the same
1281
1279
# dimensions as amperes.
1282
1280
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
1285
1283
if mag_unit is not None :
1286
1284
mag_dims = mag_unit .units .dimensions .free_symbols
1287
1285
else :
@@ -2057,9 +2055,9 @@ class ParticleFile:
2057
2055
filename : str
2058
2056
file_id : int
2059
2057
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
2063
2061
2064
2062
def __init__ (self , ds , io , filename , file_id , range = None ):
2065
2063
self .ds = ds
0 commit comments