Skip to content
master
Switch branches/tags
Code

Latest commit

I've seen crashes like this, which might be caused by not
fixing up some FakeInfos:

```
  File "mypy/checkexpr.py", line 3981, in accept
  File "mypy/nodes.py", line 1753, in accept
  File "mypy/checkexpr.py", line 288, in visit_call_expr
  File "mypy/checkexpr.py", line 371, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 880, in check_call_expr_with_callee_type
  File "mypy/checkexpr.py", line 940, in check_call
  File "mypy/checkexpr.py", line 1027, in check_callable_call
  File "mypy/checkexpr.py", line 1269, in infer_function_type_arguments
  File "mypy/checkexpr.py", line 1324, in infer_function_type_arguments_pass2
  File "mypy/infer.py", line 47, in infer_function_type_arguments
  File "mypy/constraints.py", line 72, in infer_constraints_for_callable
  File "mypy/constraints.py", line 108, in infer_constraints
  File "mypy/constraints.py", line 181, in _infer_constraints
  File "mypy/types.py", line 1576, in accept
  File "mypy/constraints.py", line 663, in visit_callable_type
  File "mypy/constraints.py", line 685, in infer_against_overloaded
  File "mypy/constraints.py", line 775, in find_matching_overload_item
  File "mypy/subtypes.py", line 942, in is_callable_compatible
  File "mypy/subtypes.py", line 1209, in unify_generic_callable
  File "mypy/applytype.py", line 86, in apply_generic_arguments
  File "mypy/applytype.py", line 50, in get_target_type
  File "mypy/subtypes.py", line 97, in is_subtype
  File "mypy/subtypes.py", line 158, in _is_subtype
  File "mypy/types.py", line 615, in accept
  File "mypy/subtypes.py", line 341, in visit_param_spec
  File "mypy/subtypes.py", line 217, in _is_subtype
  File "mypy/subtypes.py", line 97, in is_subtype
  File "mypy/subtypes.py", line 158, in _is_subtype
  File "mypy/types.py", line 1127, in accept
  File "mypy/subtypes.py", line 257, in visit_instance
AttributeError: attribute 'fallback_to_any' of 'TypeInfo' undefined
```

I don't have a small reproducer to I couldn't add a test case,
unfortunately.
07ea0f6

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time

mypy logo

Mypy: Static Typing for Python

Stable Version Downloads Build Status Documentation Status Chat at https://gitter.im/python/typing Checked with mypy

Got a question?

We are always happy to answer questions! Here are some good places to ask them:

If you're just getting started, the documentation and type hints cheat sheet can also help answer questions.

If you think you've found a bug:

To report a bug or request an enhancement:

To discuss a new type system feature:

What is mypy?

Mypy is a static type checker for Python.

Type checkers help ensure that you're using variables and functions in your code correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will warn you when you use those types incorrectly.

Python is a dynamic language, so usually you'll only see errors in your code when you attempt to run it. Mypy is a static checker, so it finds bugs in your programs without even running them!

Mypy is designed with gradual typing in mind. This means you can add type hints to your code base slowly and that you can always fall back to dynamic typing when static typing is not convenient.

Here is a small example to whet your appetite:

number = input("What is your favourite number?")
print("It is", number + 1)  # error: Unsupported operand types for + ("str" and "int")

See the documentation for more examples.

In particular, see:

Quick start

Mypy can be installed using pip:

python3 -m pip install -U mypy

If you want to run the latest version of the code, you can install from git:

python3 -m pip install -U git+https://github.com/python/mypy.git

Now you can type-check the statically typed parts of a program like this:

mypy PROGRAM

You can always use the Python interpreter to run your statically typed programs, even if mypy reports type errors:

python3 PROGRAM

You can also try mypy in an online playground (developed by Yusuke Miyazaki).

Integrations

Mypy can be integrated into popular IDEs:

Web site and documentation

Additional information is available at the web site:

http://www.mypy-lang.org/

Jump straight to the documentation:

https://mypy.readthedocs.io/

Follow along our changelog at:

https://mypy-lang.blogspot.com/

Contributing

Help in testing, development, documentation and other tasks is highly appreciated and useful to the project. There are tasks for contributors of all experience levels.

To get started with developing mypy, see CONTRIBUTING.md.

If you need help getting started, don't hesitate to ask on gitter.

Development status

Mypy is beta software, but it has already been used in production for several years at Dropbox and in many other organizations, and it has an extensive test suite.

mypyc and compiled version of mypy

Mypyc uses Python type hints to compile Python modules to faster C extensions. Mypy is itself compiled using mypyc: this makes mypy approximately 4 times faster than if interpreted!

To install an interpreted mypy instead, use:

python3 -m pip install --no-binary mypy -U mypy

To use a compiled version of a development version of mypy, directly install a binary from https://github.com/mypyc/mypy_mypyc-wheels/releases/latest.

To contribute to the mypyc project, check out https://github.com/mypyc/mypyc