From 8628fa0b842162b03621e56fbf4fe337a3fd50c8 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 24 May 2021 17:20:18 +0100 Subject: [PATCH] Move mypy_extensions stubs to typeshed/stubs/mypy-extensions (#10527) This fixes `--custom-typeshed-dir`. --- misc/sync-typeshed.py | 13 ++++++++----- mypy/modulefinder.py | 6 ++++++ mypy/typeshed/stubs/mypy-extensions/METADATA.toml | 2 ++ .../mypy-extensions}/mypy_extensions.pyi | 0 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 mypy/typeshed/stubs/mypy-extensions/METADATA.toml rename mypy/typeshed/{stdlib => stubs/mypy-extensions}/mypy_extensions.pyi (100%) diff --git a/misc/sync-typeshed.py b/misc/sync-typeshed.py index fb2e42e48b5b..631cc7682514 100644 --- a/misc/sync-typeshed.py +++ b/misc/sync-typeshed.py @@ -37,15 +37,18 @@ def update_typeshed(typeshed_dir: str, commit: Optional[str]) -> str: if commit: subprocess.run(['git', 'checkout', commit], check=True, cwd=typeshed_dir) commit = git_head_commit(typeshed_dir) - stub_dir = os.path.join('mypy', 'typeshed', 'stdlib') + stdlib_dir = os.path.join('mypy', 'typeshed', 'stdlib') # Remove existing stubs. - shutil.rmtree(stub_dir) + shutil.rmtree(stdlib_dir) # Copy new stdlib stubs. - shutil.copytree(os.path.join(typeshed_dir, 'stdlib'), stub_dir) + shutil.copytree(os.path.join(typeshed_dir, 'stdlib'), stdlib_dir) # Copy mypy_extensions stubs. We don't want to use a stub package, since it's # treated specially by mypy and we make assumptions about what's there. - shutil.copy(os.path.join(typeshed_dir, 'stubs', 'mypy-extensions', 'mypy_extensions.pyi'), - stub_dir) + stubs_dir = os.path.join('mypy', 'typeshed', 'stubs') + shutil.rmtree(stubs_dir) + os.makedirs(stubs_dir) + shutil.copytree(os.path.join(typeshed_dir, 'stubs', 'mypy-extensions'), + os.path.join(stubs_dir, 'mypy-extensions')) return commit diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index c53396e2be91..8f23299be064 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -544,6 +544,7 @@ def default_lib_path(data_dir: str, if custom_typeshed_dir: typeshed_dir = os.path.join(custom_typeshed_dir, "stdlib") + mypy_extensions_dir = os.path.join(custom_typeshed_dir, "stubs", "mypy-extensions") versions_file = os.path.join(typeshed_dir, "VERSIONS") if not os.path.isdir(typeshed_dir) or not os.path.isfile(versions_file): print("error: --custom-typeshed-dir does not point to a valid typeshed ({})".format( @@ -554,12 +555,17 @@ def default_lib_path(data_dir: str, if os.path.isdir(auto): data_dir = auto typeshed_dir = os.path.join(data_dir, "typeshed", "stdlib") + mypy_extensions_dir = os.path.join(data_dir, "typeshed", "stubs", "mypy-extensions") if pyversion[0] == 2: # Python 2 variants of certain stdlib modules are in a separate directory. python2_dir = os.path.join(typeshed_dir, PYTHON2_STUB_DIR) path.append(python2_dir) path.append(typeshed_dir) + # Get mypy-extensions stubs from typeshed, since we treat it as an + # "internal" library, similar to typing and typing-extensions. + path.append(mypy_extensions_dir) + # Add fallback path that can be used if we have a broken installation. if sys.platform != 'win32': path.append('/usr/local/lib/mypy') diff --git a/mypy/typeshed/stubs/mypy-extensions/METADATA.toml b/mypy/typeshed/stubs/mypy-extensions/METADATA.toml new file mode 100644 index 000000000000..8732c02c405f --- /dev/null +++ b/mypy/typeshed/stubs/mypy-extensions/METADATA.toml @@ -0,0 +1,2 @@ +version = "0.4" +python2 = true diff --git a/mypy/typeshed/stdlib/mypy_extensions.pyi b/mypy/typeshed/stubs/mypy-extensions/mypy_extensions.pyi similarity index 100% rename from mypy/typeshed/stdlib/mypy_extensions.pyi rename to mypy/typeshed/stubs/mypy-extensions/mypy_extensions.pyi