22# You should have received the IMAS-Python LICENSE file with this project.
33"""Logic for interacting with IMAS Data Entries."""
44
5+ from __future__ import annotations
6+
57import logging
68import os
7- from typing import Any , List , Optional , Tuple , Type , Union , overload
9+ import pathlib
10+ from typing import Any , Type , overload
811
912import numpy
1013
3336logger = logging .getLogger (__name__ )
3437
3538
36- def _get_uri_mode (uri , mode ) -> Tuple [str , str ]:
39+ def _get_uri_mode (uri , mode ) -> tuple [str , str ]:
3740 """Helper method to parse arguments of DBEntry.__init__."""
3841 return uri , mode
3942
4043
4144def _get_legacy_params (
4245 backend_id , db_name , pulse , run , user_name = None , data_version = None
43- ) -> Tuple [int , str , int , int , Optional [ str ], Optional [ str ] ]:
46+ ) -> tuple [int , str , int , int , str | None , str | None ]:
4447 """Helper method to parse arguments of DBEntry.__init__."""
4548 return backend_id , db_name , pulse , run , user_name , data_version
4649
@@ -74,8 +77,8 @@ def __init__(
7477 uri : str ,
7578 mode : str ,
7679 * ,
77- dd_version : Optional [ str ] = None ,
78- xml_path : Optional [ str ] = None ,
80+ dd_version : str | None = None ,
81+ xml_path : str | pathlib . Path | None = None ,
7982 ) -> None : ...
8083
8184 @overload
@@ -85,19 +88,19 @@ def __init__(
8588 db_name : str ,
8689 pulse : int ,
8790 run : int ,
88- user_name : Optional [ str ] = None ,
89- data_version : Optional [ str ] = None ,
91+ user_name : str | None = None ,
92+ data_version : str | None = None ,
9093 * ,
91- shot : Optional [ int ] = None ,
92- dd_version : Optional [ str ] = None ,
93- xml_path : Optional [ str ] = None ,
94+ shot : int | None = None ,
95+ dd_version : str | None = None ,
96+ xml_path : str | pathlib . Path | None = None ,
9497 ) -> None : ...
9598
9699 def __init__ (
97100 self ,
98101 * args ,
99- dd_version : Optional [ str ] = None ,
100- xml_path : Optional [ str ] = None ,
102+ dd_version : str | None = None ,
103+ xml_path : str | pathlib . Path | None = None ,
101104 ** kwargs ,
102105 ):
103106 """Open or create a Data Entry based on the provided URI and mode, or prepare a
@@ -162,7 +165,7 @@ def __init__(
162165 ) from None
163166
164167 # Actual intializiation
165- self ._dbe_impl : Optional [ DBEntryImpl ] = None
168+ self ._dbe_impl : DBEntryImpl | None = None
166169 self ._dd_version = dd_version
167170 self ._xml_path = xml_path
168171 self ._ids_factory = IDSFactory (dd_version , xml_path )
@@ -186,7 +189,7 @@ def __init__(
186189 self ._dbe_impl = cls .from_uri (self .uri , mode , self ._ids_factory )
187190
188191 @staticmethod
189- def _select_implementation (uri : Optional [ str ] ) -> Type [DBEntryImpl ]:
192+ def _select_implementation (uri : str | None ) -> Type [DBEntryImpl ]:
190193 """Select which DBEntry implementation to use based on the URI."""
191194 if uri and uri .endswith (".nc" ) and not uri .startswith ("imas:" ):
192195 from imas .backends .netcdf .db_entry_nc import NCDBEntryImpl as impl
@@ -307,7 +310,7 @@ def get(
307310 lazy : bool = False ,
308311 autoconvert : bool = True ,
309312 ignore_unknown_dd_version : bool = False ,
310- destination : Optional [ IDSToplevel ] = None ,
313+ destination : IDSToplevel | None = None ,
311314 ) -> IDSToplevel :
312315 """Read the contents of an IDS into memory.
313316
@@ -370,7 +373,7 @@ def get_slice(
370373 lazy : bool = False ,
371374 autoconvert : bool = True ,
372375 ignore_unknown_dd_version : bool = False ,
373- destination : Optional [ IDSToplevel ] = None ,
376+ destination : IDSToplevel | None = None ,
374377 ) -> IDSToplevel :
375378 """Read a single time slice from an IDS in this Database Entry.
376379
@@ -434,14 +437,14 @@ def get_sample(
434437 ids_name : str ,
435438 tmin : float ,
436439 tmax : float ,
437- dtime : Optional [ Union [ float , numpy .ndarray ]] = None ,
438- interpolation_method : Optional [ int ] = None ,
440+ dtime : float | numpy .ndarray | None = None ,
441+ interpolation_method : int | None = None ,
439442 occurrence : int = 0 ,
440443 * ,
441444 lazy : bool = False ,
442445 autoconvert : bool = True ,
443446 ignore_unknown_dd_version : bool = False ,
444- destination : Optional [ IDSToplevel ] = None ,
447+ destination : IDSToplevel | None = None ,
445448 ) -> IDSToplevel :
446449 """Read a range of time slices from an IDS in this Database Entry.
447450
@@ -547,8 +550,8 @@ def _get(
547550 self ,
548551 ids_name : str ,
549552 occurrence : int ,
550- parameters : Union [ None , GetSliceParameters , GetSampleParameters ] ,
551- destination : Optional [ IDSToplevel ] ,
553+ parameters : None | GetSliceParameters | GetSampleParameters ,
554+ destination : IDSToplevel | None ,
552555 lazy : bool ,
553556 autoconvert : bool ,
554557 ignore_unknown_dd_version : bool ,
@@ -751,12 +754,12 @@ def delete_data(self, ids_name: str, occurrence: int = 0) -> None:
751754 @overload
752755 def list_all_occurrences (
753756 self , ids_name : str , node_path : None = None
754- ) -> List [int ]: ...
757+ ) -> list [int ]: ...
755758
756759 @overload
757760 def list_all_occurrences (
758761 self , ids_name : str , node_path : str
759- ) -> Tuple [ List [int ], List [IDSBase ]]: ...
762+ ) -> tuple [ list [int ], list [IDSBase ]]: ...
760763
761764 def list_all_occurrences (self , ids_name , node_path = None ):
762765 """List all non-empty occurrences of an IDS
0 commit comments