66import os
77from configparser import ConfigParser
88from pathlib import Path
9- from typing import Any , ClassVar
9+ from typing import TYPE_CHECKING , Any , ClassVar
1010
1111from platformdirs import user_config_dir
1212
1313from tox .config .loader .api import ConfigLoadArgs
1414from tox .config .loader .ini import IniLoader
1515from tox .config .source .ini_section import CORE
1616
17+ if TYPE_CHECKING :
18+ from types import UnionType
19+
1720DEFAULT_CONFIG_FILE = Path (user_config_dir ("tox" )) / "config.ini"
1821
1922
@@ -25,7 +28,7 @@ def __init__(self) -> None:
2528 config_file = os .environ .get (self .TOX_CONFIG_FILE_ENV_VAR , None )
2629 self .is_env_var = config_file is not None
2730 self .config_file = Path (config_file if config_file is not None else DEFAULT_CONFIG_FILE )
28- self ._cache : dict [tuple [str , type [Any ]], Any ] = {}
31+ self ._cache : dict [tuple [str , type [Any ] | UnionType ], Any ] = {}
2932 self .has_config_file : bool | None = self .config_file .exists ()
3033 self .ini : IniLoader | None = None
3134
@@ -45,7 +48,7 @@ def _parse_config_file(self) -> None:
4548 if self .has_tox_section :
4649 self .ini = IniLoader (CORE , parser , overrides = [], core_section = CORE )
4750
48- def get (self , key : str , of_type : type [Any ]) -> Any :
51+ def get (self , key : str , of_type : type [Any ] | UnionType ) -> Any :
4952 cache_key = key , of_type
5053 if cache_key in self ._cache :
5154 result = self ._cache [cache_key ]
@@ -60,7 +63,7 @@ def get(self, key: str, of_type: type[Any]) -> Any:
6063 self ._cache [cache_key ] = result
6164 return result
6265
63- def _load_key (self , key : str , of_type : type [Any ]) -> Any :
66+ def _load_key (self , key : str , of_type : type [Any ] | UnionType ) -> Any :
6467 if self .ini is None : # pragma: no cover # this can only happen if we don't call __bool__ first
6568 return None
6669 args = ConfigLoadArgs (chain = [key ], name = CORE .prefix , env_name = None )
0 commit comments