1616import re
1717import subprocess
1818import sys
19- from typing import Any , Callable , Dict , List , Optional , Tuple
19+ from typing import Any , Callable
2020import functools
2121
2222
23- def get_keywords () -> Dict [str , str ]:
23+ def get_keywords () -> dict [str , str ]:
2424 """Get the keywords needed to look up the version information."""
2525 # these strings will be replaced by git during git-archive.
2626 # setup.py/versioneer.py will grep for the variable names, so they must
@@ -61,8 +61,8 @@ class NotThisMethod(Exception):
6161 """Exception raised if a method is not valid for the current scenario."""
6262
6363
64- LONG_VERSION_PY : Dict [str , str ] = {}
65- HANDLERS : Dict [str , Dict [str , Callable ]] = {}
64+ LONG_VERSION_PY : dict [str , str ] = {}
65+ HANDLERS : dict [str , dict [str , Callable ]] = {}
6666
6767
6868def register_vcs_handler (vcs : str , method : str ) -> Callable : # decorator
@@ -77,18 +77,18 @@ def decorate(f: Callable) -> Callable:
7777
7878
7979def run_command (
80- commands : List [str ],
81- args : List [str ],
82- cwd : Optional [ str ] = None ,
80+ commands : list [str ],
81+ args : list [str ],
82+ cwd : str | None = None ,
8383 verbose : bool = False ,
8484 hide_stderr : bool = False ,
85- env : Optional [ Dict [ str , str ]] = None ,
86- ) -> Tuple [ Optional [ str ], Optional [ int ] ]:
85+ env : dict [ str , str ] | None = None ,
86+ ) -> tuple [ str | None , int | None ]:
8787 """Call the given command(s)."""
8888 assert isinstance (commands , list )
8989 process = None
9090
91- popen_kwargs : Dict [str , Any ] = {}
91+ popen_kwargs : dict [str , Any ] = {}
9292 if sys .platform == "win32" :
9393 # This hides the console window if pythonw.exe is used
9494 startupinfo = subprocess .STARTUPINFO ()
@@ -128,7 +128,7 @@ def versions_from_parentdir(
128128 parentdir_prefix : str ,
129129 root : str ,
130130 verbose : bool ,
131- ) -> Dict [str , Any ]:
131+ ) -> dict [str , Any ]:
132132 """Try to determine the version from the parent directory name.
133133
134134 Source tarballs conventionally unpack into a directory that includes both
@@ -153,13 +153,13 @@ def versions_from_parentdir(
153153
154154
155155@register_vcs_handler ("git" , "get_keywords" )
156- def git_get_keywords (versionfile_abs : str ) -> Dict [str , str ]:
156+ def git_get_keywords (versionfile_abs : str ) -> dict [str , str ]:
157157 """Extract version information from the given file."""
158158 # the code embedded in _version.py can just fetch the value of these
159159 # keywords. When used from setup.py, we don't want to import _version.py,
160160 # so we do it with a regexp instead. This function is not used from
161161 # _version.py.
162- keywords : Dict [str , str ] = {}
162+ keywords : dict [str , str ] = {}
163163 try :
164164 with open (versionfile_abs , "r" ) as fobj :
165165 for line in fobj :
@@ -182,10 +182,10 @@ def git_get_keywords(versionfile_abs: str) -> Dict[str, str]:
182182
183183@register_vcs_handler ("git" , "keywords" )
184184def git_versions_from_keywords (
185- keywords : Dict [str , str ],
185+ keywords : dict [str , str ],
186186 tag_prefix : str ,
187187 verbose : bool ,
188- ) -> Dict [str , Any ]:
188+ ) -> dict [str , Any ]:
189189 """Get version information from git keywords."""
190190 if "refnames" not in keywords :
191191 raise NotThisMethod ("Short version file found" )
@@ -254,7 +254,7 @@ def git_pieces_from_vcs(
254254 root : str ,
255255 verbose : bool ,
256256 runner : Callable = run_command
257- ) -> Dict [str , Any ]:
257+ ) -> dict [str , Any ]:
258258 """Get version from 'git describe' in the root of the source tree.
259259
260260 This only gets called if the git-archive 'subst' keywords were *not*
@@ -294,7 +294,7 @@ def git_pieces_from_vcs(
294294 raise NotThisMethod ("'git rev-parse' failed" )
295295 full_out = full_out .strip ()
296296
297- pieces : Dict [str , Any ] = {}
297+ pieces : dict [str , Any ] = {}
298298 pieces ["long" ] = full_out
299299 pieces ["short" ] = full_out [:7 ] # maybe improved later
300300 pieces ["error" ] = None
@@ -386,14 +386,14 @@ def git_pieces_from_vcs(
386386 return pieces
387387
388388
389- def plus_or_dot (pieces : Dict [str , Any ]) -> str :
389+ def plus_or_dot (pieces : dict [str , Any ]) -> str :
390390 """Return a + if we don't already have one, else return a ."""
391391 if "+" in pieces .get ("closest-tag" , "" ):
392392 return "."
393393 return "+"
394394
395395
396- def render_pep440 (pieces : Dict [str , Any ]) -> str :
396+ def render_pep440 (pieces : dict [str , Any ]) -> str :
397397 """Build up version string, with post-release "local version identifier".
398398
399399 Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
@@ -418,7 +418,7 @@ def render_pep440(pieces: Dict[str, Any]) -> str:
418418 return rendered
419419
420420
421- def render_pep440_branch (pieces : Dict [str , Any ]) -> str :
421+ def render_pep440_branch (pieces : dict [str , Any ]) -> str :
422422 """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] .
423423
424424 The ".dev0" means not master branch. Note that .dev0 sorts backwards
@@ -448,7 +448,7 @@ def render_pep440_branch(pieces: Dict[str, Any]) -> str:
448448 return rendered
449449
450450
451- def pep440_split_post (ver : str ) -> Tuple [str , Optional [ int ] ]:
451+ def pep440_split_post (ver : str ) -> tuple [str , int | None ]:
452452 """Split pep440 version string at the post-release segment.
453453
454454 Returns the release segments before the post-release and the
@@ -458,7 +458,7 @@ def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]:
458458 return vc [0 ], int (vc [1 ] or 0 ) if len (vc ) == 2 else None
459459
460460
461- def render_pep440_pre (pieces : Dict [str , Any ]) -> str :
461+ def render_pep440_pre (pieces : dict [str , Any ]) -> str :
462462 """TAG[.postN.devDISTANCE] -- No -dirty.
463463
464464 Exceptions:
@@ -482,7 +482,7 @@ def render_pep440_pre(pieces: Dict[str, Any]) -> str:
482482 return rendered
483483
484484
485- def render_pep440_post (pieces : Dict [str , Any ]) -> str :
485+ def render_pep440_post (pieces : dict [str , Any ]) -> str :
486486 """TAG[.postDISTANCE[.dev0]+gHEX] .
487487
488488 The ".dev0" means dirty. Note that .dev0 sorts backwards
@@ -509,7 +509,7 @@ def render_pep440_post(pieces: Dict[str, Any]) -> str:
509509 return rendered
510510
511511
512- def render_pep440_post_branch (pieces : Dict [str , Any ]) -> str :
512+ def render_pep440_post_branch (pieces : dict [str , Any ]) -> str :
513513 """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] .
514514
515515 The ".dev0" means not master branch.
@@ -538,7 +538,7 @@ def render_pep440_post_branch(pieces: Dict[str, Any]) -> str:
538538 return rendered
539539
540540
541- def render_pep440_old (pieces : Dict [str , Any ]) -> str :
541+ def render_pep440_old (pieces : dict [str , Any ]) -> str :
542542 """TAG[.postDISTANCE[.dev0]] .
543543
544544 The ".dev0" means dirty.
@@ -560,7 +560,7 @@ def render_pep440_old(pieces: Dict[str, Any]) -> str:
560560 return rendered
561561
562562
563- def render_git_describe (pieces : Dict [str , Any ]) -> str :
563+ def render_git_describe (pieces : dict [str , Any ]) -> str :
564564 """TAG[-DISTANCE-gHEX][-dirty].
565565
566566 Like 'git describe --tags --dirty --always'.
@@ -580,7 +580,7 @@ def render_git_describe(pieces: Dict[str, Any]) -> str:
580580 return rendered
581581
582582
583- def render_git_describe_long (pieces : Dict [str , Any ]) -> str :
583+ def render_git_describe_long (pieces : dict [str , Any ]) -> str :
584584 """TAG-DISTANCE-gHEX[-dirty].
585585
586586 Like 'git describe --tags --dirty --always -long'.
@@ -600,7 +600,7 @@ def render_git_describe_long(pieces: Dict[str, Any]) -> str:
600600 return rendered
601601
602602
603- def render (pieces : Dict [str , Any ], style : str ) -> Dict [str , Any ]:
603+ def render (pieces : dict [str , Any ], style : str ) -> dict [str , Any ]:
604604 """Render the given version pieces into the requested style."""
605605 if pieces ["error" ]:
606606 return {"version" : "unknown" ,
@@ -636,7 +636,7 @@ def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
636636 "date" : pieces .get ("date" )}
637637
638638
639- def get_versions () -> Dict [str , Any ]:
639+ def get_versions () -> dict [str , Any ]:
640640 """Get version information or return default if unable to do so."""
641641 # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
642642 # __file__, we can work backwards from there to the root. Some
0 commit comments