Skip to content

Commit

Permalink
Merge branch 'python:master' into c-a
Browse files Browse the repository at this point in the history
  • Loading branch information
clintaire committed Sep 15, 2024
2 parents cc5a3ef + 5c38427 commit c84e2ef
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 266 deletions.
310 changes: 155 additions & 155 deletions CHANGELOG.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sphinx>=5.1.0
furo>=2022.3.4
myst-parser>=4.0.0
3 changes: 3 additions & 0 deletions docs/source/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- This file includes mypy/CHANGELOG.md into mypy documentation -->
```{include} ../../CHANGELOG.md
```
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx.ext.intersphinx", "docs.source.html_builder"]
extensions = ["sphinx.ext.intersphinx", "docs.source.html_builder", "myst_parser"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Contents
error_code_list2
additional_features
faq
changelog

.. toctree::
:hidden:
Expand Down
13 changes: 11 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5651,7 +5651,16 @@ def _is_truthy_type(self, t: ProperType) -> bool:
)
)

def _check_for_truthy_type(self, t: Type, expr: Expression) -> None:
def check_for_truthy_type(self, t: Type, expr: Expression) -> None:
"""
Check if a type can have a truthy value.
Used in checks like::
if x: # <---
not x # <---
"""
if not state.strict_optional:
return # if everything can be None, all bets are off

Expand Down Expand Up @@ -6145,7 +6154,7 @@ def has_no_custom_eq_checks(t: Type) -> bool:
if in_boolean_context:
# We don't check `:=` values in expressions like `(a := A())`,
# because they produce two error messages.
self._check_for_truthy_type(original_vartype, node)
self.check_for_truthy_type(original_vartype, node)
vartype = try_expanding_sum_type_to_union(original_vartype, "builtins.bool")

if_type = true_only(vartype)
Expand Down
1 change: 1 addition & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4256,6 +4256,7 @@ def visit_unary_expr(self, e: UnaryExpr) -> Type:
op = e.op
if op == "not":
result: Type = self.bool_type()
self.chk.check_for_truthy_type(operand_type, e.expr)
else:
method = operators.unary_op_methods[op]
result, method_type = self.check_method_call_by_name(method, operand_type, [], [], e)
Expand Down
2 changes: 2 additions & 0 deletions mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ def on_finish(self) -> None:
self.root_package.covered_lines, self.root_package.total_lines
)
self.root.attrib["branch-rate"] = "0"
self.root.attrib["lines-covered"] = str(self.root_package.covered_lines)
self.root.attrib["lines-valid"] = str(self.root_package.total_lines)
sources = etree.SubElement(self.root, "sources")
source_element = etree.SubElement(sources, "source")
source_element.text = os.getcwd()
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ _json: 3.0-
_locale: 3.0-
_lsprof: 3.0-
_markupbase: 3.0-
_msi: 3.0-
_msi: 3.0-3.12
_operator: 3.4-
_osx_support: 3.0-
_posixsubprocess: 3.2-
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/_curses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class _CursesWindow:
def instr(self, y: int, x: int, n: int = ...) -> bytes: ...
def is_linetouched(self, line: int, /) -> bool: ...
def is_wintouched(self) -> bool: ...
def keypad(self, yes: bool) -> None: ...
def keypad(self, yes: bool, /) -> None: ...
def leaveok(self, yes: bool) -> None: ...
def move(self, new_y: int, new_x: int) -> None: ...
def mvderwin(self, y: int, x: int) -> None: ...
Expand Down
149 changes: 85 additions & 64 deletions mypy/typeshed/stdlib/_locale.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import sys
from _typeshed import StrPath
from collections.abc import Mapping
from typing import Final, Literal, TypedDict, type_check_only

LC_CTYPE: int
LC_COLLATE: int
LC_TIME: int
LC_MONETARY: int
LC_NUMERIC: int
LC_ALL: int
CHAR_MAX: int
@type_check_only
class _LocaleConv(TypedDict):
decimal_point: str
grouping: list[int]
thousands_sep: str
int_curr_symbol: str
currency_symbol: str
p_cs_precedes: Literal[0, 1, 127]
n_cs_precedes: Literal[0, 1, 127]
p_sep_by_space: Literal[0, 1, 127]
n_sep_by_space: Literal[0, 1, 127]
mon_decimal_point: str
frac_digits: int
int_frac_digits: int
mon_thousands_sep: str
mon_grouping: list[int]
positive_sign: str
negative_sign: str
p_sign_posn: Literal[0, 1, 2, 3, 4, 127]
n_sign_posn: Literal[0, 1, 2, 3, 4, 127]

