Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic updates from Ruff for Python 3.9+ #4721

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,17 @@
import warnings
import zipfile
import zipimport
from collections.abc import Iterable, Iterator, Mapping, MutableSequence
from pkgutil import get_importer
from typing import (
TYPE_CHECKING,
Any,
BinaryIO,
Callable,
Dict,
Iterable,
Iterator,
Literal,
Mapping,
MutableSequence,
NamedTuple,
NoReturn,
Protocol,
Tuple,
TypeVar,
Union,
overload,
Expand Down Expand Up @@ -424,7 +419,7 @@ def get_provider(moduleOrReq: str | Requirement) -> IResourceProvider | Distribu
return _find_adapter(_provider_factories, loader)(module)


@functools.lru_cache(maxsize=None)
@functools.cache
def _macos_vers():
version = platform.mac_ver()[0]
# fallback for MacPorts
Expand Down Expand Up @@ -1120,7 +1115,7 @@ def __setstate__(self, e_k_b_n_c) -> None:
self.callbacks = callbacks[:]


class _ReqExtras(Dict["Requirement", Tuple[str, ...]]):
class _ReqExtras(dict["Requirement", tuple[str, ...]]):
"""
Map each requirement to the extras that demanded it.
"""
Expand Down Expand Up @@ -1952,7 +1947,7 @@ def __init__(self) -> None:
empty_provider = EmptyProvider()


class ZipManifests(Dict[str, "MemoizedZipManifests.manifest_mod"]):
class ZipManifests(dict[str, "MemoizedZipManifests.manifest_mod"]):
"""
zip manifest builder
"""
Expand Down Expand Up @@ -2662,7 +2657,7 @@ def _normalize_cached(filename: StrOrBytesPath) -> str | bytes: ...

else:

@functools.lru_cache(maxsize=None)
@functools.cache
def _normalize_cached(filename):
return normalize_path(filename)

Expand Down
3 changes: 2 additions & 1 deletion setuptools/_reqs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Iterable, Iterator
from functools import lru_cache
from typing import TYPE_CHECKING, Callable, Iterable, Iterator, TypeVar, Union, overload
from typing import TYPE_CHECKING, Callable, TypeVar, Union, overload

import jaraco.text as text
from packaging.requirements import Requirement
Expand Down
5 changes: 3 additions & 2 deletions setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
import tempfile
import tokenize
import warnings
from collections.abc import Iterable, Iterator, Mapping
from pathlib import Path
from typing import TYPE_CHECKING, Iterable, Iterator, List, Mapping, Union
from typing import TYPE_CHECKING, Union

import setuptools

Expand Down Expand Up @@ -146,7 +147,7 @@ def suppress_known_deprecation():
yield


_ConfigSettings: TypeAlias = Union[Mapping[str, Union[str, List[str], None]], None]
_ConfigSettings: TypeAlias = Union[Mapping[str, Union[str, list[str], None]], None]
"""
Currently the user can run::

Expand Down
5 changes: 3 additions & 2 deletions setuptools/command/_requirestxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import io
from collections import defaultdict
from collections.abc import Mapping
from itertools import filterfalse
from typing import Dict, Mapping, TypeVar
from typing import TypeVar

from jaraco.text import yield_lines
from packaging.requirements import Requirement
Expand All @@ -22,7 +23,7 @@

# dict can work as an ordered set
_T = TypeVar("_T")
_Ordered = Dict[_T, None]
_Ordered = dict[_T, None]


def _prepare(
Expand Down
3 changes: 2 additions & 1 deletion setuptools/command/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import sys
import sysconfig
import warnings
from collections.abc import Iterable, Sequence
from email.generator import BytesGenerator, Generator
from email.policy import EmailPolicy
from glob import iglob
from shutil import rmtree
from typing import TYPE_CHECKING, Callable, Iterable, Literal, Sequence, cast
from typing import TYPE_CHECKING, Callable, Literal, cast
from zipfile import ZIP_DEFLATED, ZIP_STORED

from packaging import tags, version as _packaging_version
Expand Down
3 changes: 2 additions & 1 deletion setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import itertools
import os
import sys
from collections.abc import Iterator
from importlib.machinery import EXTENSION_SUFFIXES
from importlib.util import cache_from_source as _compiled_file_name
from pathlib import Path
from typing import TYPE_CHECKING, Iterator
from typing import TYPE_CHECKING

from setuptools.dist import Distribution
from setuptools.errors import BaseError
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import os
import stat
import textwrap
from collections.abc import Iterable, Iterator
from functools import partial
from glob import glob
from pathlib import Path
from typing import Iterable, Iterator

from more_itertools import unique_everseen

Expand Down
3 changes: 2 additions & 1 deletion setuptools/command/editable_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
import os
import shutil
import traceback
from collections.abc import Iterable, Iterator, Mapping
from contextlib import suppress
from enum import Enum
from inspect import cleandoc
from itertools import chain, starmap
from pathlib import Path
from tempfile import TemporaryDirectory
from types import TracebackType
from typing import TYPE_CHECKING, Iterable, Iterator, Mapping, Protocol, TypeVar, cast
from typing import TYPE_CHECKING, Protocol, TypeVar, cast

from .. import Command, _normalization, _path, errors, namespaces
from .._path import StrPath
Expand Down
5 changes: 3 additions & 2 deletions setuptools/config/_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

import logging
import os
from collections.abc import Mapping
from email.headerregistry import Address
from functools import partial, reduce
from inspect import cleandoc
from itertools import chain
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Callable, Dict, Mapping, TypeVar, Union
from typing import TYPE_CHECKING, Any, Callable, TypeVar, Union

from .._path import StrPath
from ..errors import RemovedConfigError
Expand All @@ -34,7 +35,7 @@


EMPTY: Mapping = MappingProxyType({}) # Immutable dict-like
_ProjectReadmeValue: TypeAlias = Union[str, Dict[str, str]]
_ProjectReadmeValue: TypeAlias = Union[str, dict[str, str]]
_Correspondence: TypeAlias = Callable[["Distribution", Any, Union[StrPath, None]], None]
_T = TypeVar("_T")

Expand Down
3 changes: 2 additions & 1 deletion setuptools/config/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
import os
import pathlib
import sys
from collections.abc import Iterable, Iterator, Mapping
from configparser import ConfigParser
from glob import iglob
from importlib.machinery import ModuleSpec, all_suffixes
from itertools import chain
from pathlib import Path
from types import ModuleType, TracebackType
from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator, Mapping, TypeVar
from typing import TYPE_CHECKING, Any, Callable, TypeVar

from .._path import StrPath, same_path as _same_path
from ..discovery import find_package_path
Expand Down
3 changes: 2 additions & 1 deletion setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

import logging
import os
from collections.abc import Mapping
from contextlib import contextmanager
from functools import partial
from types import TracebackType
from typing import TYPE_CHECKING, Any, Callable, Mapping
from typing import TYPE_CHECKING, Any, Callable

from .._path import StrPath
from ..errors import FileError, InvalidConfigError
Expand Down
22 changes: 5 additions & 17 deletions setuptools/config/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,9 @@
import functools
import os
from collections import defaultdict
from collections.abc import Iterable, Iterator
from functools import partial, wraps
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Dict,
Generic,
Iterable,
Iterator,
List,
Tuple,
TypeVar,
cast,
)
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Generic, TypeVar, cast

from packaging.markers import default_environment as marker_env
from packaging.requirements import InvalidRequirement, Requirement
Expand All @@ -48,13 +36,13 @@

from distutils.dist import DistributionMetadata

SingleCommandOptions: TypeAlias = Dict[str, Tuple[str, Any]]
SingleCommandOptions: TypeAlias = dict[str, tuple[str, Any]]
"""Dict that associate the name of the options of a particular command to a
tuple. The first element of the tuple indicates the origin of the option value
(e.g. the name of the configuration file where it was read from),
while the second element of the tuple is the option value itself
"""
AllCommandOptions: TypeAlias = Dict[str, SingleCommandOptions]
AllCommandOptions: TypeAlias = dict[str, SingleCommandOptions]
"""cmd name => its options"""
Target = TypeVar("Target", "Distribution", "DistributionMetadata")

Expand Down Expand Up @@ -114,7 +102,7 @@ def _apply(

try:
# TODO: Temporary cast until mypy 1.12 is released with upstream fixes from typeshed
_Distribution.parse_config_files(dist, filenames=cast(List[str], filenames))
_Distribution.parse_config_files(dist, filenames=cast(list[str], filenames))
handlers = parse_configuration(
dist, dist.command_options, ignore_option_errors=ignore_option_errors
)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@

import itertools
import os
from collections.abc import Iterator
from collections.abc import Iterable, Iterator, Mapping
from fnmatch import fnmatchcase
from glob import glob
from pathlib import Path
from typing import TYPE_CHECKING, ClassVar, Iterable, Mapping
from typing import TYPE_CHECKING, ClassVar

import _distutils_hack.override # noqa: F401

Expand Down
17 changes: 4 additions & 13 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,10 @@
import os
import re
import sys
from collections.abc import Iterable
from collections.abc import Iterable, MutableMapping, Sequence
from glob import iglob
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Dict,
List,
MutableMapping,
Sequence,
Tuple,
Union,
)
from typing import TYPE_CHECKING, Any, Union

from more_itertools import partition, unique_everseen
from packaging.markers import InvalidMarker, Marker
Expand Down Expand Up @@ -66,10 +57,10 @@
- not imply a nested type (like `dict`)
for use with `isinstance`.
"""
_Sequence: TypeAlias = Union[Tuple[str, ...], List[str]]
_Sequence: TypeAlias = Union[tuple[str, ...], list[str]]
# This is how stringifying _Sequence would look in Python 3.10
_sequence_type_repr = "tuple[str, ...] | list[str]"
_OrderedStrSequence: TypeAlias = Union[str, Dict[str, Any], Sequence[str]]
_OrderedStrSequence: TypeAlias = Union[str, dict[str, Any], Sequence[str]]
"""
:meta private:
Avoid single-use iterable. Disallow sets.
Expand Down
4 changes: 2 additions & 2 deletions setuptools/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import platform
import sys
import types
from typing import Type, TypeVar, cast, overload
from typing import TypeVar, cast, overload

import distutils.filelist

Check warning on line 13 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

Import "distutils.filelist" could not be resolved from source (reportMissingModuleSource)

_T = TypeVar("_T")
_UnpatchT = TypeVar("_UnpatchT", type, types.FunctionType)
Expand Down Expand Up @@ -58,7 +58,7 @@
first.
"""
external_bases = (
cast(Type[_T], cls)
cast(type[_T], cls)
for cls in _get_mro(cls)
if not cls.__module__.startswith('setuptools')
)
Expand All @@ -73,21 +73,21 @@
import setuptools

# we can't patch distutils.cmd, alas
distutils.core.Command = setuptools.Command

Check warning on line 76 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

"core" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 76 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

"core" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

_patch_distribution_metadata()

# Install Distribution throughout the distutils
for module in distutils.dist, distutils.core, distutils.cmd:

Check warning on line 81 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

"dist" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 81 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

"core" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 81 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

"cmd" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 81 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

"dist" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 81 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

"core" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 81 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

"cmd" is not a known attribute of module "distutils" (reportAttributeAccessIssue)
module.Distribution = setuptools.dist.Distribution

# Install the patched Extension
distutils.core.Extension = setuptools.extension.Extension

Check warning on line 85 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

"core" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 85 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

"core" is not a known attribute of module "distutils" (reportAttributeAccessIssue)
distutils.extension.Extension = setuptools.extension.Extension

Check warning on line 86 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

"extension" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 86 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

"extension" is not a known attribute of module "distutils" (reportAttributeAccessIssue)
if 'distutils.command.build_ext' in sys.modules:
sys.modules[
'distutils.command.build_ext'
].Extension = setuptools.extension.Extension

Check warning on line 90 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

Cannot assign to attribute "Extension" for class "ModuleType"   Attribute "Extension" is unknown (reportAttributeAccessIssue)

Check warning on line 90 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

Cannot assign to attribute "Extension" for class "ModuleType"   Attribute "Extension" is unknown (reportAttributeAccessIssue)


def _patch_distribution_metadata():
Expand All @@ -102,7 +102,7 @@
'get_fullname',
):
new_val = getattr(_core_metadata, attr)
setattr(distutils.dist.DistributionMetadata, attr, new_val)

