Skip to content

Commit

Permalink
Merge branch 'main' into fix/12628
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Sunglasses committed Sep 17, 2024
2 parents 7d754a8 + 0015ce8 commit e23814c
Show file tree
Hide file tree
Showing 49 changed files with 859 additions and 249 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/meta_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
# Max supported Python version as of pytype 2024.2.27.
python-version: "3.11"
python-version: "3.12"
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- run: uv pip install -r requirements-tests.txt --system
- name: Run pyright on typeshed
uses: jakebailey/pyright-action@v2
with:
version: PATH
python-platform: ${{ matrix.python-platform }}
python-version: "3.9" # The Python version to test against.
python-version: "3.9" # Oldest version supported for running scripts and tests
project: ./pyrightconfig.scripts_and_tests.json
stubsabot-dry-run:
name: Stubsabot dry run
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
# Max supported Python version as of pytype 2024.9.13.
# Max supported Python version as of pytype 2024.9.13
python-version: "3.12"
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
Expand Down
25 changes: 11 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ range of Python users and Python codebases. If you're trying a type
checker on your Python code, your experience and what you can contribute
are important to the project's success.


## The contribution process at a glance

1. [Prepare your environment](#preparing-the-environment).
Expand Down Expand Up @@ -51,10 +50,10 @@ please refer to this

Note that some tests require extra setup steps to install the required dependencies.

### Linux/Mac OS
### Linux/Mac OS/WSL

On Linux and Mac OS, you will be able to run the full test suite on Python
3.9, 3.10, or 3.11.
3.9-3.12.
To install the necessary requirements, run the following commands from a
terminal window:

Expand All @@ -67,24 +66,22 @@ $ source .venv/bin/activate

### Windows

If you are using a Windows operating system, you will not be able to run the pytype
tests, as pytype
[does not currently support running on Windows](https://github.com/google/pytype#requirements).
One option is to install
[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/faq),
which will allow you to run the full suite of tests. If you choose to install
WSL, follow the Linux/Mac OS instructions above.

If you do not wish to install WSL, run the following commands from a Windows
terminal to install all non-pytype requirements:
Run the following commands from a Windows terminal to install all requirements:

```powershell
> python -m venv .venv
> .venv\scripts\activate
> .venv\Scripts\activate
(.venv) > pip install -U pip
(.venv) > pip install -r "requirements-tests.txt"
```

To be able to run pytype tests, you'll also need to install it manually
as it's currently excluded from the requirements file:

```powershell
(.venv) > pip install -U pytype
```

## Code formatting

The code is formatted using [`Black`](https://github.com/psf/black).
Expand Down
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ flake8-pyi==24.6.0 # must match .pre-commit-config.yaml
mypy==1.11.1
pre-commit-hooks==4.6.0 # must match .pre-commit-config.yaml
pyright==1.1.379
# pytype can be installed on Windows, but requires building wheels, let's not do that on the CI
pytype==2024.9.13; platform_system != "Windows" and python_version < "3.13"
ruff==0.5.4 # must match .pre-commit-config.yaml

Expand Down
3 changes: 3 additions & 0 deletions stdlib/@tests/stubtest_allowlists/py312.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ platform.uname_result.processor
unittest.TestCase.__init_subclass__
unittest.case.TestCase.__init_subclass__

# Deprecated argument is supported at runtime by renaming it through a decorator.
importlib.resources._common.files
importlib.resources.files
# Problematic protocol signature at runtime, see source code comments.
importlib.abc.Traversable.open
importlib.resources.abc.Traversable.open
Expand Down
13 changes: 3 additions & 10 deletions stdlib/@tests/stubtest_allowlists/py313.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@

# TODO: triage these new errors
_tkinter.create
importlib.resources.Anchor
importlib.resources.Resource
importlib.resources.__all__
importlib.resources.contents
importlib.resources.is_resource
importlib.resources.open_binary
importlib.resources.open_text
importlib.resources.path
importlib.resources.read_binary
importlib.resources.read_text
os.path.splitroot
tkinter.Misc.after_info
tkinter.Misc.busy
Expand Down Expand Up @@ -151,6 +141,9 @@ platform.uname_result.processor
unittest.TestCase.__init_subclass__
unittest.case.TestCase.__init_subclass__

# Deprecated argument is supported at runtime by renaming it through a decorator.
importlib.resources._common.files
importlib.resources.files
# Problematic protocol signature at runtime, see source code comments.
importlib.abc.Traversable.open
importlib.resources.abc.Traversable.open
Expand Down
32 changes: 32 additions & 0 deletions stdlib/@tests/test_cases/check_importlib_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

import importlib.resources
import pathlib
import sys


class _CustomPathLike:
def __fspath__(self) -> str:
return ""


if sys.version_info >= (3, 13):

def f(pth: pathlib.Path | str | _CustomPathLike) -> None:
importlib.resources.open_binary("pkg", pth)
# Encoding defaults to "utf-8" for one arg.
importlib.resources.open_text("pkg", pth)
# Otherwise, it must be specified.
importlib.resources.open_text("pkg", pth, pth) # type: ignore
importlib.resources.open_text("pkg", pth, pth, encoding="utf-8")

# Encoding defaults to "utf-8" for one arg.
importlib.resources.read_text("pkg", pth)
# Otherwise, it must be specified.
importlib.resources.read_text("pkg", pth, pth) # type: ignore
importlib.resources.read_text("pkg", pth, pth, encoding="utf-8")

importlib.resources.read_binary("pkg", pth)
importlib.resources.path("pkg", pth)
importlib.resources.is_resource("pkg", pth)
importlib.resources.contents("pkg", pth)
2 changes: 2 additions & 0 deletions stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ importlib.metadata._meta: 3.10-
importlib.metadata.diagnose: 3.13-
importlib.readers: 3.10-
importlib.resources: 3.7-
importlib.resources._common: 3.11-
importlib.resources._functional: 3.13-
importlib.resources.abc: 3.11-
importlib.resources.readers: 3.11-
importlib.resources.simple: 3.11-
Expand Down
4 changes: 2 additions & 2 deletions stdlib/importlib/abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ if sys.version_info >= (3, 9):
# which is not the case.
@overload
@abstractmethod
def open(self, mode: Literal["r"] = "r", /, *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ...
def open(self, mode: Literal["r"] = "r", *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ...
@overload
@abstractmethod
def open(self, mode: Literal["rb"], /) -> IO[bytes]: ...
def open(self, mode: Literal["rb"]) -> IO[bytes]: ...
@property
@abstractmethod
def name(self) -> str: ...
Expand Down
54 changes: 39 additions & 15 deletions stdlib/importlib/resources/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,61 @@ from types import ModuleType
from typing import Any, BinaryIO, TextIO
from typing_extensions import TypeAlias

if sys.version_info >= (3, 11):
from importlib.resources._common import Package as Package
else:
Package: TypeAlias = str | ModuleType

if sys.version_info >= (3, 9):
from importlib.abc import Traversable

__all__ = ["Package", "Resource", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"]
__all__ = ["Package", "contents", "is_resource", "open_binary", "open_text", "path", "read_binary", "read_text"]

if sys.version_info >= (3, 9):
__all__ += ["as_file", "files"]

if sys.version_info >= (3, 10):
__all__ += ["ResourceReader"]

Package: TypeAlias = str | ModuleType
if sys.version_info < (3, 13):
__all__ += ["Resource"]

if sys.version_info >= (3, 11):
Resource: TypeAlias = str
else:
if sys.version_info < (3, 11):
Resource: TypeAlias = str | os.PathLike[Any]
elif sys.version_info < (3, 13):
Resource: TypeAlias = str

def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ...
def read_binary(package: Package, resource: Resource) -> bytes: ...
def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ...
def path(package: Package, resource: Resource) -> AbstractContextManager[Path]: ...
def is_resource(package: Package, name: str) -> bool: ...
def contents(package: Package) -> Iterator[str]: ...
if sys.version_info >= (3, 13):
from importlib.resources._common import Anchor as Anchor

if sys.version_info >= (3, 9):
__all__ += ["Anchor"]

from importlib.resources._functional import (
contents as contents,
is_resource as is_resource,
open_binary as open_binary,
open_text as open_text,
path as path,
read_binary as read_binary,
read_text as read_text,
)

else:
def open_binary(package: Package, resource: Resource) -> BinaryIO: ...
def open_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> TextIO: ...
def read_binary(package: Package, resource: Resource) -> bytes: ...
def read_text(package: Package, resource: Resource, encoding: str = "utf-8", errors: str = "strict") -> str: ...
def path(package: Package, resource: Resource) -> AbstractContextManager[Path]: ...
def is_resource(package: Package, name: str) -> bool: ...
def contents(package: Package) -> Iterator[str]: ...

if sys.version_info >= (3, 11):
from importlib.resources._common import as_file as as_file
elif sys.version_info >= (3, 9):
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...

if sys.version_info >= (3, 12):
def files(anchor: Package | None = ...) -> Traversable: ...
if sys.version_info >= (3, 11):
from importlib.resources._common import files as files

elif sys.version_info >= (3, 9):
def files(package: Package) -> Traversable: ...
Expand Down
42 changes: 42 additions & 0 deletions stdlib/importlib/resources/_common.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys

# Even though this file is 3.11+ only, Pyright will complain in stubtest for older versions.
if sys.version_info >= (3, 11):
import types
from collections.abc import Callable
from contextlib import AbstractContextManager
from importlib.abc import ResourceReader, Traversable
from pathlib import Path
from typing import overload
from typing_extensions import TypeAlias, deprecated

Package: TypeAlias = str | types.ModuleType

if sys.version_info >= (3, 12):
Anchor: TypeAlias = Package

def package_to_anchor(
func: Callable[[Anchor | None], Traversable]
) -> Callable[[Anchor | None, Anchor | None], Traversable]: ...
@overload
def files(anchor: Anchor | None = None) -> Traversable: ...
@overload
@deprecated("First parameter to files is renamed to 'anchor'")
def files(package: Anchor | None = None) -> Traversable: ...

else:
def files(package: Package) -> Traversable: ...

def get_resource_reader(package: types.ModuleType) -> ResourceReader | None: ...

if sys.version_info >= (3, 12):
def resolve(cand: Anchor | None) -> types.ModuleType: ...

else:
def resolve(cand: Package) -> types.ModuleType: ...

if sys.version_info < (3, 12):
def get_package(package: Package) -> types.ModuleType: ...

def from_package(package: types.ModuleType) -> Traversable: ...
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...
30 changes: 30 additions & 0 deletions stdlib/importlib/resources/_functional.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys

# Even though this file is 3.13+ only, Pyright will complain in stubtest for older versions.
if sys.version_info >= (3, 13):
from _typeshed import StrPath
from collections.abc import Iterator
from contextlib import AbstractContextManager
from importlib.resources._common import Anchor
from io import TextIOWrapper
from pathlib import Path
from typing import BinaryIO, overload
from typing_extensions import Unpack

def open_binary(anchor: Anchor, *path_names: StrPath) -> BinaryIO: ...
@overload
def open_text(
anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict"
) -> TextIOWrapper: ...
@overload
def open_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> TextIOWrapper: ...
def read_binary(anchor: Anchor, *path_names: StrPath) -> bytes: ...
@overload
def read_text(
anchor: Anchor, *path_names: Unpack[tuple[StrPath]], encoding: str | None = "utf-8", errors: str | None = "strict"
) -> str: ...
@overload
def read_text(anchor: Anchor, *path_names: StrPath, encoding: str | None, errors: str | None = "strict") -> str: ...
def path(anchor: Anchor, *path_names: StrPath) -> AbstractContextManager[Path]: ...
def is_resource(anchor: Anchor, *path_names: StrPath) -> bool: ...
def contents(anchor: Anchor, *path_names: StrPath) -> Iterator[str]: ...
7 changes: 2 additions & 5 deletions stubs/PyYAML/yaml/constructor.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ from collections.abc import Callable, Hashable
from datetime import date
from re import Pattern
from typing import Any, ClassVar, TypeVar
from typing_extensions import TypeAlias

from yaml.error import MarkedYAMLError
from yaml.nodes import MappingNode, Node, ScalarNode, SequenceNode
Expand All @@ -13,8 +12,6 @@ from .loader import _Loader
_L = TypeVar("_L", bound=_Loader | _CLoader)
_N = TypeVar("_N", bound=Node)

_Scalar: TypeAlias = str | int | float | bool | None

class ConstructorError(MarkedYAMLError): ...

class BaseConstructor:
Expand All @@ -31,7 +28,7 @@ class BaseConstructor:
def get_single_data(self) -> Any: ...
def construct_document(self, node): ...
def construct_object(self, node, deep=False): ...
def construct_scalar(self, node: ScalarNode) -> _Scalar: ...
def construct_scalar(self, node: ScalarNode) -> str: ...
def construct_sequence(self, node: SequenceNode, deep: bool = False) -> list[Any]: ...
def construct_mapping(self, node: MappingNode, deep: bool = False) -> dict[Hashable, Any]: ...
def construct_pairs(self, node, deep=False): ...
Expand All @@ -42,7 +39,7 @@ class BaseConstructor:
def add_multi_constructor(cls, tag_prefix, multi_constructor): ...

class SafeConstructor(BaseConstructor):
def construct_scalar(self, node: ScalarNode) -> _Scalar: ...
def construct_scalar(self, node: ScalarNode) -> str: ...
def flatten_mapping(self, node: MappingNode) -> None: ...
def construct_mapping(self, node: MappingNode, deep: bool = False) -> dict[Hashable, Any]: ...
def construct_yaml_null(self, node: ScalarNode) -> None: ...
Expand Down
2 changes: 2 additions & 0 deletions stubs/lupa/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "2.2.*"
upstream_repository = "https://github.com/scoder/lupa"
17 changes: 17 additions & 0 deletions stubs/lupa/lupa/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .lua54 import *

__all__ = [
# from lua54 (newest lib)
"LUA_VERSION",
"LUA_MAXINTEGER",
"LUA_MININTEGER",
"LuaRuntime",
"LuaError",
"LuaSyntaxError",
"LuaMemoryError",
"as_itemgetter",
"as_attrgetter",
"lua_type",
"unpacks_lua_table",
"unpacks_lua_table_method",
]
Loading

0 comments on commit e23814c

Please sign in to comment.