Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old parser #2977

Merged
merged 3 commits into from
Mar 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ this:

$ python3 -m pip install -U mypy

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

$ python3 -m pip install -U typed-ast

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

- ``--fast-parser`` enables an experimental parser implemented in C that
is faster than the default parser and supports multi-line comment
function annotations (see :ref:`multi_line_annotation` for the details).

- ``--python-version X.Y`` will make mypy typecheck your code as if it were
run under Python version X.Y. Without this option, mypy will default to using
whatever version of Python is running mypy. Note that the ``-2`` and
Expand Down
3 changes: 0 additions & 3 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ The following global flags may only be set in the global section
- ``dump_inference_stats`` (Boolean, default False) dumps stats about
type inference.

- ``fast_parser`` (Boolean, default False) enables the experimental
fast parser.

- ``incremental`` (Boolean, default False) enables the experimental
module cache.

Expand Down
15 changes: 0 additions & 15 deletions docs/source/kinds_of_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,6 @@ Mypy supports it already:

p = Point(x=1, y='x') # Argument has incompatible type "str"; expected "int"

.. note::

The Python 3.6 syntax requires the ``--fast-parser`` flag. You must also have the
`typed_ast <https://pypi.python.org/pypi/typed-ast>`_ package
installed and have at least version 0.6.1. Use ``pip3 install -U typed_ast``.

.. _type-of-class:

The type of class objects
Expand Down Expand Up @@ -872,15 +866,6 @@ annotated the first example as the following:
Typing async/await
******************

.. note::

Currently, you must pass in the ``--fast-parser`` flag if you want to run
mypy against code containing the ``async/await`` keywords. The fast parser
will be enabled by default in a future version of mypy.

Note that mypy will understand coroutines created using the ``@asyncio.coroutine``
decorator both with and without the fast parser enabled.

Mypy supports the ability to type coroutines that use the ``async/await``
syntax introduced in Python 3.5. For more information regarding coroutines and
this new syntax, see `PEP 492 <https://www.python.org/dev/peps/pep-0492/>`_.
Expand Down
6 changes: 0 additions & 6 deletions docs/source/python2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ overly long type comments and it's often tricky to see which argument
type corresponds to which argument. The alternative, multi-line
annotation syntax makes long annotations easier to read and write.

.. note::

Multi-line comment annotations currently only work when using the
``--fast-parser`` command line option. This is not enabled by
default because the option isn’t supported on Windows yet.

Here is an example (from PEP 484):

.. code-block:: python
Expand Down
5 changes: 2 additions & 3 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1836,9 +1836,8 @@ def visit_assert_stmt(self, s: AssertStmt) -> None:
if s.msg is not None:
self.expr_checker.accept(s.msg)

if self.options.fast_parser:
if isinstance(s.expr, TupleExpr) and len(s.expr.items) > 0:
self.warn(messages.MALFORMED_ASSERT, s)
if isinstance(s.expr, TupleExpr) and len(s.expr.items) > 0:
self.warn(messages.MALFORMED_ASSERT, s)

# If this is asserting some isinstance check, bind that type in the following code
true_map, _ = self.find_isinstance_check(s.expr)
Expand Down
6 changes: 3 additions & 3 deletions mypy/exprtotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ListExpr, StrExpr, BytesExpr, UnicodeExpr, EllipsisExpr,
get_member_expr_fullname
)
from mypy.parsetype import parse_str_as_type, TypeParseError
from mypy.fastparse import parse_type_comment
from mypy.types import Type, UnboundType, TypeList, EllipsisType


Expand Down Expand Up @@ -49,8 +49,8 @@ def expr_to_unanalyzed_type(expr: Expression) -> Type:
elif isinstance(expr, (StrExpr, BytesExpr, UnicodeExpr)):
# Parse string literal type.
try:
result = parse_str_as_type(expr.value, expr.line)
except TypeParseError:
result = parse_type_comment(expr.value, expr.line, None)
except SyntaxError:
raise TypeTranslationError()
return result
elif isinstance(expr, EllipsisExpr):
Expand Down
7 changes: 5 additions & 2 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ def parse_type_comment(type_comment: str, line: int, errors: Errors) -> Optional
try:
typ = ast3.parse(type_comment, '<type_comment>', 'eval')
except SyntaxError as e:
errors.report(line, e.offset, TYPE_COMMENT_SYNTAX_ERROR)
return None
if errors is not None:
errors.report(line, e.offset, TYPE_COMMENT_SYNTAX_ERROR)
return None
else:
raise
else:
assert isinstance(typ, ast3.Expression)
return TypeConverter(errors, line=line).visit(typ.body)
Expand Down
Loading