48
48
49
49
"""
50
50
51
+ from __future__ import annotations
52
+
51
53
from collections import namedtuple
52
54
from contextlib import (
53
55
ContextDecorator ,
57
59
from typing import (
58
60
Any ,
59
61
Callable ,
60
- Dict ,
61
62
Iterable ,
62
- List ,
63
- Optional ,
64
- Tuple ,
65
- Type ,
66
63
cast ,
67
64
)
68
65
import warnings
73
70
RegisteredOption = namedtuple ("RegisteredOption" , "key defval doc validator cb" )
74
71
75
72
# holds deprecated option metadata
76
- _deprecated_options : Dict [str , DeprecatedOption ] = {}
73
+ _deprecated_options : dict [str , DeprecatedOption ] = {}
77
74
78
75
# holds registered option metadata
79
- _registered_options : Dict [str , RegisteredOption ] = {}
76
+ _registered_options : dict [str , RegisteredOption ] = {}
80
77
81
78
# holds the current values for registered options
82
- _global_config : Dict [str , Any ] = {}
79
+ _global_config : dict [str , Any ] = {}
83
80
84
81
# keys which have a special meaning
85
- _reserved_keys : List [str ] = ["all" ]
82
+ _reserved_keys : list [str ] = ["all" ]
86
83
87
84
88
85
class OptionError (AttributeError , KeyError ):
@@ -194,7 +191,7 @@ def get_default_val(pat: str):
194
191
class DictWrapper :
195
192
""" provide attribute-style access to a nested dict"""
196
193
197
- def __init__ (self , d : Dict [str , Any ], prefix : str = "" ):
194
+ def __init__ (self , d : dict [str , Any ], prefix : str = "" ):
198
195
object .__setattr__ (self , "d" , d )
199
196
object .__setattr__ (self , "prefix" , prefix )
200
197
@@ -428,8 +425,8 @@ def register_option(
428
425
key : str ,
429
426
defval : object ,
430
427
doc : str = "" ,
431
- validator : Optional [ Callable [[Any ], Any ]] = None ,
432
- cb : Optional [ Callable [[str ], Any ]] = None ,
428
+ validator : Callable [[Any ], Any ] | None = None ,
429
+ cb : Callable [[str ], Any ] | None = None ,
433
430
) -> None :
434
431
"""
435
432
Register an option in the package-wide pandas config object
@@ -500,7 +497,7 @@ def register_option(
500
497
501
498
502
499
def deprecate_option (
503
- key : str , msg : Optional [ str ] = None , rkey : Optional [ str ] = None , removal_ver = None
500
+ key : str , msg : str | None = None , rkey : str | None = None , removal_ver = None
504
501
) -> None :
505
502
"""
506
503
Mark option `key` as deprecated, if code attempts to access this option,
@@ -547,7 +544,7 @@ def deprecate_option(
547
544
# functions internal to the module
548
545
549
546
550
- def _select_options (pat : str ) -> List [str ]:
547
+ def _select_options (pat : str ) -> list [str ]:
551
548
"""
552
549
returns a list of keys matching `pat`
553
550
@@ -565,7 +562,7 @@ def _select_options(pat: str) -> List[str]:
565
562
return [k for k in keys if re .search (pat , k , re .I )]
566
563
567
564
568
- def _get_root (key : str ) -> Tuple [ Dict [str , Any ], str ]:
565
+ def _get_root (key : str ) -> tuple [ dict [str , Any ], str ]:
569
566
path = key .split ("." )
570
567
cursor = _global_config
571
568
for p in path [:- 1 ]:
@@ -674,7 +671,7 @@ def pp_options_list(keys: Iterable[str], width=80, _print: bool = False):
674
671
from itertools import groupby
675
672
from textwrap import wrap
676
673
677
- def pp (name : str , ks : Iterable [str ]) -> List [str ]:
674
+ def pp (name : str , ks : Iterable [str ]) -> list [str ]:
678
675
pfx = "- " + name + ".[" if name else ""
679
676
ls = wrap (
680
677
", " .join (ks ),
@@ -687,7 +684,7 @@ def pp(name: str, ks: Iterable[str]) -> List[str]:
687
684
ls [- 1 ] = ls [- 1 ] + "]"
688
685
return ls
689
686
690
- ls : List [str ] = []
687
+ ls : list [str ] = []
691
688
singles = [x for x in sorted (keys ) if x .find ("." ) < 0 ]
692
689
if singles :
693
690
ls += pp ("" , singles )
@@ -760,7 +757,7 @@ def inner(key: str, *args, **kwds):
760
757
# arg in register_option
761
758
762
759
763
- def is_type_factory (_type : Type [Any ]) -> Callable [[Any ], None ]:
760
+ def is_type_factory (_type : type [Any ]) -> Callable [[Any ], None ]:
764
761
"""
765
762
766
763
Parameters
@@ -826,7 +823,7 @@ def inner(x) -> None:
826
823
return inner
827
824
828
825
829
- def is_nonnegative_int (value : Optional [ int ] ) -> None :
826
+ def is_nonnegative_int (value : int | None ) -> None :
830
827
"""
831
828
Verify that value is None or a positive int.
832
829
0 commit comments