Skip to content

Commit 42020fb

Browse files
authored
Merge branch 'master' into fix-property-selftype
2 parents 3c8e85f + 5928551 commit 42020fb

File tree

180 files changed

+10787
-10909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+10787
-10909
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ python:
1515

1616
install:
1717
- pip install -r test-requirements.txt
18+
- python2 -m pip install --user typing
1819
- python setup.py install
1920

2021
script:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ place to start a discussion of any of the above or most any other
3030
topic concerning the project.
3131

3232
For less formal discussion we have a chat room on
33-
[gitter.im](https://gitter.im/python/mypy). Some Mypy core developers
33+
[gitter.im](https://gitter.im/python/typing). Some Mypy core developers
3434
are almost always present; feel free to find us there and we're happy
3535
to chat. Substantive technical discussion will be directed to the
3636
issue tracker.

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ DEALINGS IN THE SOFTWARE.
2727
= = = = =
2828

2929
Portions of mypy are licensed under different licenses. The files
30-
under stdlib-samples and lib-typing are licensed under the PSF 2
31-
License, reproduced below.
30+
under stdlib-samples are licensed under the PSF 2 License, reproduced below.
3231

3332
= = = = =
3433

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ Mypy: Optional Static Typing for Python
22
=======================================
33

44
[![Build Status](https://travis-ci.org/python/mypy.svg)](https://travis-ci.org/python/mypy)
5-
[![Chat at https://gitter.im/python/mypy](https://badges.gitter.im/python/mypy.svg)](https://gitter.im/python/mypy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5+
[![Chat at https://gitter.im/python/typing](https://badges.gitter.im/python/typing.svg)](https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
66

77

88
Got a question? Join us on Gitter!
99
----------------------------------
1010

1111
We don't have a mailing list; but we are always happy to answer
12-
questions on [gitter chat](https://gitter.im/python/mypy). If you are
12+
questions on [gitter chat](https://gitter.im/python/typing). If you are
1313
sure you've found a bug please search our issue trackers for a
1414
duplicate before filing a new issue:
1515

@@ -97,6 +97,23 @@ programs, even if they have type errors:
9797
[statically typed parts]: http://mypy.readthedocs.io/en/latest/basics.html#function-signatures
9898

9999

100+
IDE & Linter Integrations
101+
-------------------------
102+
103+
Mypy can be integrated into popular IDEs:
104+
105+
* Vim: [vim-mypy](https://github.com/Integralist/vim-mypy)
106+
* Emacs: using [Flycheck](https://github.com/flycheck/) and [Flycheck-mypy](https://github.com/lbolla/emacs-flycheck-mypy/issues)
107+
* Sublime Text: [SublimeLinter-contrib-mypy]
108+
* Atom: [linter-mypy](https://atom.io/packages/linter-mypy)
109+
* PyCharm: PyCharm integrates [its own implementation of PEP 484](https://www.jetbrains.com/help/pycharm/2017.1/type-hinting-in-pycharm.html).
110+
111+
Mypy can also be integrated into [Flake8] using [flake8-mypy].
112+
113+
[Flake8]: http://flake8.pycqa.org/
114+
[flake8-mypy]: https://github.com/ambv/flake8-mypy
115+
116+
100117
Web site and documentation
101118
--------------------------
102119

@@ -157,6 +174,15 @@ If you want to contribute, first clone the mypy git repository:
157174

158175
$ git clone --recurse-submodules https://github.com/python/mypy.git
159176

177+
If you've already cloned the repo without `--recurse-submodules`,
178+
you need to pull in the typeshed repo as follows:
179+
180+
$ git submodule init
181+
$ git submodule update
182+
183+
Either way you should now have a subdirectory `typeshed` containing a
184+
clone of the typeshed repo (`https://github.com/python/typeshed`).
185+
160186
From the mypy directory, use pip to install mypy:
161187

162188
$ cd mypy
@@ -170,10 +196,6 @@ the above as root. For example, in Ubuntu:
170196
Now you can use the `mypy` program just as above. In case of trouble
171197
see "Troubleshooting" above.
172198

173-
The mypy wiki contains some useful information for contributors:
174-
175-
https://github.com/python/mypy/wiki/Developer-Guides
176-
177199

178200
Working with the git version of mypy
179201
------------------------------------

ROADMAP.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Mypy Roadmap
2+
3+
The goal of the roadmap is to document areas the mypy core team is
4+
planning to work on in the future or is currently working on. PRs
5+
targeting these areas are very welcome, but please check first with a
6+
core team member that nobody else is working on the same thing.
7+
8+
**Note:** This doesn’t include everything that the core team will work
9+
on, and everything is subject to change. Near-term plans are likely
10+
more accurate.
11+
12+
## April-June 2017
13+
14+
- Add more comprehensive testing for `--incremental` and `--quick`
15+
modes to improve reliability. At least write more unit tests with
16+
focus on areas that have previously had bugs.
17+
([issue](https://github.com/python/mypy/issues/3455))
18+
19+
- Speed up `--quick` mode to better support million+ line codebases
20+
through some of these:
21+
22+
- Make it possible to use remote caching for incremental cache
23+
files. This would speed up a cold run with no local cache data.
24+
We need to update incremental cache to use hashes to determine
25+
whether files have changes to allow
26+
[sharing cache data](https://github.com/python/mypy/issues/3403).
27+
28+
- See if we can speed up deserialization of incremental cache
29+
files. Initial experiments aren’t very promising though so there
30+
might not be any easy wins left.
31+
([issue](https://github.com/python/mypy/issues/3456))
32+
33+
- Improve support for complex signatures such as `open(fn, 'rb')` and
34+
specific complex decorators such as `contextlib.contextmanager`
35+
through type checker plugins/hooks.
36+
([issue](https://github.com/python/mypy/issues/1240))
37+
38+
- Document basic properties of all type operations used within mypy,
39+
including compatibility, proper subtyping, joins and meets.
40+
([issue](https://github.com/python/mypy/issues/3454))
41+
42+
- Make TypedDict an officially supported mypy feature. This makes it
43+
possible to give precise types for dictionaries that represent JSON
44+
objects, such as `{"path": "/dir/fnam.ext", "size": 1234}`.
45+
([issue](https://github.com/python/mypy/issues/3453))
46+
47+
- Make error messages more useful and informative.
48+
([issue](https://github.com/python/mypy/labels/topic-usability))
49+
50+
- Resolve [#2008](https://github.com/python/mypy/issues/2008) (we are
51+
converging on approach 4).
52+
53+
## July-December 2017
54+
55+
- Invest some effort into systematically filling in missing
56+
annotations and stubs in typeshed, with focus on features heavily
57+
used at Dropbox. Better support for ORMs will be a separate
58+
project.
59+
60+
- Improve opt-in warnings about `Any` types to make it easier to keep
61+
code free from unwanted `Any` types. For example, warn about using
62+
`list` (instead of `List[x]`) and calling `open` if we can’t infer a
63+
precise return type, or using types imported from ignored modules
64+
(they are implicitly `Any`).
65+
66+
- Add support for protocols and structural subtyping (PEP 544).
67+
68+
- Switch completely to pytest and remove the custom testing framework.
69+
([issue](https://github.com/python/mypy/issues/1673))
70+
71+
- Make it possible to run mypy as a daemon to avoid reprocessing the
72+
entire program on each run. This will improve performance
73+
significantly. Even when using the incremental mode, processing a
74+
large number of files is not cheap.
75+
76+
- Refactor and simplify specific tricky parts of mypy internals, such
77+
as the [conditional type binder](https://github.com/python/mypy/issues/3457),
78+
[symbol tables](https://github.com/python/mypy/issues/3458) or
79+
the various [semantic analysis passes](https://github.com/python/mypy/issues/3459).
80+
81+
- Implement a general type system plugin architecture. It should be
82+
able to support some typical ORM features at least, such as
83+
metaclasses that add methods with automatically inferred signatures
84+
and complex descriptors such as those used by Django models.
85+
([issue](https://github.com/python/mypy/issues/1240))
86+
87+
- Add support for statically typed
88+
[protobufs](https://developers.google.com/protocol-buffers/).
89+
90+
- Provide much faster, reliable interactive feedback through
91+
fine-grained incremental type checking, built on top the daemon
92+
mode.
93+
94+
- Start work on editor plugins and support for selected IDE features.
95+
96+
- Turn on `--strict-optional` by default.

appveyor.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
environment:
22
matrix:
33

4-
- PYTHON: "C:\\Python35"
5-
PYTHON_VERSION: "3.5.1"
6-
PYTHON_ARCH: "32"
7-
8-
- PYTHON: "C:\\Python35-x64"
9-
PYTHON_VERSION: "3.5.1"
10-
PYTHON_ARCH: "64"
11-
12-
- PYTHON: "C:\\Python36"
13-
PYTHON_VERSION: "3.6.x"
14-
PYTHON_ARCH: "32"
15-
164
- PYTHON: "C:\\Python36-x64"
175
PYTHON_VERSION: "3.6.x"
186
PYTHON_ARCH: "64"
197

20-
218
install:
229
- "git config core.symlinks true"
2310
- "git reset --hard"
@@ -50,3 +37,5 @@ skip_commits:
5037
- .travis.yml
5138
- CREDITS
5239
- LICENSE
40+
41+
skip_branch_with_pr: true

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import os.path
2+
3+
import pytest
4+
15
pytest_plugins = [
26
'mypy.test.data',
37
]
8+
9+
10+
def pytest_configure(config):
11+
mypy_source_root = os.path.dirname(os.path.abspath(__file__))
12+
if os.getcwd() != mypy_source_root:
13+
os.chdir(mypy_source_root)

docs/source/cheat_sheet.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ When you're puzzled or when things are complicated
149149
reveal_type(c) # -> error: Revealed type is 'builtins.list[builtins.str]'
150150
print(c) # -> [4] the object is not cast
151151
152+
# if you want dynamic attributes on your class, have it override __setattr__ or __getattr__
153+
# in a stub or in your source code.
154+
# __setattr__ allows for dynamic assignment to names
155+
# __getattr__ allows for dynamic access to names
156+
class A:
157+
# this will allow assignment to any A.x, if x is the same type as `value`
158+
def __setattr__(self, name, value):
159+
# type: (str, int) -> None
160+
...
161+
a.foo = 42 # works
162+
a.bar = 'Ex-parrot' # fails type checking
163+
152164
# TODO: explain "Need type annotation for variable" when
153165
# initializing with None or an empty container
154166
@@ -220,15 +232,17 @@ Other stuff
220232
221233
# Use AnyStr for functions that should accept any kind of string
222234
# without allowing different kinds of strings to mix.
223-
def concat(a: AnyStr, b: AnyStr) -> AnyStr:
235+
def concat(a, b):
236+
# type: (AnyStr, AnyStr) -> AnyStr
224237
return a + b
225238
concat(u"foo", u"bar") # type: unicode
226239
concat(b"foo", b"bar") # type: bytes
227240
228241
# Use IO[] for functions that should accept or return any
229242
# object that comes from an open() call. The IO[] does not
230243
# distinguish between reading, writing or other modes.
231-
def get_sys_IO(mode='w') -> IO[str]:
244+
def get_sys_IO(mode='w'):
245+
# type: (str) -> IO[str]
232246
if mode == 'w':
233247
return sys.stdout
234248
elif mode == 'r':

docs/source/cheat_sheet_py3.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ When you're puzzled or when things are complicated
142142
reveal_type(c) # -> error: Revealed type is 'builtins.list[builtins.str]'
143143
print(c) # -> [4] the object is not cast
144144
145+
# if you want dynamic attributes on your class, have it override __setattr__ or __getattr__
146+
# in a stub or in your source code.
147+
# __setattr__ allows for dynamic assignment to names
148+
# __getattr__ allows for dynamic access to names
149+
class A:
150+
# this will allow assignment to any A.x, if x is the same type as `value`
151+
def __setattr__(self, name: str, value: int) -> None: ...
152+
# this will allow access to any A.x, if x is compatible with the return type
153+
def __getattr__(self, name: str) -> int: ...
154+
a.foo = 42 # works
155+
a.bar = 'Ex-parrot' # fails type checking
156+
157+
145158
# TODO: explain "Need type annotation for variable" when
146159
# initializing with None or an empty container
147160

0 commit comments

Comments
 (0)