1212import tempfile
1313import time
1414from collections import defaultdict
15+ from collections .abc import Sequence
1516from dataclasses import dataclass
1617from itertools import product
1718from pathlib import Path
1819from threading import Lock
19- from typing import TYPE_CHECKING , Any , NamedTuple
20+ from typing import TYPE_CHECKING , Any , NamedTuple , Tuple
2021
2122if TYPE_CHECKING :
2223 from _typeshed import StrPath
5354
5455ReturnCode : TypeAlias = int
5556VersionString : TypeAlias = Annotated [str , "Must be one of the entries in SUPPORTED_VERSIONS" ]
56- VersionTuple : TypeAlias = tuple [int , int ]
57+ VersionTuple : TypeAlias = Tuple [int , int ]
5758Platform : TypeAlias = Annotated [str , "Must be one of the entries in SUPPORTED_PLATFORMS" ]
5859
5960
@@ -78,6 +79,21 @@ def valid_path(cmd_arg: str) -> Path:
7879parser = argparse .ArgumentParser (
7980 description = "Typecheck typeshed's stubs with mypy. Patterns are unanchored regexps on the full path."
8081)
82+ if sys .version_info < (3 , 8 ):
83+
84+ class ExtendAction (argparse .Action ):
85+ def __call__ (
86+ self ,
87+ parser : argparse .ArgumentParser ,
88+ namespace : argparse .Namespace ,
89+ values : Sequence [str ],
90+ option_string : object = None ,
91+ ) -> None :
92+ items = getattr (namespace , self .dest ) or []
93+ items .extend (values )
94+ setattr (namespace , self .dest , items )
95+
96+ parser .register ("action" , "extend" , ExtendAction )
8197parser .add_argument (
8298 "filter" ,
8399 type = valid_path ,
@@ -324,7 +340,7 @@ def test_third_party_distribution(
324340
325341 mypypath = os .pathsep .join (str (Path ("stubs" , dist )) for dist in seen_dists )
326342 if args .verbose :
327- print (colored (f"\n { mypypath = } " , "blue" ))
343+ print (colored (f"\n MYPYPATH= { mypypath } " , "blue" ))
328344 code = run_mypy (
329345 args ,
330346 configurations ,
0 commit comments