Check warning on line 105 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.9, ubuntu-latest)

"dist" is not a known attribute of module "distutils" (reportAttributeAccessIssue)

Check warning on line 105 in setuptools/monkey.py

View workflow job for this annotation

GitHub Actions / pyright (3.13, ubuntu-latest)

"dist" is not a known attribute of module "distutils" (reportAttributeAccessIssue)


def patch_func(replacement, target_mod, func_name):
Expand Down
4 changes: 2 additions & 2 deletions setuptools/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from datetime import date
from inspect import cleandoc
from textwrap import indent
from typing import TYPE_CHECKING, Tuple
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing_extensions import TypeAlias

_DueDate: TypeAlias = Tuple[int, int, int] # time tuple
_DueDate: TypeAlias = tuple[int, int, int] # time tuple
_INDENT = 8 * " "
_TEMPLATE = f"""{80 * '*'}\n{{details}}\n{80 * '*'}"""

Expand Down
2 changes: 1 addition & 1 deletion setuptools/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
NAMESPACE_PACKAGE_INIT = "__import__('pkg_resources').declare_namespace(__name__)\n"


@functools.lru_cache(maxsize=None)
@functools.cache
def _get_supported_tags():
# We calculate the supported tags only once, otherwise calling
# this method on thousands of wheels takes seconds instead of
Expand Down
2 changes: 1 addition & 1 deletion tools/generate_validation_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import itertools
import subprocess
import sys
from collections.abc import Iterable
from pathlib import Path
from typing import Iterable


def generate_pyproject_validation(dest: Path, schemas: Iterable[Path]) -> bool:
Expand Down
Loading