LC_CTYPE: Final[int]
LC_COLLATE: Final[int]
LC_TIME: Final[int]
LC_MONETARY: Final[int]
LC_NUMERIC: Final[int]
LC_ALL: Final[int]
CHAR_MAX: Final = 127

def setlocale(category: int, locale: str | None = None, /) -> str: ...
def localeconv() -> Mapping[str, int | str | list[int]]: ...
def localeconv() -> _LocaleConv: ...

if sys.version_info >= (3, 11):
def getencoding() -> str: ...
Expand All @@ -25,67 +46,67 @@ def strxfrm(string: str, /) -> str: ...
if sys.platform != "win32":
LC_MESSAGES: int

ABDAY_1: int
ABDAY_2: int
ABDAY_3: int
ABDAY_4: int
ABDAY_5: int
ABDAY_6: int
ABDAY_7: int
ABDAY_1: Final[int]
ABDAY_2: Final[int]
ABDAY_3: Final[int]
ABDAY_4: Final[int]
ABDAY_5: Final[int]
ABDAY_6: Final[int]
ABDAY_7: Final[int]

ABMON_1: int
ABMON_2: int
ABMON_3: int
ABMON_4: int
ABMON_5: int
ABMON_6: int
ABMON_7: int
ABMON_8: int
ABMON_9: int
ABMON_10: int
ABMON_11: int
ABMON_12: int
ABMON_1: Final[int]
ABMON_2: Final[int]
ABMON_3: Final[int]
ABMON_4: Final[int]
ABMON_5: Final[int]
ABMON_6: Final[int]
ABMON_7: Final[int]
ABMON_8: Final[int]
ABMON_9: Final[int]
ABMON_10: Final[int]
ABMON_11: Final[int]
ABMON_12: Final[int]

DAY_1: int
DAY_2: int
DAY_3: int
DAY_4: int
DAY_5: int
DAY_6: int
DAY_7: int
DAY_1: Final[int]
DAY_2: Final[int]
DAY_3: Final[int]
DAY_4: Final[int]
DAY_5: Final[int]
DAY_6: Final[int]
DAY_7: Final[int]

ERA: int
ERA_D_T_FMT: int
ERA_D_FMT: int
ERA_T_FMT: int
ERA: Final[int]
ERA_D_T_FMT: Final[int]
ERA_D_FMT: Final[int]
ERA_T_FMT: Final[int]

MON_1: int
MON_2: int
MON_3: int
MON_4: int
MON_5: int
MON_6: int
MON_7: int
MON_8: int
MON_9: int
MON_10: int
MON_11: int
MON_12: int
MON_1: Final[int]
MON_2: Final[int]
MON_3: Final[int]
MON_4: Final[int]
MON_5: Final[int]
MON_6: Final[int]
MON_7: Final[int]
MON_8: Final[int]
MON_9: Final[int]
MON_10: Final[int]
MON_11: Final[int]
MON_12: Final[int]

CODESET: int
D_T_FMT: int
D_FMT: int
T_FMT: int
T_FMT_AMPM: int
AM_STR: int
PM_STR: int
CODESET: Final[int]
D_T_FMT: Final[int]
D_FMT: Final[int]
T_FMT: Final[int]
T_FMT_AMPM: Final[int]
AM_STR: Final[int]
PM_STR: Final[int]

RADIXCHAR: int
THOUSEP: int
YESEXPR: int
NOEXPR: int
CRNCYSTR: int
ALT_DIGITS: int
RADIXCHAR: Final[int]
THOUSEP: Final[int]
YESEXPR: Final[int]
NOEXPR: Final[int]
CRNCYSTR: Final[int]
ALT_DIGITS: Final[int]

def nl_langinfo(key: int, /) -> str: ...

Expand Down
28 changes: 28 additions & 0 deletions mypy/typeshed/stdlib/_winapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ if sys.platform == "win32":
SEC_RESERVE: Final = 0x4000000
SEC_WRITECOMBINE: Final = 0x40000000

if sys.version_info >= (3, 13):
STARTF_FORCEOFFFEEDBACK: Final = 0x80
STARTF_FORCEONFEEDBACK: Final = 0x40
STARTF_PREVENTPINNING: Final = 0x2000
STARTF_RUNFULLSCREEN: Final = 0x20
STARTF_TITLEISAPPID: Final = 0x1000
STARTF_TITLEISLINKNAME: Final = 0x800
STARTF_UNTRUSTEDSOURCE: Final = 0x8000
STARTF_USECOUNTCHARS: Final = 0x8
STARTF_USEFILLATTRIBUTE: Final = 0x10
STARTF_USEHOTKEY: Final = 0x200
STARTF_USEPOSITION: Final = 0x4
STARTF_USESIZE: Final = 0x2

