Skip to content

Commit

Permalink
Merge branch 'python:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kreathon authored Aug 12, 2023
2 parents 669b5d6 + 3631528 commit ad7e272
Show file tree
Hide file tree
Showing 191 changed files with 2,596 additions and 1,877 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
23ee1e7aff357e656e3102435ad0fe3b5074571e
# Use variable annotations (#10723)
f98f78216ba9d6ab68c8e69c19e9f3c7926c5efe
# run pyupgrade (#12711)
fc335cb16315964b923eb1927e3aad1516891c28
25 changes: 7 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ jobs:
toxenv: py
tox_extra_args: "-n 2"
test_mypyc: true
- name: Test suite with py312-ubuntu, mypyc-compiled
python: '3.12-dev'
arch: x64
os: ubuntu-latest
toxenv: py
tox_extra_args: "-n 2"
test_mypyc: true

- name: mypyc runtime tests with py38-macos
python: '3.8.17'
Expand Down Expand Up @@ -134,24 +141,6 @@ jobs:
- name: Test
run: tox run -e ${{ matrix.toxenv }} --skip-pkg-install -- ${{ matrix.tox_extra_args }}

python-nightly:
runs-on: ubuntu-latest
name: Test suite with Python nightly
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.12-dev'
- name: Install tox
run: pip install --upgrade 'setuptools!=50' tox==4.4.4
- name: Setup tox environment
run: tox run -e py --notest
- name: Test
run: tox run -e py --skip-pkg-install -- "-n 2"
continue-on-error: true
- name: Mark as a success
run: exit 0

python_32bits:
runs-on: ubuntu-latest
name: Test mypyc suite with 32-bit Python
Expand Down
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ repos:
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/hauntsaninja/black-pre-commit-mirror
rev: 23.3.0 # must match test-requirements.txt
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.7.0 # must match test-requirements.txt
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.272 # must match test-requirements.txt
rev: v0.0.280 # must match test-requirements.txt
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
ci:
autoupdate_schedule: quarterly
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Mypy (and mypyc) are licensed under the terms of the MIT license, reproduced bel

The MIT License

Copyright (c) 2012-2022 Jukka Lehtosalo and contributors
Copyright (c) 2015-2022 Dropbox, Inc.
Copyright (c) 2012-2023 Jukka Lehtosalo and contributors
Copyright (c) 2015-2023 Dropbox, Inc.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ graft test-data
include conftest.py
include runtests.py
include pytest.ini
include tox.ini

include LICENSE mypyc/README.md
exclude .gitmodules CONTRIBUTING.md CREDITS ROADMAP.md tox.ini action.yml .editorconfig
exclude .gitmodules CONTRIBUTING.md CREDITS ROADMAP.md action.yml .editorconfig
exclude .git-blame-ignore-revs .pre-commit-config.yaml

global-exclude *.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/cheat_sheet_py3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Functions
print(value + "!" * excitement)
# Note that arguments without a type are dynamically typed (treated as Any)
# and that functions without any annotations not checked
# and that functions without any annotations are not checked
def untyped(x):
x.anything() + 1 + "string" # no errors
Expand Down
9 changes: 8 additions & 1 deletion docs/source/class_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ override has a compatible signature:

In order to ensure that your code remains correct when renaming methods,
it can be helpful to explicitly mark a method as overriding a base
method. This can be done with the ``@override`` decorator. If the base
method. This can be done with the ``@override`` decorator. ``@override``
can be imported from ``typing`` starting with Python 3.12 or from
``typing_extensions`` for use with older Python versions. If the base
method is then renamed while the overriding method is not, mypy will
show an error:

Expand All @@ -233,6 +235,11 @@ show an error:
def g(self, y: str) -> None: # Error: no corresponding base method found
...
.. note::

Use :ref:`--enable-error-code explicit-override <code-explicit-override>` to require
that method overrides use the ``@override`` decorator. Emit an error if it is missing.

You can also override a statically typed method with a dynamically
typed one. This allows dynamically typed code to override methods
defined in library classes without worrying about their type
Expand Down
38 changes: 34 additions & 4 deletions docs/source/error_code_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,18 @@ the issue:
.. _code-import:

Check that import target can be found [import]
----------------------------------------------
Check for an issue with imports [import]
----------------------------------------

Mypy generates an error if it can't resolve an `import` statement.
This is a parent error code of `import-not-found` and `import-untyped`

See :ref:`ignore-missing-imports` for how to work around these errors.

.. _code-import-not-found:

Check that import target can be found [import-not-found]
--------------------------------------------------------

Mypy generates an error if it can't find the source code or a stub file
for an imported module.
Expand All @@ -658,11 +668,31 @@ Example:

