Skip to content

Commit a8c7947

Browse files
ddfishergvanrossum
authored andcommitted
Remove old parser (#2977)
It's no longer needed.
1 parent 6488838 commit a8c7947

38 files changed

+182
-3857
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ this:
116116

117117
$ python3 -m pip install -U mypy
118118

119-
Except on Windows, it's best to always use the `--fast-parser`
120-
option to mypy; this requires installing `typed-ast`:
119+
This should automatically installed the appropriate version of
120+
mypy's parser, typed-ast. If for some reason it does not, you
121+
can install it manually:
121122

122123
$ python3 -m pip install -U typed-ast
123124

docs/source/command_line.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ flag (or its long form ``--help``)::
1515
[--check-untyped-defs] [--disallow-subclassing-any]
1616
[--warn-incomplete-stub] [--warn-redundant-casts]
1717
[--warn-no-return] [--warn-unused-ignores] [--show-error-context]
18-
[--fast-parser] [-i] [--cache-dir DIR] [--strict-optional]
18+
[-i] [--cache-dir DIR] [--strict-optional]
1919
[--strict-optional-whitelist [GLOB [GLOB ...]]] [--strict]
2020
[--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats]
2121
[--inferstats] [--custom-typing MODULE]
@@ -303,10 +303,6 @@ Here are some more useful flags:
303303
to speed up type checking. Incremental mode can help when most parts
304304
of your program haven't changed since the previous mypy run.
305305

306-
- ``--fast-parser`` enables an experimental parser implemented in C that
307-
is faster than the default parser and supports multi-line comment
308-
function annotations (see :ref:`multi_line_annotation` for the details).
309-
310306
- ``--python-version X.Y`` will make mypy typecheck your code as if it were
311307
run under Python version X.Y. Without this option, mypy will default to using
312308
whatever version of Python is running mypy. Note that the ``-2`` and

docs/source/config_file.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ The following global flags may only be set in the global section
9393
- ``dump_inference_stats`` (Boolean, default False) dumps stats about
9494
type inference.
9595

96-
- ``fast_parser`` (Boolean, default False) enables the experimental
97-
fast parser.
98-
9996
- ``incremental`` (Boolean, default False) enables the experimental
10097
module cache.
10198

docs/source/kinds_of_types.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,6 @@ Mypy supports it already:
691691
692692
p = Point(x=1, y='x') # Argument has incompatible type "str"; expected "int"
693693
694-
.. note::
695-
696-
The Python 3.6 syntax requires the ``--fast-parser`` flag. You must also have the
697-
`typed_ast <https://pypi.python.org/pypi/typed-ast>`_ package
698-
installed and have at least version 0.6.1. Use ``pip3 install -U typed_ast``.
699-
700694
.. _type-of-class:
701695

702696
The type of class objects
@@ -872,15 +866,6 @@ annotated the first example as the following:
872866
Typing async/await
873867
******************
874868

875-
.. note::
876-
877-
Currently, you must pass in the ``--fast-parser`` flag if you want to run
878-
mypy against code containing the ``async/await`` keywords. The fast parser
879-
will be enabled by default in a future version of mypy.
880-
881-
Note that mypy will understand coroutines created using the ``@asyncio.coroutine``
882-
decorator both with and without the fast parser enabled.
883-
884869
Mypy supports the ability to type coroutines that use the ``async/await``
885870
syntax introduced in Python 3.5. For more information regarding coroutines and
886871
this new syntax, see `PEP 492 <https://www.python.org/dev/peps/pep-0492/>`_.

docs/source/python2.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ overly long type comments and it's often tricky to see which argument
6666
type corresponds to which argument. The alternative, multi-line
6767
annotation syntax makes long annotations easier to read and write.
6868

69-
.. note::
70-
71-
Multi-line comment annotations currently only work when using the
72-
``--fast-parser`` command line option. This is not enabled by
73-
default because the option isn’t supported on Windows yet.
74-
7569
Here is an example (from PEP 484):
7670

7771
.. code-block:: python

mypy/checker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,9 +1836,8 @@ def visit_assert_stmt(self, s: AssertStmt) -> None:
18361836
if s.msg is not None:
18371837
self.expr_checker.accept(s.msg)
18381838

1839-
if self.options.fast_parser:
1840-
if isinstance(s.expr, TupleExpr) and len(s.expr.items) > 0:
1841-
self.warn(messages.MALFORMED_ASSERT, s)
1839+
if isinstance(s.expr, TupleExpr) and len(s.expr.items) > 0:
1840+
self.warn(messages.MALFORMED_ASSERT, s)
18421841

18431842
# If this is asserting some isinstance check, bind that type in the following code
18441843
true_map, _ = self.find_isinstance_check(s.expr)

mypy/exprtotype.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
ListExpr, StrExpr, BytesExpr, UnicodeExpr, EllipsisExpr,
66
get_member_expr_fullname
77
)
8-
from mypy.parsetype import parse_str_as_type, TypeParseError
8+
from mypy.fastparse import parse_type_comment
99
from mypy.types import Type, UnboundType, TypeList, EllipsisType
1010

1111

@@ -49,8 +49,8 @@ def expr_to_unanalyzed_type(expr: Expression) -> Type:
4949
elif isinstance(expr, (StrExpr, BytesExpr, UnicodeExpr)):
5050
# Parse string literal type.
5151
try:
52-
result = parse_str_as_type(expr.value, expr.line)
53-
except TypeParseError:
52+
result = parse_type_comment(expr.value, expr.line, None)
53+
except SyntaxError:
5454
raise TypeTranslationError()
5555
return result
5656
elif isinstance(expr, EllipsisExpr):

mypy/fastparse.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ def parse_type_comment(type_comment: str, line: int, errors: Errors) -> Optional
9595
try:
9696
typ = ast3.parse(type_comment, '<type_comment>', 'eval')
9797
except SyntaxError as e:
98-
errors.report(line, e.offset, TYPE_COMMENT_SYNTAX_ERROR)
99-
return None
98+
if errors is not None:
99+
errors.report(line, e.offset, TYPE_COMMENT_SYNTAX_ERROR)
100+
return None
101+
else:
102+
raise
100103
else:
101104
assert isinstance(typ, ast3.Expression)
102105
return TypeConverter(errors, line=line).visit(typ.body)

0 commit comments

Comments
 (0)