Skip to content

Commit

Permalink
Merge branch 'python:master' into pythongh-16649-type-comments-and-co…
Browse files Browse the repository at this point in the history
…nstrained-generics
  • Loading branch information
picnixz authored Jun 23, 2024
2 parents b9b31a5 + abdaf6a commit 92dfc73
Show file tree
Hide file tree
Showing 273 changed files with 8,629 additions and 2,157 deletions.
11 changes: 11 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,17 @@ in error messages.

main.py:12:9: error: Unsupported operand types for / ("int" and "str")

.. option:: --show-error-code-links

This flag will also display a link to error code documentation, anchored to the error code reported by mypy.
The corresponding error code will be highlighted within the documentation page.
If we enable this flag, the error message now looks like this::

main.py:3: error: Unsupported operand types for - ("int" and "str") [operator]
main.py:3: note: See 'https://mypy.rtfd.io/en/stable/_refs.html#code-operator' for more info



.. option:: --show-error-end

This flag will make mypy show not just that start position where
Expand Down
7 changes: 7 additions & 0 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,13 @@ These options may only be set in the global section (``[mypy]``).

Shows column numbers in error messages.

.. confval:: show_error_code_links

:type: boolean
:default: False

Shows documentation link to corresponding error code.

.. confval:: hide_error_codes

:type: boolean
Expand Down
20 changes: 10 additions & 10 deletions docs/source/error_code_list2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Error codes for optional checks

This section documents various errors codes that mypy generates only
if you enable certain options. See :ref:`error-codes` for general
documentation about error codes. :ref:`error-code-list` documents
error codes that are enabled by default.
documentation about error codes and their configuration.
:ref:`error-code-list` documents error codes that are enabled by default.

.. note::

Expand Down Expand Up @@ -241,7 +241,7 @@ mypy generates an error if it thinks that an expression is redundant.

.. code-block:: python
# Use "mypy --enable-error-code redundant-expr ..."
# mypy: enable-error-code="redundant-expr"
def example(x: int) -> None:
# Error: Left operand of "and" is always true [redundant-expr]
Expand All @@ -268,7 +268,7 @@ example:

.. code-block:: python
# Use "mypy --enable-error-code possibly-undefined ..."
# mypy: enable-error-code="possibly-undefined"
from typing import Iterable
Expand Down Expand Up @@ -297,7 +297,7 @@ Using an iterable value in a boolean context has a separate error code

.. code-block:: python
# Use "mypy --enable-error-code truthy-bool ..."
# mypy: enable-error-code="truthy-bool"
class Foo:
pass
Expand Down Expand Up @@ -347,7 +347,7 @@ Example:

.. code-block:: python
# Use "mypy --enable-error-code ignore-without-code ..."
# mypy: enable-error-code="ignore-without-code"
class Foo:
def __init__(self, name: str) -> None:
Expand Down Expand Up @@ -378,7 +378,7 @@ Example:

.. code-block:: python
# Use "mypy --enable-error-code unused-awaitable ..."
# mypy: enable-error-code="unused-awaitable"
import asyncio
Expand Down Expand Up @@ -462,7 +462,7 @@ Example:

.. code-block:: python
# Use "mypy --enable-error-code explicit-override ..."
# mypy: enable-error-code="explicit-override"
from typing import override
Expand Down Expand Up @@ -536,7 +536,7 @@ Now users can actually import ``reveal_type`` to make the runtime code safe.

.. code-block:: python
# Use "mypy --enable-error-code unimported-reveal"
# mypy: enable-error-code="unimported-reveal"
x = 1
reveal_type(x) # Note: Revealed type is "builtins.int" \
Expand All @@ -546,7 +546,7 @@ Correct usage:

.. code-block:: python
# Use "mypy --enable-error-code unimported-reveal"
# mypy: enable-error-code="unimported-reveal"
from typing import reveal_type # or `typing_extensions`
x = 1
Expand Down
10 changes: 7 additions & 3 deletions docs/source/error_codes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ still keep the other two error codes enabled. The overall logic is following:

* Individual config sections *adjust* them per glob/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"``
* Inline ``# mypy: disable-error-code="..."`` and ``# mypy: enable-error-code="..."``
comments can further *adjust* them for a specific file.
For example:

.. code-block:: python
# mypy: enable-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
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
From 5c00e362d40aa26e0a22a740f05a52d05edf0f91 Mon Sep 17 00:00:00 2001
From 3ec9b878d6bbe3fae64a508a62372f10a886406f Mon Sep 17 00:00:00 2001
From: Shantanu <[email protected]>
Date: Mon, 26 Sep 2022 12:55:07 -0700
Subject: [PATCH] Remove use of LiteralString in builtins (#13743)

---
mypy/typeshed/stdlib/builtins.pyi | 88 -------------------------------
1 file changed, 88 deletions(-)
mypy/typeshed/stdlib/builtins.pyi | 95 -------------------------------
1 file changed, 95 deletions(-)

diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
index b4765b26c..99919c64c 100644
index 53e00ec6a..bad3250ef 100644
--- a/mypy/typeshed/stdlib/builtins.pyi
+++ b/mypy/typeshed/stdlib/builtins.pyi
@@ -61,7 +61,6 @@ from typing import ( # noqa: Y022
Expand All @@ -19,7 +19,7 @@ index b4765b26c..99919c64c 100644
ParamSpec,
Self,
TypeAlias,
@@ -434,31 +433,16 @@ class str(Sequence[str]):
@@ -435,31 +434,16 @@ class str(Sequence[str]):
def __new__(cls, object: object = ...) -> Self: ...
@overload
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
Expand Down Expand Up @@ -49,9 +49,9 @@ index b4765b26c..99919c64c 100644
- def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
- @overload
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, map: _FormatMapMapping) -> str: ...
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@@ -474,89 +458,32 @@ class str(Sequence[str]):
@@ -475,99 +459,35 @@ class str(Sequence[str]):
def isspace(self) -> bool: ...
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
Expand All @@ -75,10 +75,20 @@ index b4765b26c..99919c64c 100644
- def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
- @overload
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
- @overload
- def replace(self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /) -> LiteralString: ...
- @overload
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 13):
- @overload
- def replace(
- self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
- ) -> LiteralString: ...
- @overload
def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
else:
- @overload
- def replace(
- self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
- ) -> LiteralString: ...
- @overload
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 9):
- @overload
- def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
Expand Down Expand Up @@ -141,7 +151,7 @@ index b4765b26c..99919c64c 100644
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
@staticmethod
@overload
@@ -567,9 +494,6 @@ class str(Sequence[str]):
@@ -578,9 +498,6 @@ class str(Sequence[str]):
@staticmethod
@overload
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
Expand All @@ -151,7 +161,7 @@ index b4765b26c..99919c64c 100644
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
# Incompatible with Sequence.__contains__
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
@@ -578,25 +502,13 @@ class str(Sequence[str]):
@@ -589,25 +506,13 @@ class str(Sequence[str]):
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
def __gt__(self, value: str, /) -> bool: ...
def __hash__(self) -> int: ...
Expand All @@ -178,5 +188,5 @@ index b4765b26c..99919c64c 100644
def __getnewargs__(self) -> tuple[str]: ...

--
2.39.3 (Apple Git-146)
2.45.2

3 changes: 2 additions & 1 deletion mypy-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# NOTE: this needs to be kept in sync with the "requires" list in pyproject.toml
typing_extensions>=4.1.0
# and the pins in setup.py
typing_extensions>=4.6.0
mypy_extensions>=1.0.0
tomli>=1.1.0; python_version<'3.11'
Loading

0 comments on commit 92dfc73

Please sign in to comment.