Skip to content

Commit

Permalink
Merge branch 'main' into dropbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul D.Smith committed Aug 13, 2024
2 parents 9eed859 + 89bb3c1 commit 2bdc084
Show file tree
Hide file tree
Showing 109 changed files with 2,831 additions and 267 deletions.
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"stubs/cffi",
"stubs/click-default-group",
"stubs/commonmark",
"stubs/corus",
"stubs/dateparser",
"stubs/defusedxml",
"stubs/docker",
Expand Down
2 changes: 1 addition & 1 deletion scripts/sync_tensorflow_protobuf_stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -euxo pipefail

# Whenever you update TENSORFLOW_VERSION here, version should be updated
# in stubs/tensorflow/METADATA.toml and vice-versa.
TENSORFLOW_VERSION=2.16.1
TENSORFLOW_VERSION=2.17.0
MYPY_PROTOBUF_VERSION=3.6.0

# brew install coreutils wget
Expand Down
1 change: 1 addition & 0 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ tkinter.simpledialog.[A-Z_]+
tkinter.simpledialog.TclVersion
tkinter.simpledialog.TkVersion
tkinter.Misc.after # we intentionally don't allow everything that "works" at runtime
tkinter.Text.count # stubtest somehow thinks that index1 parameter has a default value, but it doesn't in any of the overloads
traceback.TracebackException.from_exception # explicitly expanding arguments going into TracebackException __init__
typing(_extensions)?\.IO\.__next__ # Added because IO streams are iterable. See https://github.com/python/typeshed/commit/97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3
typing.type_check_only # typing decorator that is not available at runtime
Expand Down
6 changes: 6 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py313.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,9 @@ codecs.xmlcharrefreplace_errors

# To match `dict`, we lie about the runtime, but use overloads to match the correct behavior
types.MappingProxyType.get

# logging.warn() was restored after the 3.13 release candidate, which is what CI is using
logging.__all__
logging.Logger.warn
logging.LoggerAdapter.warn
logging.warn
24 changes: 24 additions & 0 deletions stdlib/@tests/test_cases/check_tkinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import tkinter
import traceback
import types
from typing import Optional, Tuple
from typing_extensions import assert_type


def custom_handler(exc: type[BaseException], val: BaseException, tb: types.TracebackType | None) -> None:
Expand All @@ -28,3 +30,25 @@ def foo(x: int, y: str) -> None:
label.config(font=("", 12.34)) # type: ignore
label.config(font=("", 12, "bold"))
label.config(font=("", 12.34, "bold")) # type: ignore


# Test the `.count()` method. Comments show values that are returned at runtime.
t = tkinter.Text()
t.insert("end", "asd asd asd\nasd asd")

assert_type(t.count("1.0", "2.3"), Optional[Tuple[int]]) # (15,)
assert_type(t.count("2.3", "2.3"), Optional[Tuple[int]]) # None
assert_type(t.count("1.0", "2.3", "indices"), Optional[Tuple[int]]) # (15,)
assert_type(t.count("2.3", "2.3", "indices"), Optional[Tuple[int]]) # None
assert_type(t.count("1.0", "2.3", "indices", "update"), Optional[int]) # 15
assert_type(t.count("2.3", "2.3", "indices", "update"), Optional[int]) # None
assert_type(t.count("1.0", "2.3", "indices", "lines"), Tuple[int, int]) # (15, 1)
assert_type(t.count("2.3", "2.3", "indices", "lines"), Tuple[int, int]) # (0, 0)
assert_type(t.count("1.0", "2.3", "indices", "lines", "update"), Tuple[int, ...]) # (15, 1)
assert_type(t.count("2.3", "2.3", "indices", "lines", "update"), Tuple[int, ...]) # (0, 0)
assert_type(t.count("1.0", "2.3", "indices", "lines", "chars"), Tuple[int, ...]) # (15, 1, 15)
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars"), Tuple[int, ...]) # (0, 0, 0)
assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update"), Tuple[int, ...]) # (15, 1, 15)
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update"), Tuple[int, ...]) # (0, 0, 0)
assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (15, 1, 15, 19)
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (0, 0, 0, 0)
131 changes: 131 additions & 0 deletions stdlib/@tests/test_cases/check_zipfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
from __future__ import annotations

import io
import pathlib
import zipfile
from typing import Literal

###
# Tests for `zipfile.ZipFile`
###

p = pathlib.Path("test.zip")


class CustomPathObj:
def __init__(self, path: str) -> None:
self.path = path

def __fspath__(self) -> str:
return self.path


class NonPathObj:
def __init__(self, path: str) -> None:
self.path = path


class ReadableObj:
def seek(self, offset: int, whence: int = 0) -> int:
return 0

def read(self, n: int | None = -1) -> bytes:
return b"test"


class TellableObj:
def tell(self) -> int:
return 0


class WriteableObj:
def close(self) -> None:
pass

def write(self, b: bytes) -> int:
return len(b)

def flush(self) -> None:
pass


class ReadTellableObj(ReadableObj):
def tell(self) -> int:
return 0


class SeekTellObj:
def seek(self, offset: int, whence: int = 0) -> int:
return 0

def tell(self) -> int:
return 0


def write_zip(mode: Literal["r", "w", "x", "a"]) -> None:
# Test any mode with `pathlib.Path`
with zipfile.ZipFile(p, mode) as z:
z.writestr("test.txt", "test")

# Test any mode with `str` path
with zipfile.ZipFile("test.zip", mode) as z:
z.writestr("test.txt", "test")

