1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
.. Mypy documentation master file, created by
sphinx-quickstart on Sun Sep 14 19:50:35 2014.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to mypy documentation!
==============================
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!
Here is a small example to whet your appetite:
.. code-block:: python
number = input("What is your favourite number?")
print("It is", number + 1) # error: Unsupported operand types for + ("str" and "int")
Adding type hints for mypy does not interfere with the way your program would
otherwise run. Think of type hints as similar to comments! You can always use
the Python interpreter to run your code, even if mypy reports errors.
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.
Mypy has a powerful and easy-to-use type system, supporting features such as
type inference, generics, callable types, tuple types, union types,
structural subtyping and more. Using mypy will make your programs easier to
understand, debug, and maintain.
.. note::
Although mypy is production ready, there may be occasional changes
that break backward compatibility. The mypy development team tries to
minimize the impact of changes to user code. In case of a major breaking
change, mypy's major version will be bumped.
Contents
--------
.. toctree::
:maxdepth: 2
:caption: First steps
getting_started
cheat_sheet_py3
existing_code
.. _overview-type-system-reference:
.. toctree::
:maxdepth: 2
:caption: Type system reference
builtin_types
type_inference_and_annotations
kinds_of_types
class_basics
runtime_troubles
protocols
dynamic_typing
type_narrowing
duck_type_compatibility
stubs
generics
more_types
literal_types
typed_dict
final_attrs
metaclasses
.. toctree::
:maxdepth: 2
:caption: Configuring and running mypy
running_mypy
command_line
config_file
inline_config
mypy_daemon
installed_packages
extending_mypy
stubgen
stubtest
.. toctree::
:maxdepth: 2
:caption: Miscellaneous
common_issues
supported_python_features
error_codes
error_code_list
error_code_list2
additional_features
faq
changelog
.. toctree::
:hidden:
:caption: Project Links
GitHub <https://github.com/python/mypy>
Website <https://mypy-lang.org/>
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`
|