Skip to content

Commit 0ffd193

Browse files
committed
Create mypy_extensions package.
1 parent 7e2b3b4 commit 0ffd193

File tree

5 files changed

+115
-36
lines changed

5 files changed

+115
-36
lines changed

extensions/mypy_extensions/__init__.py

Whitespace-only changes.

extensions/mypy_extensions/typing.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import cast, Dict, Type, TypeVar
2+
3+
4+
_T = TypeVar('_T')
5+
6+
7+
def TypedDict(typename: str, fields: Dict[str, Type[_T]]) -> Type[dict]:
8+
"""TypedDict creates a dictionary type that expects all of its
9+
instances to have a certain common set of keys, with each key
10+
associated with a value of a consistent type. This expectation
11+
is not checked at runtime but is only enforced by typecheckers.
12+
"""
13+
def new_dict(*args, **kwargs):
14+
return dict(*args, **kwargs)
15+
16+
new_dict.__name__ = typename # type: ignore # https://github.com/python/mypy/issues/708
17+
new_dict.__supertype__ = dict # type: ignore # https://github.com/python/mypy/issues/708
18+
return cast(Type[dict], new_dict)

extensions/setup.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
3+
from distutils.core import setup
4+
import sys
5+
6+
if '..' not in sys.path:
7+
sys.path.insert(0, '..')
8+
import setup as mypy_setup
9+
10+
description = 'Experimental type system extensions for programs checked with the mypy typechecker.'
11+
long_description = '''
12+
Mypy Extensions
13+
===============
14+
15+
The "mypy_extensions.typing" module defines experimental extensions to the
16+
standard "typing" module that are supported by the mypy typechecker.
17+
'''.lstrip()
18+
19+
20+
setup(
21+
name='mypy_extensions',
22+
version=mypy_setup.setup_kwargs['version'],
23+
description=description,
24+
long_description=long_description,
25+
author=mypy_setup.setup_kwargs['author'],
26+
author_email=mypy_setup.setup_kwargs['author_email'],
27+
url=mypy_setup.setup_kwargs['url'],
28+
license=mypy_setup.setup_kwargs['license'],
29+
platforms=mypy_setup.setup_kwargs['platforms'],
30+
package_dir={'mypy_extensions': 'mypy_extensions'},
31+
py_modules=['mypy_extensions'],
32+
packages=['mypy_extensions'],
33+
scripts=[],
34+
data_files=mypy_setup.find_data_files('mypy_extensions', ['*.py', '*.pyi']),
35+
classifiers=mypy_setup.setup_kwargs['classifiers'],
36+
)

mypy/git.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
"""Utilities for verifying git integrity."""
22

3+
from __future__ import print_function
4+
35
# Used also from setup.py, so don't pull in anything additional here (like mypy or typing):
46
import os
57
import pipes
68
import subprocess
79
import sys
810

911

10-
def is_git_repo(dir: str) -> bool:
12+
# NOTE: Cannot use typing.TYPE_CHECKING guard here because cannot import
13+
# "typing" in this file at all.
14+
if False:
15+
from typing import Iterator
16+
17+
18+
def is_git_repo(dir):
19+
# type: (str) -> bool
1120
"""Is the given directory version-controlled with git?"""
1221
return os.path.exists(os.path.join(dir, ".git"))
1322

1423

15-
def have_git() -> bool:
24+
def have_git():
25+
# type: () -> bool
1626
"""Can we run the git executable?"""
1727
try:
1828
subprocess.check_output(["git", "--help"])
@@ -23,7 +33,8 @@ def have_git() -> bool:
2333
return False
2434

2535

26-
def get_submodules(dir: str):
36+
def get_submodules(dir):
37+
# type: (str) -> Iterator[str]
2738
"""Return a list of all git top-level submodules in a given directory."""
2839
# It would be nicer to do
2940
# "git submodule foreach 'echo MODULE $name $path $sha1 $toplevel'"
@@ -41,67 +52,77 @@ def get_submodules(dir: str):
4152
yield name.decode(sys.getfilesystemencoding())
4253

4354

44-
def git_revision(dir: str) -> bytes:
55+
def git_revision(dir):
56+
# type: (str) -> bytes
4557
"""Get the SHA-1 of the HEAD of a git repository."""
4658
return subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=dir).strip()
4759

4860

49-
def submodule_revision(dir: str, submodule: str) -> bytes:
61+
def submodule_revision(dir, submodule):
62+
# type: (str, str) -> bytes
5063
"""Get the SHA-1 a submodule is supposed to have."""
5164
output = subprocess.check_output(["git", "ls-files", "-s", submodule], cwd=dir).strip()
5265
# E.g.: "160000 e4a7edb949e0b920b16f61aeeb19fc3d328f3012 0 typeshed"
5366
return output.split()[1]
5467

5568

56-
def is_dirty(dir: str) -> bool:
69+
def is_dirty(dir):
70+
# type: (str) -> bool
5771
"""Check whether a git repository has uncommitted changes."""
5872
output = subprocess.check_output(["git", "status", "-uno", "--porcelain"], cwd=dir)
5973
return output.strip() != b""
6074

6175