.. code-block:: python
# Error: Cannot find implementation or library stub for module named 'acme' [import]
import acme
# Error: Cannot find implementation or library stub for module named "m0dule_with_typo" [import-not-found]
import m0dule_with_typo
See :ref:`ignore-missing-imports` for how to work around these errors.

.. _code-import-untyped:

Check that import target can be found [import-untyped]
--------------------------------------------------------

Mypy generates an error if it can find the source code for an imported module,
but that module does not provide type annotations (via :ref:`PEP 561 <installed-packages>`).

Example:

.. code-block:: python
# Error: Library stubs not installed for "bs4" [import-untyped]
import bs4
# Error: Skipping analyzing "no_py_typed": module is installed, but missing library stubs or py.typed marker [import-untyped]
import no_py_typed
In some cases, these errors can be fixed by installing an appropriate
stub package. See :ref:`ignore-missing-imports` for more details.

.. _code-no-redef:

Check that each name is defined once [no-redef]
Expand Down
39 changes: 39 additions & 0 deletions docs/source/error_code_list2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,42 @@ Example:
# The following will not generate an error on either
# Python 3.8, or Python 3.9
42 + "testing..." # type: ignore
.. _code-explicit-override:

Check that ``@override`` is used when overriding a base class method [explicit-override]
----------------------------------------------------------------------------------------

If you use :option:`--enable-error-code explicit-override <mypy --enable-error-code>`
mypy generates an error if you override a base class method without using the
``@override`` decorator. An error will not be emitted for overrides of ``__init__``
or ``__new__``. See `PEP 698 <https://peps.python.org/pep-0698/#strict-enforcement-per-project>`_.

.. note::

Starting with Python 3.12, the ``@override`` decorator can be imported from ``typing``.
To use it with older Python versions, import it from ``typing_extensions`` instead.

Example:

.. code-block:: python
# Use "mypy --enable-error-code explicit-override ..."
from typing import override
class Parent:
def f(self, x: int) -> None:
pass
def g(self, y: int) -> None:
pass
class Child(Parent):
def f(self, x: int) -> None: # Error: Missing @override decorator
pass
@override
def g(self, y: int) -> None:
pass
23 changes: 10 additions & 13 deletions docs/source/error_codes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ Silencing errors based on error codes
You can use a special comment ``# type: ignore[code, ...]`` to only
ignore errors with a specific error code (or codes) on a particular
line. This can be used even if you have not configured mypy to show
error codes. Currently it's only possible to disable arbitrary error
codes on individual lines using this comment.

You can also use :option:`--disable-error-code <mypy --disable-error-code>`
to disable specific error codes globally.
error codes.

This example shows how to ignore an error about an imported name mypy
thinks is undefined:
Expand All @@ -58,17 +54,17 @@ thinks is undefined:
# definition.
from foolib import foo # type: ignore[attr-defined]
Enabling specific error codes
-----------------------------
Enabling/disabling specific error codes globally
------------------------------------------------

There are command-line flags and config file settings for enabling
certain optional error codes, such as :option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>`,
which enables the ``no-untyped-def`` error code.

You can use :option:`--enable-error-code <mypy --enable-error-code>` to
enable specific error codes that don't have a dedicated command-line
flag or config file setting.
You can use :option:`--enable-error-code <mypy --enable-error-code>`
and :option:`--disable-error-code <mypy --disable-error-code>`
to enable or disable specific error codes that don't have a dedicated
command-line flag or config file setting.

Per-module enabling/disabling error codes
-----------------------------------------
Expand Down Expand Up @@ -107,8 +103,9 @@ still keep the other two error codes enabled. The overall logic is following:

* Individual config sections *adjust* them per glob/module

* Inline ``# mypy: ...`` comments can further *adjust* them for a specific
module
* Inline ``# mypy: disable-error-code="..."`` comments can further
*adjust* them for a specific module.
For example: ``# mypy: disable-error-code="truthy-bool, ignore-without-code"``

So one can e.g. enable some code globally, disable it for all tests in
the corresponding config section, and then re-enable it with an inline
Expand Down
4 changes: 2 additions & 2 deletions docs/source/type_narrowing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Generic TypeGuards
else:
reveal_type(names) # tuple[str, ...]
Typeguards with parameters
TypeGuards with parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~

Type guard functions can accept extra arguments:
Expand All @@ -293,7 +293,7 @@ Type guard functions can accept extra arguments:
TypeGuards as methods
~~~~~~~~~~~~~~~~~~~~~

A method can also serve as the ``TypeGuard``:
A method can also serve as a ``TypeGuard``:

.. code-block:: python
Expand Down
Loading

0 comments on commit ad7e272

Please sign in to comment.