Skip to content

Commit

Permalink
Remove mention of Python 2 from documentation (#13255)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jul 28, 2022
1 parent 989e407 commit 002f77c
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 629 deletions.
282 changes: 0 additions & 282 deletions docs/source/cheat_sheet.rst

This file was deleted.

5 changes: 0 additions & 5 deletions docs/source/class_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,6 @@ function decorator. Example:
x = Animal() # Error: 'Animal' is abstract due to 'eat' and 'can_walk'
y = Cat() # OK
.. note::

In Python 2.7 you have to use :py:func:`@abc.abstractproperty <abc.abstractproperty>` to define
an abstract property.

Note that mypy performs checking for unimplemented abstract methods
even if you omit the :py:class:`~abc.ABCMeta` metaclass. This can be useful if the
metaclass would cause runtime metaclass conflicts.
Expand Down
12 changes: 1 addition & 11 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -251,23 +251,13 @@ For more information on how to use these flags, see :ref:`version_and_platform_c

This flag will make mypy type check 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 :option:`-2` and
:option:`--py2` flags are aliases for :option:`--python-version 2.7 <--python-version>`.
whatever version of Python is running mypy.

This flag will attempt to find a Python executable of the corresponding
version to search for :pep:`561` compliant packages. If you'd like to
disable this, use the :option:`--no-site-packages` flag (see
:ref:`import-discovery` for more details).

.. option:: -2, --py2

Equivalent to running :option:`--python-version 2.7 <--python-version>`.

.. note::

To check Python 2 code with mypy, you'll need to install mypy with
``pip install 'mypy[python2]'``.

.. option:: --platform PLATFORM

This flag will make mypy type check your code as if it were
Expand Down
10 changes: 4 additions & 6 deletions docs/source/common_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,8 @@ More specifically, mypy will understand the use of :py:data:`sys.version_info` a
# Distinguishing between different versions of Python:
if sys.version_info >= (3, 8):
# Python 3.8+ specific definitions and imports
elif sys.version_info[0] >= 3:
# Python 3 specific definitions and imports
else:
# Python 2 specific definitions and imports
# Other definitions and imports
# Distinguishing between different operating systems:
if sys.platform.startswith("linux"):
Expand Down Expand Up @@ -484,9 +482,9 @@ operating system as default values for :py:data:`sys.version_info` and
:py:data:`sys.platform`.

To target a different Python version, use the :option:`--python-version X.Y <mypy --python-version>` flag.
For example, to verify your code typechecks if were run using Python 2, pass
in :option:`--python-version 2.7 <mypy --python-version>` from the command line. Note that you do not need
to have Python 2.7 installed to perform this check.
For example, to verify your code typechecks if were run using Python 3.8, pass
in :option:`--python-version 3.8 <mypy --python-version>` from the command line. Note that you do not need
to have Python 3.8 installed to perform this check.

To target a different operating system, use the :option:`--platform PLATFORM <mypy --platform>` flag.
For example, to verify your code typechecks if it were run in Windows, pass
Expand Down
10 changes: 3 additions & 7 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ of your repo and run mypy.
# Global options:
[mypy]
python_version = 2.7
warn_return_any = True
warn_unused_configs = True
Expand All @@ -129,16 +128,13 @@ of your repo and run mypy.
[mypy-somelibrary]
ignore_missing_imports = True
This config file specifies three global options in the ``[mypy]`` section. These three
This config file specifies two global options in the ``[mypy]`` section. These two
options will:

1. Type-check your entire project assuming it will be run using Python 2.7.
(This is equivalent to using the :option:`--python-version 2.7 <mypy --python-version>` or :option:`-2 <mypy -2>` flag).

2. Report an error whenever a function returns a value that is inferred
1. Report an error whenever a function returns a value that is inferred
to have type ``Any``.

3. Report any config options that are unused by mypy. (This will help us catch typos
2. Report any config options that are unused by mypy. (This will help us catch typos
when making changes to our config file).

Next, this module specifies three per-module options. The first two options change how mypy
Expand Down
14 changes: 0 additions & 14 deletions docs/source/duck_type_compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ supported for a small set of built-in types:
* ``int`` is duck type compatible with ``float`` and ``complex``.
* ``float`` is duck type compatible with ``complex``.
* ``bytearray`` and ``memoryview`` are duck type compatible with ``bytes``.
* In Python 2, ``str`` is duck type compatible with ``unicode``.

For example, mypy considers an ``int`` object to be valid whenever a
``float`` object is expected. Thus code like this is nice and clean
Expand All @@ -30,16 +29,3 @@ a more principled and extensible fashion. Protocols don't apply to
cases like ``int`` being compatible with ``float``, since ``float`` is not
a protocol class but a regular, concrete class, and many standard library
functions expect concrete instances of ``float`` (or ``int``).

.. note::

Note that in Python 2 a ``str`` object with non-ASCII characters is
often *not valid* when a unicode string is expected. The mypy type
system does not consider a string with non-ASCII values as a
separate type so some programs with this kind of error will
silently pass type checking. In Python 3 ``str`` and ``bytes`` are
separate, unrelated types and this kind of error is easy to
detect. This a good reason for preferring Python 3 over Python 2!

See :ref:`text-and-anystr` for details on how to enforce that a
value must be a unicode string in a cross-compatible way.
Loading

0 comments on commit 002f77c

Please sign in to comment.