STARTF_USESHOWWINDOW: Final = 0x1
STARTF_USESTDHANDLES: Final = 0x100

Expand Down Expand Up @@ -250,6 +264,20 @@ if sys.platform == "win32":
def cancel(self) -> None: ...
def getbuffer(self) -> bytes | None: ...

if sys.version_info >= (3, 13):
def BatchedWaitForMultipleObjects(
handle_seq: Sequence[int], wait_all: bool, milliseconds: int = 0xFFFFFFFF
) -> list[int]: ...
def CreateEventW(security_attributes: int, manual_reset: bool, initial_state: bool, name: str | None) -> int: ...
def CreateMutexW(security_attributes: int, initial_owner: bool, name: str) -> int: ...
def GetLongPathName(path: str) -> str: ...
def GetShortPathName(path: str) -> str: ...
def OpenEventW(desired_access: int, inherit_handle: bool, name: str) -> int: ...
def OpenMutexW(desired_access: int, inherit_handle: bool, name: str) -> int: ...
def ReleaseMutex(mutex: int) -> None: ...
def ResetEvent(event: int) -> None: ...
def SetEvent(event: int) -> None: ...

if sys.version_info >= (3, 12):
def CopyFile2(existing_file_name: str, new_file_name: str, flags: int, progress_routine: int | None = None) -> int: ...
def NeedCurrentDirectoryForExePath(exe_name: str, /) -> bool: ...
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: PYI036 # This is the module declaring BaseException
import _ast
import _typeshed
import sys
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeshed/stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _Encoder(Protocol):
def __call__(self, input: str, errors: str = ..., /) -> tuple[bytes, int]: ... # signature of Codec().encode

class _Decoder(Protocol):
def __call__(self, input: bytes, errors: str = ..., /) -> tuple[str, int]: ... # signature of Codec().decode
def __call__(self, input: ReadableBuffer, errors: str = ..., /) -> tuple[str, int]: ... # signature of Codec().decode

class _StreamReader(Protocol):
def __call__(self, stream: _ReadableStream, errors: str = ..., /) -> StreamReader: ...
Expand Down
9 changes: 4 additions & 5 deletions mypy/typeshed/stdlib/copy.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import sys
from typing import Any, Protocol, TypeVar
from typing_extensions import ParamSpec, Self
from typing_extensions import Self

__all__ = ["Error", "copy", "deepcopy"]

_T = TypeVar("_T")
_SR = TypeVar("_SR", bound=_SupportsReplace[Any])
_P = ParamSpec("_P")
_SR = TypeVar("_SR", bound=_SupportsReplace)

class _SupportsReplace(Protocol[_P]):
class _SupportsReplace(Protocol):
# In reality doesn't support args, but there's no other great way to express this.
def __replace__(self, *args: _P.args, **kwargs: _P.kwargs) -> Self: ...
def __replace__(self, *args: Any, **kwargs: Any) -> Self: ...

# None in CPython but non-None in Jython
PyStringMap: Any
Expand Down
25 changes: 24 additions & 1 deletion mypy/typeshed/stdlib/distutils/dist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class Distribution:
def has_data_files(self) -> bool: ...
def is_pure(self) -> bool: ...

# Getter methods generated in __init__
# Default getter methods generated in __init__ from self.metadata._METHOD_BASENAMES
def get_name(self) -> str: ...
def get_version(self) -> str: ...
def get_fullname(self) -> str: ...
Expand All @@ -292,3 +292,26 @@ class Distribution:
def get_requires(self) -> list[str]: ...
def get_provides(self) -> list[str]: ...
def get_obsoletes(self) -> list[str]: ...

# Default attributes generated in __init__ from self.display_option_names
help_commands: bool | Literal[0]
name: str | Literal[0]
version: str | Literal[0]
fullname: str | Literal[0]
author: str | Literal[0]
author_email: str | Literal[0]
maintainer: str | Literal[0]
maintainer_email: str | Literal[0]
contact: str | Literal[0]
contact_email: str | Literal[0]
url: str | Literal[0]
license: str | Literal[0]
licence: str | Literal[0]
description: str | Literal[0]
long_description: str | Literal[0]
platforms: str | list[str] | Literal[0]
classifiers: str | list[str] | Literal[0]
keywords: str | list[str] | Literal[0]
provides: list[str] | Literal[0]
requires: list[str] | Literal[0]
obsoletes: list[str] | Literal[0]
Loading

0 comments on commit c84e2ef

Please sign in to comment.