Skip to content

Commit

Permalink
Move mypy_extensions stubs to typeshed/stubs/mypy-extensions (python#…
Browse files Browse the repository at this point in the history
…10527)

This fixes `--custom-typeshed-dir`.
  • Loading branch information
JukkaL committed May 24, 2021
1 parent b633ae1 commit 8628fa0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions misc/sync-typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 6 additions & 0 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stubs/mypy-extensions/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "0.4"
python2 = true
File renamed without changes.

0 comments on commit 8628fa0

Please sign in to comment.