4242from collections .abc import Iterable
4343from enum import Enum
4444from pathlib import Path , PureWindowsPath
45- from typing import TYPE_CHECKING , Any , Optional , Union
45+ from typing import TYPE_CHECKING , Any
4646
4747from west .util import WEST_DIR , PathType , WestNotFound , west_dir
4848
@@ -67,7 +67,7 @@ def parse_key(dotted_name: str):
6767 return section_child
6868
6969 @staticmethod
70- def from_path (path : Optional [ Path ] ) -> Optional [ '_InternalCF' ] :
70+ def from_path (path : Path | None ) -> '_InternalCF | None' :
7171 return _InternalCF (path ) if path and path .exists () else None
7272
7373 def __init__ (self , path : Path ):
@@ -160,7 +160,7 @@ class Configuration:
160160
161161 '''
162162
163- def __init__ (self , topdir : Optional [ PathType ] = None ):
163+ def __init__ (self , topdir : PathType | None = None ):
164164 '''Load the system, global, and workspace configurations and
165165 make them available for the user.
166166
@@ -179,8 +179,8 @@ def __init__(self, topdir: Optional[PathType] = None):
179179 self ._local = _InternalCF .from_path (self ._local_path )
180180
181181 def get (self , option : str ,
182- default : Optional [ str ] = None ,
183- configfile : ConfigFile = ConfigFile .ALL ) -> Optional [ str ] :
182+ default : str | None = None ,
183+ configfile : ConfigFile = ConfigFile .ALL ) -> str | None :
184184 '''Get a configuration option's value as a string.
185185
186186 :param option: option to get, in 'foo.bar' form
@@ -204,8 +204,8 @@ def getboolean(self, option: str,
204204 return self ._get (lambda cf : cf .getboolean (option ), default , configfile )
205205
206206 def getint (self , option : str ,
207- default : Optional [ int ] = None ,
208- configfile : ConfigFile = ConfigFile .ALL ) -> Optional [ int ] :
207+ default : int | None = None ,
208+ configfile : ConfigFile = ConfigFile .ALL ) -> int | None :
209209 '''Get a configuration option's value as an int.
210210
211211 :param option: option to get, in 'foo.bar' form
@@ -215,8 +215,8 @@ def getint(self, option: str,
215215 return self ._get (lambda cf : cf .getint (option ), default , configfile )
216216
217217 def getfloat (self , option : str ,
218- default : Optional [ float ] = None ,
219- configfile : ConfigFile = ConfigFile .ALL ) -> Optional [ float ] :
218+ default : float | None = None ,
219+ configfile : ConfigFile = ConfigFile .ALL ) -> float | None :
220220 '''Get a configuration option's value as a float.
221221
222222 :param option: option to get, in 'foo.bar' form
@@ -306,7 +306,7 @@ def _create(path: Path) -> _InternalCF:
306306 return ret
307307
308308 def delete (self , option : str ,
309- configfile : Optional [ ConfigFile ] = None ) -> None :
309+ configfile : ConfigFile | None = None ) -> None :
310310 '''Delete an option from the given file or files.
311311
312312 If *option* is not set in the given *configfile*, KeyError is raised.
@@ -401,7 +401,7 @@ def _local_as_dict(self):
401401 return self ._cf_to_dict (self ._local )
402402
403403 @staticmethod
404- def _cf_to_dict (cf : Optional [ _InternalCF ] ) -> dict [str , Any ]:
404+ def _cf_to_dict (cf : _InternalCF | None ) -> dict [str , Any ]:
405405 ret : dict [str , Any ] = {}
406406 if cf is None :
407407 return ret
@@ -423,9 +423,9 @@ def _deprecated(old_function):
423423 'use a west.configuration.Configuration object' ,
424424 DeprecationWarning , stacklevel = 2 )
425425
426- def read_config (configfile : Optional [ ConfigFile ] = None ,
426+ def read_config (configfile : ConfigFile | None = None ,
427427 config : configparser .ConfigParser = config ,
428- topdir : Optional [ PathType ] = None ) -> None :
428+ topdir : PathType | None = None ) -> None :
429429 '''Read configuration files into *config*.
430430
431431 Reads the files given by *configfile*, storing the values into the
@@ -458,7 +458,7 @@ def read_config(configfile: Optional[ConfigFile] = None,
458458
459459def update_config (section : str , key : str , value : Any ,
460460 configfile : ConfigFile = ConfigFile .LOCAL ,
461- topdir : Optional [ PathType ] = None ) -> None :
461+ topdir : PathType | None = None ) -> None :
462462 '''Sets ``section.key`` to *value* in the given configuration file.
463463
464464 :param section: config section; will be created if it does not exist
@@ -493,8 +493,8 @@ def update_config(section: str, key: str, value: Any,
493493 config .write (f )
494494
495495def delete_config (section : str , key : str ,
496- configfile : Union [ Optional [ ConfigFile ], list [ConfigFile ]] = None ,
497- topdir : Optional [ PathType ] = None ) -> None :
496+ configfile : ConfigFile | list [ConfigFile ] | None = None ,
497+ topdir : PathType | None = None ) -> None :
498498 '''Delete the option section.key from the given file or files.
499499
500500 :param section: section whose key to delete
@@ -556,7 +556,7 @@ def delete_config(section: str, key: str,
556556 if not found :
557557 raise KeyError (f'{ section } .{ key } ' )
558558
559- def _location (cfg : ConfigFile , topdir : Optional [ PathType ] = None ,
559+ def _location (cfg : ConfigFile , topdir : PathType | None = None ,
560560 find_local : bool = True ) -> str :
561561 # Making this a function that gets called each time you ask for a
562562 # configuration file makes it respect updated environment
@@ -628,7 +628,7 @@ def _location(cfg: ConfigFile, topdir: Optional[PathType] = None,
628628 else :
629629 raise ValueError (f'invalid configuration file { cfg } ' )
630630
631- def _gather_configs (cfg : ConfigFile , topdir : Optional [ PathType ] ) -> list [str ]:
631+ def _gather_configs (cfg : ConfigFile , topdir : PathType | None ) -> list [str ]:
632632 # Find the paths to the given configuration files, in increasing
633633 # precedence order.
634634 ret = []
@@ -645,7 +645,7 @@ def _gather_configs(cfg: ConfigFile, topdir: Optional[PathType]) -> list[str]:
645645
646646 return ret
647647
648- def _ensure_config (configfile : ConfigFile , topdir : Optional [ PathType ] ) -> str :
648+ def _ensure_config (configfile : ConfigFile , topdir : PathType | None ) -> str :
649649 # Ensure the given configfile exists, returning its path. May
650650 # raise permissions errors, WestNotFound, etc.
651651 loc = _location (configfile , topdir = topdir )
0 commit comments