62-
def has_extra_files(dir: str) -> bool:
76+
def has_extra_files(dir):
77+
# type: (str) -> bool
6378
"""Check whether a git repository has untracked files."""
6479
output = subprocess.check_output(["git", "clean", "--dry-run", "-d"], cwd=dir)
6580
return output.strip() != b""
6681

6782

68-
def warn_no_git_executable() -> None:
83+
def warn_no_git_executable():
84+
# type: () -> None
6985
print("Warning: Couldn't check git integrity. "
7086
"git executable not in path.", file=sys.stderr)
7187

7288

73-
def warn_dirty(dir: str) -> None:
89+
def warn_dirty(dir):
90+
# type: (str) -> None
7491
print("Warning: git module '{}' has uncommitted changes.".format(dir),
7592
file=sys.stderr)
7693
print("Go to the directory", file=sys.stderr)
7794
print(" {}".format(dir), file=sys.stderr)
7895
print("and commit or reset your changes", file=sys.stderr)
7996

8097

81-
def warn_extra_files(dir: str) -> None:
98+
def warn_extra_files(dir):
99+
# type: (str) -> None
82100
print("Warning: git module '{}' has untracked files.".format(dir),
83101
file=sys.stderr)
84102
print("Go to the directory", file=sys.stderr)
85103
print(" {}".format(dir), file=sys.stderr)
86104
print("and add & commit your new files.", file=sys.stderr)
87105

88106

89-
def chdir_prefix(dir: str) -> str:
107+
def chdir_prefix(dir):
108+
# type: (str) -> str
90109
"""Return the command to change to the target directory, plus '&&'."""
91110
if os.path.relpath(dir) != ".":
92111
return "cd " + pipes.quote(dir) + " && "
93112
else:
94113
return ""
95114

96115

97-
def error_submodule_not_initialized(name: str, dir: str) -> None:
116+
def error_submodule_not_initialized(name, dir):
117+
# type: (str, str) -> None
98118
print("Submodule '{}' not initialized.".format(name), file=sys.stderr)
99119
print("Please run:", file=sys.stderr)
100120
print(" {}git submodule update --init {}".format(
101121
chdir_prefix(dir), name), file=sys.stderr)
102122

103123

104-
def error_submodule_not_updated(name: str, dir: str) -> None:
124+
def error_submodule_not_updated(name, dir):
125+
# type: (str, str) -> None
105126
print("Submodule '{}' not updated.".format(name), file=sys.stderr)
106127
print("Please run:", file=sys.stderr)
107128
print(" {}git submodule update {}".format(
@@ -110,7 +131,8 @@ def error_submodule_not_updated(name: str, dir: str) -> None:
110131
print(" then run \"git add {}\" to silence this check)".format(name), file=sys.stderr)
111132

112133

113-
def verify_git_integrity_or_abort(datadir: str) -> None:
134+
def verify_git_integrity_or_abort(datadir):
135+
# type: (str) -> None
114136
"""Verify the (submodule) integrity of a git repository.
115137
116138
Potentially output warnings/errors (to stderr), and exit with status 1

setup.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
import os.path
66
import sys
77

8-
if sys.version_info < (3, 2, 0):
9-
sys.stderr.write("ERROR: You need Python 3.2 or later to use mypy.\n")
10-
exit(1)
8+
if __name__ == '__main__':
9+
if sys.version_info < (3, 2, 0):
10+
sys.stderr.write("ERROR: You need Python 3.2 or later to use mypy.\n")
11+
exit(1)
1112

1213
from distutils.core import setup
1314
from distutils.command.build_py import build_py
@@ -79,9 +80,7 @@ def run(self):
7980

8081

8182
data_files = []
82-
8383
data_files += find_data_files('typeshed', ['*.py', '*.pyi'])
84-
8584
data_files += find_data_files('xml', ['*.xsd', '*.xslt', '*.css'])
8685

8786
classifiers = [
@@ -105,20 +104,24 @@ def run(self):
105104
if os.name == 'nt':
106105
scripts.append('scripts/mypy.bat')
107106

108-
setup(name='mypy-lang',
109-
version=version,
110-
description=description,
111-
long_description=long_description,
112-
author='Jukka Lehtosalo',
113-
author_email='[email protected]',
114-
url='http://www.mypy-lang.org/',
115-
license='MIT License',
116-
platforms=['POSIX'],
117-
package_dir=package_dir,
118-
py_modules=['typing'] if sys.version_info < (3, 5, 0) else [],
119-
packages=['mypy'],
120-
scripts=scripts,
121-
data_files=data_files,
122-
classifiers=classifiers,
123-
cmdclass={'build_py': CustomPythonBuild},
124-
)
107+
setup_kwargs = dict(
108+
name='mypy-lang',
109+
version=version,
110+
description=description,
111+
long_description=long_description,
112+
author='Jukka Lehtosalo',
113+
author_email='[email protected]',
114+
url='http://www.mypy-lang.org/',
115+
license='MIT License',
116+
platforms=['POSIX'],
117+
package_dir=package_dir,
118+
py_modules=['typing'] if sys.version_info < (3, 5, 0) else [],
119+
packages=['mypy'],
120+
scripts=scripts,
121+
data_files=data_files,
122+
classifiers=classifiers,
123+
cmdclass={'build_py': CustomPythonBuild},
124+
)
125+
126+
if __name__ == '__main__':
127+
setup(**setup_kwargs)

0 commit comments

Comments
 (0)