@@ -47,8 +47,6 @@ class SearchPaths(NamedTuple):
47
47
48
48
PYTHON_EXTENSIONS : Final = [".pyi" , ".py" ]
49
49
50
- PYTHON2_STUB_DIR : Final = "@python2"
51
-
52
50
53
51
# TODO: Consider adding more reasons here?
54
52
# E.g. if we deduce a module would likely be found if the user were
@@ -192,7 +190,6 @@ def __init__(
192
190
self .stdlib_py_versions = stdlib_py_versions or load_stdlib_py_versions (
193
191
custom_typeshed_dir
194
192
)
195
- self .python_major_ver = 3 if options is None else options .python_version [0 ]
196
193
197
194
def clear (self ) -> None :
198
195
self .results .clear ()
@@ -292,9 +289,6 @@ def get_toplevel_possibilities(self, lib_path: Tuple[str, ...], id: str) -> List
292
289
name = os .path .splitext (name )[0 ]
293
290
components .setdefault (name , []).append (dir )
294
291
295
- if self .python_major_ver == 2 :
296
- components = {id : filter_redundant_py2_dirs (dirs ) for id , dirs in components .items ()}
297
-
298
292
self .initial_components [lib_path ] = components
299
293
return components .get (id , [])
300
294
@@ -439,12 +433,6 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
439
433
for pkg_dir in self .search_paths .package_path :
440
434
stub_name = components [0 ] + "-stubs"
441
435
stub_dir = os .path .join (pkg_dir , stub_name )
442
- if self .python_major_ver == 2 :
443
- alt_stub_name = components [0 ] + "-python2-stubs"
444
- alt_stub_dir = os .path .join (pkg_dir , alt_stub_name )
445
- if fscache .isdir (alt_stub_dir ):
446
- stub_name = alt_stub_name
447
- stub_dir = alt_stub_dir
448
436
if fscache .isdir (stub_dir ) and self ._is_compatible_stub_package (stub_dir ):
449
437
stub_typed_file = os .path .join (stub_dir , "py.typed" )
450
438
stub_components = [stub_name ] + components [1 :]
@@ -506,11 +494,7 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
506
494
# Prefer package over module, i.e. baz/__init__.py* over baz.py*.
507
495
for extension in PYTHON_EXTENSIONS :
508
496
path = base_path + sepinit + extension
509
- suffix = "-stubs"
510
- if self .python_major_ver == 2 :
511
- if os .path .isdir (base_path + "-python2-stubs" ):
512
- suffix = "-python2-stubs"
513
- path_stubs = base_path + suffix + sepinit + extension
497
+ path_stubs = base_path + "-stubs" + sepinit + extension
514
498
if fscache .isfile_case (path , dir_prefix ):
515
499
has_init = True
516
500
if verify and not verify_module (fscache , id , path , dir_prefix ):
@@ -591,10 +575,7 @@ def _is_compatible_stub_package(self, stub_dir: str) -> bool:
591
575
if os .path .isfile (metadata_fnam ):
592
576
with open (metadata_fnam , "rb" ) as f :
593
577
metadata = tomllib .load (f )
594
- if self .python_major_ver == 2 :
595
- return bool (metadata .get ("python2" , False ))
596
- else :
597
- return bool (metadata .get ("python3" , True ))
578
+ return bool (metadata .get ("python3" , True ))
598
579
return True
599
580
600
581
def find_modules_recursive (self , module : str ) -> List [BuildSource ]:
@@ -726,10 +707,6 @@ def default_lib_path(
726
707
data_dir = auto
727
708
typeshed_dir = os .path .join (data_dir , "typeshed" , "stdlib" )
728
709
mypy_extensions_dir = os .path .join (data_dir , "typeshed" , "stubs" , "mypy-extensions" )
729
- if pyversion [0 ] == 2 :
730
- # Python 2 variants of certain stdlib modules are in a separate directory.
731
- python2_dir = os .path .join (typeshed_dir , PYTHON2_STUB_DIR )
732
- path .append (python2_dir )
733
710
path .append (typeshed_dir )
734
711
735
712
# Get mypy-extensions stubs from typeshed, since we treat it as an
@@ -782,25 +759,6 @@ def get_search_dirs(python_executable: Optional[str]) -> Tuple[List[str], List[s
782
759
return sys_path , site_packages
783
760
784
761
785
- def add_py2_mypypath_entries (mypypath : List [str ]) -> List [str ]:
786
- """Add corresponding @python2 subdirectories to mypypath.
787
-
788
- For each path entry 'x', add 'x/@python2' before 'x' if the latter is
789
- a directory.
790
- """
791
- result = []
792
- for item in mypypath :
793
- python2_dir = os .path .join (item , PYTHON2_STUB_DIR )
794
- if os .path .isdir (python2_dir ):
795
- # @python2 takes precedence, but we also look into the parent
796
- # directory.
797
- result .append (python2_dir )
798
- result .append (item )
799
- else :
800
- result .append (item )
801
- return result
802
-
803
-
804
762
def compute_search_paths (
805
763
sources : List [BuildSource ], options : Options , data_dir : str , alt_lib_path : Optional [str ] = None
806
764
) -> SearchPaths :
@@ -863,11 +821,6 @@ def compute_search_paths(
863
821
if alt_lib_path :
864
822
mypypath .insert (0 , alt_lib_path )
865
823
866
- # When type checking in Python 2 module, add @python2 subdirectories of
867
- # path items into the search path.
868
- if options .python_version [0 ] == 2 :
869
- mypypath = add_py2_mypypath_entries (mypypath )
870
-
871
824
sys_path , site_packages = get_search_dirs (options .python_executable )
872
825
# We only use site packages for this check
873
826
for site in site_packages :
@@ -919,19 +872,6 @@ def load_stdlib_py_versions(custom_typeshed_dir: Optional[str]) -> StdlibVersion
919
872
parse_version (versions [1 ]) if len (versions ) >= 2 and versions [1 ].strip () else None
920
873
)
921
874
result [module ] = min_version , max_version
922
-
923
- # Modules that are Python 2 only or have separate Python 2 stubs
924
- # have stubs in @python2/ and may need an override.
925
- python2_dir = os .path .join (stdlib_dir , PYTHON2_STUB_DIR )
926
- try :
927
- for fnam in os .listdir (python2_dir ):
928
- fnam = fnam .replace (".pyi" , "" )
929
- max_version = result .get (fnam , ((2 , 7 ), None ))[1 ]
930
- result [fnam ] = (2 , 7 ), max_version
931
- except FileNotFoundError :
932
- # Ignore error to support installations where Python 2 stubs aren't available.
933
- pass
934
-
935
875
return result
936
876
937
877
@@ -944,23 +884,4 @@ def typeshed_py_version(options: Options) -> Tuple[int, int]:
944
884
"""Return Python version used for checking whether module supports typeshed."""
945
885
# Typeshed no longer covers Python 3.x versions before 3.6, so 3.6 is
946
886
# the earliest we can support.
947
- if options .python_version [0 ] >= 3 :
948
- return max (options .python_version , (3 , 6 ))
949
- else :
950
- return options .python_version
951
-
952
-
953
- def filter_redundant_py2_dirs (dirs : List [str ]) -> List [str ]:
954
- """If dirs has <dir>/@python2 followed by <dir>, filter out the latter."""
955
- if len (dirs ) <= 1 or not any (d .endswith (PYTHON2_STUB_DIR ) for d in dirs ):
956
- # Fast path -- nothing to do
957
- return dirs
958
- seen = []
959
- result = []
960
- for d in dirs :
961
- if d .endswith (PYTHON2_STUB_DIR ):
962
- seen .append (os .path .dirname (d ))
963
- result .append (d )
964
- elif d not in seen :
965
- result .append (d )
966
- return result
887
+ return max (options .python_version , (3 , 6 ))
0 commit comments