# Test any mode with `os.PathLike` object
with zipfile.ZipFile(CustomPathObj("test.zip"), mode) as z:
z.writestr("test.txt", "test")

# Non-PathLike object should raise an error
with zipfile.ZipFile(NonPathObj("test.zip"), mode) as z: # type: ignore
z.writestr("test.txt", "test")

# IO[bytes] like-obj should work for any mode.
io_obj = io.BytesIO(b"This is a test")
with zipfile.ZipFile(io_obj, mode) as z:
z.writestr("test.txt", "test")

# Readable object should not work for any mode.
with zipfile.ZipFile(ReadableObj(), mode) as z: # type: ignore
z.writestr("test.txt", "test")

# Readable object should work for "r" mode.
with zipfile.ZipFile(ReadableObj(), "r") as z:
z.writestr("test.txt", "test")

# Readable/tellable object should work for "a" mode.
with zipfile.ZipFile(ReadTellableObj(), "a") as z:
z.writestr("test.txt", "test")

# If it doesn't have 'tell' method, it should raise an error.
with zipfile.ZipFile(ReadableObj(), "a") as z: # type: ignore
z.writestr("test.txt", "test")

# Readable object should not work for "w" mode.
with zipfile.ZipFile(ReadableObj(), "w") as z: # type: ignore
z.writestr("test.txt", "test")

# Tellable object should not work for any mode.
with zipfile.ZipFile(TellableObj(), mode) as z: # type: ignore
z.writestr("test.txt", "test")

# Tellable object shouldn't work for "w" mode.
# As `__del__` will call close.
with zipfile.ZipFile(TellableObj(), "w") as z: # type: ignore
z.writestr("test.txt", "test")

# Writeable object should not work for any mode.
with zipfile.ZipFile(WriteableObj(), mode) as z: # type: ignore
z.writestr("test.txt", "test")

# Writeable object should work for "w" mode.
with zipfile.ZipFile(WriteableObj(), "w") as z:
z.writestr("test.txt", "test")

# Seekable and Tellable object should not work for any mode.
with zipfile.ZipFile(SeekTellObj(), mode) as z: # type: ignore
z.writestr("test.txt", "test")

# Seekable and Tellable object shouldn't work for "w" mode.
# Cause `__del__` will call close.
with zipfile.ZipFile(SeekTellObj(), "w") as z: # type: ignore
z.writestr("test.txt", "test")
8 changes: 5 additions & 3 deletions stdlib/_ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,11 @@ class Constant(expr):
__match_args__ = ("value", "kind")
value: Any # None, str, bytes, bool, int, float, complex, Ellipsis
kind: str | None
# Aliases for value, for backwards compatibility
s: Any
n: int | float | complex
if sys.version_info < (3, 14):
# Aliases for value, for backwards compatibility
s: Any
n: int | float | complex

def __init__(self, value: Any, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ...

class NamedExpr(expr):
Expand Down
12 changes: 11 additions & 1 deletion stdlib/argparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,17 @@ class Action(_AttributeHolder):

if sys.version_info >= (3, 12):
class BooleanOptionalAction(Action):
if sys.version_info >= (3, 13):
if sys.version_info >= (3, 14):
def __init__(
self,
option_strings: Sequence[str],
dest: str,
default: bool | None = None,
required: bool = False,
help: str | None = None,
deprecated: bool = False,
) -> None: ...
elif sys.version_info >= (3, 13):
@overload
def __init__(
self,
Expand Down
35 changes: 18 additions & 17 deletions stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@ class _ABC(type):
if sys.version_info >= (3, 9):
def __init__(cls, *args: Unused) -> None: ...

@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
class Num(Constant, metaclass=_ABC):
value: int | float | complex
if sys.version_info < (3, 14):
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Num(Constant, metaclass=_ABC):
value: int | float | complex

@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
class Str(Constant, metaclass=_ABC):
value: str
# Aliases for value, for backwards compatibility
s: str
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Str(Constant, metaclass=_ABC):
value: str
# Aliases for value, for backwards compatibility
s: str

@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
class Bytes(Constant, metaclass=_ABC):
value: bytes
# Aliases for value, for backwards compatibility
s: bytes
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Bytes(Constant, metaclass=_ABC):
value: bytes
# Aliases for value, for backwards compatibility
s: bytes

@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
class NameConstant(Constant, metaclass=_ABC): ...
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class NameConstant(Constant, metaclass=_ABC): ...

@deprecated("Replaced by ast.Constant; removal scheduled for Python 3.14")
class Ellipsis(Constant, metaclass=_ABC): ...
@deprecated("Replaced by ast.Constant; removed in Python 3.14")
class Ellipsis(Constant, metaclass=_ABC): ...

if sys.version_info >= (3, 9):
class slice(AST): ...
Expand Down
2 changes: 2 additions & 0 deletions stdlib/contextlib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class AbstractAsyncContextManager(Protocol[_T_co, _ExitT_co]):
) -> _ExitT_co: ...

class ContextDecorator:
def _recreate_cm(self) -> Self: ...
def __call__(self, func: _F) -> _F: ...

class _GeneratorContextManager(AbstractContextManager[_T_co, bool | None], ContextDecorator):
Expand All @@ -80,6 +81,7 @@ if sys.version_info >= (3, 10):
_AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]])

class AsyncContextDecorator:
def _recreate_cm(self) -> Self: ...
def __call__(self, func: _AF) -> _AF: ...

class _AsyncGeneratorContextManager(AbstractAsyncContextManager[_T_co, bool | None], AsyncContextDecorator):
Expand Down
Loading

0 comments on commit 2bdc084

Please sign in to comment.