1616import re
1717import subprocess
1818import sys
19- from typing import Any , Callable , Dict , List , Optional , Tuple
19+ from collections .abc import Callable
20+ from typing import Any
2021
2122
22- def get_keywords () -> Dict [str , str ]:
23+ def get_keywords () -> dict [str , str ]:
2324 """Get the keywords needed to look up the version information."""
2425 # these strings will be replaced by git during git-archive.
2526 # setup.py/versioneer.py will grep for the variable names, so they must
@@ -61,8 +62,8 @@ class NotThisMethod(Exception):
6162 """Exception raised if a method is not valid for the current scenario."""
6263
6364
64- LONG_VERSION_PY : Dict [str , str ] = {}
65- HANDLERS : Dict [str , Dict [str , Callable ]] = {}
65+ LONG_VERSION_PY : dict [str , str ] = {}
66+ HANDLERS : dict [str , dict [str , Callable ]] = {}
6667
6768
6869def register_vcs_handler (vcs : str , method : str ) -> Callable : # decorator
@@ -79,18 +80,18 @@ def decorate(f: Callable) -> Callable:
7980
8081
8182def run_command (
82- commands : List [str ],
83- args : List [str ],
84- cwd : Optional [ str ] = None ,
83+ commands : list [str ],
84+ args : list [str ],
85+ cwd : str | None = None ,
8586 verbose : bool = False ,
8687 hide_stderr : bool = False ,
87- env : Optional [ Dict [ str , str ]] = None ,
88- ) -> Tuple [ Optional [ str ], Optional [ int ] ]:
88+ env : dict [ str , str ] | None = None ,
89+ ) -> tuple [ str | None , int | None ]:
8990 """Call the given command(s)."""
9091 assert isinstance (commands , list )
9192 process = None
9293
93- popen_kwargs : Dict [str , Any ] = {}
94+ popen_kwargs : dict [str , Any ] = {}
9495 if sys .platform == "win32" :
9596 # This hides the console window if pythonw.exe is used
9697 startupinfo = subprocess .STARTUPINFO ()
@@ -119,7 +120,7 @@ def run_command(
119120 return None , None
120121 else :
121122 if verbose :
122- print ("unable to find command, tried %s" % ( commands ,) )
123+ print (f "unable to find command, tried { commands } " )
123124 return None , None
124125 stdout = process .communicate ()[0 ].strip ().decode ()
125126 if process .returncode != 0 :
@@ -134,7 +135,7 @@ def versions_from_parentdir(
134135 parentdir_prefix : str ,
135136 root : str ,
136137 verbose : bool ,
137- ) -> Dict [str , Any ]:
138+ ) -> dict [str , Any ]:
138139 """Try to determine the version from the parent directory name.
139140
140141 Source tarballs conventionally unpack into a directory that includes both
@@ -165,15 +166,15 @@ def versions_from_parentdir(
165166
166167
167168@register_vcs_handler ("git" , "get_keywords" )
168- def git_get_keywords (versionfile_abs : str ) -> Dict [str , str ]:
169+ def git_get_keywords (versionfile_abs : str ) -> dict [str , str ]:
169170 """Extract version information from the given file."""
170171 # the code embedded in _version.py can just fetch the value of these
171172 # keywords. When used from setup.py, we don't want to import _version.py,
172173 # so we do it with a regexp instead. This function is not used from
173174 # _version.py.
174- keywords : Dict [str , str ] = {}
175+ keywords : dict [str , str ] = {}
175176 try :
176- with open (versionfile_abs , "r" ) as fobj :
177+ with open (versionfile_abs ) as fobj :
177178 for line in fobj :
178179 if line .strip ().startswith ("git_refnames =" ):
179180 mo = re .search (r'=\s*"(.*)"' , line )
@@ -194,10 +195,10 @@ def git_get_keywords(versionfile_abs: str) -> Dict[str, str]:
194195
195196@register_vcs_handler ("git" , "keywords" )
196197def git_versions_from_keywords (
197- keywords : Dict [str , str ],
198+ keywords : dict [str , str ],
198199 tag_prefix : str ,
199200 verbose : bool ,
200- ) -> Dict [str , Any ]:
201+ ) -> dict [str , Any ]:
201202 """Get version information from git keywords."""
202203 if "refnames" not in keywords :
203204 raise NotThisMethod ("Short version file found" )
@@ -270,7 +271,7 @@ def git_versions_from_keywords(
270271@register_vcs_handler ("git" , "pieces_from_vcs" )
271272def git_pieces_from_vcs (
272273 tag_prefix : str , root : str , verbose : bool , runner : Callable = run_command
273- ) -> Dict [str , Any ]:
274+ ) -> dict [str , Any ]:
274275 """Get version from 'git describe' in the root of the source tree.
275276
276277 This only gets called if the git-archive 'subst' keywords were *not*
@@ -318,7 +319,7 @@ def git_pieces_from_vcs(
318319 raise NotThisMethod ("'git rev-parse' failed" )
319320 full_out = full_out .strip ()
320321
321- pieces : Dict [str , Any ] = {}
322+ pieces : dict [str , Any ] = {}
322323 pieces ["long" ] = full_out
323324 pieces ["short" ] = full_out [:7 ] # maybe improved later
324325 pieces ["error" ] = None
@@ -383,7 +384,7 @@ def git_pieces_from_vcs(
383384 if verbose :
384385 fmt = "tag '%s' doesn't start with prefix '%s'"
385386 print (fmt % (full_tag , tag_prefix ))
386- pieces ["error" ] = "tag '%s ' doesn't start with prefix '%s'" % (
387+ pieces ["error" ] = "tag '{} ' doesn't start with prefix '{}'" . format (
387388 full_tag ,
388389 tag_prefix ,
389390 )
@@ -417,14 +418,14 @@ def git_pieces_from_vcs(
417418 return pieces
418419
419420
420- def plus_or_dot (pieces : Dict [str , Any ]) -> str :
421+ def plus_or_dot (pieces : dict [str , Any ]) -> str :
421422 """Return a + if we don't already have one, else return a ."""
422423 if "+" in pieces .get ("closest-tag" , "" ):
423424 return "."
424425 return "+"
425426
426427
427- def render_pep440 (pieces : Dict [str , Any ]) -> str :
428+ def render_pep440 (pieces : dict [str , Any ]) -> str :
428429 """Build up version string, with post-release "local version identifier".
429430
430431 Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
@@ -448,7 +449,7 @@ def render_pep440(pieces: Dict[str, Any]) -> str:
448449 return rendered
449450
450451
451- def render_pep440_branch (pieces : Dict [str , Any ]) -> str :
452+ def render_pep440_branch (pieces : dict [str , Any ]) -> str :
452453 """TAG[[.dev0]+DISTANCE.gHEX[.dirty]] .
453454
454455 The ".dev0" means not master branch. Note that .dev0 sorts backwards
@@ -477,7 +478,7 @@ def render_pep440_branch(pieces: Dict[str, Any]) -> str:
477478 return rendered
478479
479480
480- def pep440_split_post (ver : str ) -> Tuple [str , Optional [ int ] ]:
481+ def pep440_split_post (ver : str ) -> tuple [str , int | None ]:
481482 """Split pep440 version string at the post-release segment.
482483
483484 Returns the release segments before the post-release and the
@@ -487,7 +488,7 @@ def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]:
487488 return vc [0 ], int (vc [1 ] or 0 ) if len (vc ) == 2 else None
488489
489490
490- def render_pep440_pre (pieces : Dict [str , Any ]) -> str :
491+ def render_pep440_pre (pieces : dict [str , Any ]) -> str :
491492 """TAG[.postN.devDISTANCE] -- No -dirty.
492493
493494 Exceptions:
@@ -511,7 +512,7 @@ def render_pep440_pre(pieces: Dict[str, Any]) -> str:
511512 return rendered
512513
513514
514- def render_pep440_post (pieces : Dict [str , Any ]) -> str :
515+ def render_pep440_post (pieces : dict [str , Any ]) -> str :
515516 """TAG[.postDISTANCE[.dev0]+gHEX] .
516517
517518 The ".dev0" means dirty. Note that .dev0 sorts backwards
@@ -538,7 +539,7 @@ def render_pep440_post(pieces: Dict[str, Any]) -> str:
538539 return rendered
539540
540541
541- def render_pep440_post_branch (pieces : Dict [str , Any ]) -> str :
542+ def render_pep440_post_branch (pieces : dict [str , Any ]) -> str :
542543 """TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] .
543544
544545 The ".dev0" means not master branch.
@@ -567,7 +568,7 @@ def render_pep440_post_branch(pieces: Dict[str, Any]) -> str:
567568 return rendered
568569
569570
570- def render_pep440_old (pieces : Dict [str , Any ]) -> str :
571+ def render_pep440_old (pieces : dict [str , Any ]) -> str :
571572 """TAG[.postDISTANCE[.dev0]] .
572573
573574 The ".dev0" means dirty.
@@ -589,7 +590,7 @@ def render_pep440_old(pieces: Dict[str, Any]) -> str:
589590 return rendered
590591
591592
592- def render_git_describe (pieces : Dict [str , Any ]) -> str :
593+ def render_git_describe (pieces : dict [str , Any ]) -> str :
593594 """TAG[-DISTANCE-gHEX][-dirty].
594595
595596 Like 'git describe --tags --dirty --always'.
@@ -609,7 +610,7 @@ def render_git_describe(pieces: Dict[str, Any]) -> str:
609610 return rendered
610611
611612
612- def render_git_describe_long (pieces : Dict [str , Any ]) -> str :
613+ def render_git_describe_long (pieces : dict [str , Any ]) -> str :
613614 """TAG-DISTANCE-gHEX[-dirty].
614615
615616 Like 'git describe --tags --dirty --always -long'.
@@ -629,7 +630,7 @@ def render_git_describe_long(pieces: Dict[str, Any]) -> str:
629630 return rendered
630631
631632
632- def render (pieces : Dict [str , Any ], style : str ) -> Dict [str , Any ]:
633+ def render (pieces : dict [str , Any ], style : str ) -> dict [str , Any ]:
633634 """Render the given version pieces into the requested style."""
634635 if pieces ["error" ]:
635636 return {
@@ -671,7 +672,7 @@ def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
671672 }
672673
673674
674- def get_versions () -> Dict [str , Any ]:
675+ def get_versions () -> dict [str , Any ]:
675676 """Get version information or return default if unable to do so."""
676677 # I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
677678 # __file__, we can work backwards from there to the root. Some
0 commit comments