Skip to content

Commit d43db1b

Browse files
authored
Merge pull request #56 from python/master
Sync Fork from Upstream Repo
2 parents e2ac2d3 + 4ecbd4d commit d43db1b

File tree

98 files changed

+1494
-529
lines changed

Some content is hidden

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

98 files changed

+1494
-529
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__
66
/env*/
77
docs/build/
88
docs/source/_build
9+
mypyc/doc/_build
910
*.iml
1011
/out/
1112
.venv*/

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ env:
2222
PYTHON_DEBUG_BUILD=0
2323

2424
jobs:
25+
fast_finish: true
2526
include:
2627
# Specifically request 3.5.1 because we need to be compatible with that.
2728
- name: "run test suite with python 3.5.1 (compiled with mypyc)"
@@ -43,6 +44,8 @@ jobs:
4344
python: 3.8
4445
- name: "run test suite with python 3.9"
4546
python: 3.9
47+
- name: "run test suite with python nightly"
48+
python: nightly
4649
- name: "run mypyc runtime tests with python 3.6 debug build"
4750
language: generic
4851
env:
@@ -80,6 +83,8 @@ jobs:
8083
# env:
8184
# - TOXENV=dev
8285
# - EXTRA_ARGS=
86+
allow_failures:
87+
- python: nightly
8388

8489
install:
8590
# pip 21.0 no longer works on Python 3.5

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Getting started, building, and testing
1212

1313
If you haven't already, take a look at the project's
1414
[README.md file](README.md)
15-
and the [Mypy documentation](http://mypy.readthedocs.io/en/latest/),
15+
and the [Mypy documentation](https://mypy.readthedocs.io/en/latest/),
1616
and try adding type annotations to your file and type-checking it with Mypy.
1717

1818

docs/source/cheat_sheet.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ language represents various common types in Python 2.
1313
many of the examples have a dual purpose: show how to write the
1414
annotation, and show the inferred types.
1515

16+
.. note::
17+
18+
To check Python 2 code with mypy, you'll need to install mypy with
19+
``pip install 'mypy[python2]'``.
20+
21+
1622

1723
Built-in types
1824
**************

docs/source/command_line.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ For more information on how to use these flags, see :ref:`version_and_platform_c
232232

233233
Equivalent to running :option:`--python-version 2.7 <--python-version>`.
234234

235+
.. note::
236+
237+
To check Python 2 code with mypy, you'll need to install mypy with
238+
``pip install 'mypy[python2]'``.
239+
235240
.. option:: --platform PLATFORM
236241

237242
This flag will make mypy type check your code as if it were

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
Welcome to Mypy documentation!
6+
Welcome to mypy documentation!
77
==============================
88

99
Mypy is a static type checker for Python 3 and Python 2.7.

docs/source/python2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ annotations are given in comments, since the function annotation
88
syntax was introduced in Python 3. The comment-based syntax is
99
specified in :pep:`484`.
1010

11+
Mypy requires typed-ast in order to check Python 2 code. You can install it
12+
using ``pip install 'mypy[python2]'``.
13+
1114
Run mypy in Python 2 mode by using the :option:`--py2 <mypy --py2>` option::
1215

1316
$ mypy --py2 program.py

mypy/errors.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,14 @@ def num_messages(self) -> int:
405405
return sum(len(x) for x in self.error_info_map.values())
406406

407407
def is_errors(self) -> bool:
408-
"""Are there any generated errors?"""
408+
"""Are there any generated messages?"""
409409
return bool(self.error_info_map)
410410

411+
def is_real_errors(self) -> bool:
412+
"""Are there any generated errors (not just notes, for example)?"""
413+
return any(info.severity == 'error'
414+
for infos in self.error_info_map.values() for info in infos)
415+
411416
def is_blockers(self) -> bool:
412417
"""Are the any errors that are blockers?"""
413418
return any(err for errs in self.error_info_map.values() for err in errs if err.blocker)
@@ -721,7 +726,8 @@ def report_internal_error(err: Exception,
721726
# Print "INTERNAL ERROR" message.
722727
print('{}error: INTERNAL ERROR --'.format(prefix),
723728
'Please try using mypy master on Github:\n'
724-
'https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build',
729+
'https://mypy.readthedocs.io/en/stable/common_issues.html'
730+
'#using-a-development-mypy-build',
725731
file=stderr)
726732
if options.show_traceback:
727733
print('Please report a bug at https://github.com/python/mypy/issues',

mypy/fastparse2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
from typed_ast import ast35 # type: ignore[attr-defined] # noqa: F401
6969
except ImportError:
7070
print('The typed_ast package is not installed.\n'
71-
'You can install it with `python3 -m pip install typed-ast`.',
71+
'For Python 2 support, install mypy using `python3 -m pip install "mypy[python2]"`'
72+
'Alternatively, you can install typed_ast with `python3 -m pip install typed-ast`.',
7273
file=sys.stderr)
7374
else:
7475
print('You need a more recent version of the typed_ast package.\n'

mypy/join.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ def visit_literal_type(self, t: LiteralType) -> ProperType:
310310
if isinstance(self.s, LiteralType):
311311
if t == self.s:
312312
return t
313-
else:
314-
return join_types(self.s.fallback, t.fallback)
313+
if self.s.fallback.type.is_enum and t.fallback.type.is_enum:
314+
return mypy.typeops.make_simplified_union([self.s, t])
315+
return join_types(self.s.fallback, t.fallback)
315316
else:
316317
return join_types(self.s, t.fallback)
317318

0 commit comments

Comments
 (0)