Skip to content

Commit 5f21936

Browse files
authored
Update getting started docs (#13734)
See #13681. I'd like to make bigger changes to this page, but still thinking them through
1 parent f5ce4ee commit 5f21936

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

docs/source/builtin_types.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ Type Description
1515
``int`` integer
1616
``float`` floating point number
1717
``bool`` boolean value (subclass of ``int``)
18-
``str`` string (unicode in Python 3)
19-
``bytes`` 8-bit string
18+
``str`` text, sequence of unicode codepoints
19+
``bytes`` 8-bit string, sequence of byte values
2020
``object`` an arbitrary object (``object`` is the common base class)
2121
====================== ===============================
2222

docs/source/getting_started.rst

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ Getting started
66
This chapter introduces some core concepts of mypy, including function
77
annotations, the :py:mod:`typing` module, stub files, and more.
88

9-
Be sure to read this chapter carefully, as the rest of the documentation
9+
If you're looking for a quick intro, see the
10+
:ref:`mypy cheatsheet <cheat-sheet-py3>`.
11+
12+
If you're unfamiliar with the concepts of static and dynamic type checking,
13+
be sure to read this chapter carefully, as the rest of the documentation
1014
may not make much sense otherwise.
1115

1216
Installing and running mypy
1317
***************************
1418

15-
Mypy requires Python 3.6 or later to run. Once you've
16-
`installed Python 3 <https://www.python.org/downloads/>`_,
17-
install mypy using pip:
19+
Mypy requires Python 3.7 or later to run. You can install mypy using pip:
1820

1921
.. code-block:: shell
2022
@@ -31,13 +33,16 @@ out any errors it finds. Mypy will type check your code *statically*: this
3133
means that it will check for errors without ever running your code, just
3234
like a linter.
3335

34-
This means that you are always free to ignore the errors mypy reports and
35-
treat them as just warnings, if you so wish: mypy runs independently from
36-
Python itself.
36+
This also means that you are always free to ignore the errors mypy reports,
37+
if you so wish. You can always use the Python interpreter to run your code,
38+
even if mypy reports errors.
3739

3840
However, if you try directly running mypy on your existing Python code, it
39-
will most likely report little to no errors: you must add *type annotations*
40-
to your code to take full advantage of mypy. See the section below for details.
41+
will most likely report little to no errors. This is a feature! It makes it
42+
easy to adopt mypy incrementally.
43+
44+
In order to get useful diagnostics from mypy, you must add *type annotations*
45+
to your code. See the section below for details.
4146

4247
Function signatures and dynamic vs static typing
4348
************************************************
@@ -77,9 +82,6 @@ calls since the arguments have invalid types:
7782
greeting(3) # Argument 1 to "greeting" has incompatible type "int"; expected "str"
7883
greeting(b'Alice') # Argument 1 to "greeting" has incompatible type "bytes"; expected "str"
7984
80-
Note that this is all still valid Python 3 code! The function annotation syntax
81-
shown above was added to Python :pep:`as a part of Python 3.0 <3107>`.
82-
8385
Being able to pick whether you want a function to be dynamically or statically
8486
typed can be very helpful. For example, if you are migrating an existing
8587
Python codebase to use static types, it's usually easier to migrate by incrementally
@@ -91,12 +93,6 @@ Once you are finished migrating or prototyping your code, you can make mypy warn
9193
if you add a dynamic function by mistake by using the :option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>`
9294
flag. See :ref:`command-line` for more information on configuring mypy.
9395

94-
.. note::
95-
96-
The earlier stages of analysis performed by mypy may report errors
97-
even for dynamically typed functions. However, you should not rely
98-
on this, as this may change in the future.
99-
10096
More function signatures
10197
************************
10298

0 commit comments

Comments
 (0)