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

Merge overloaded method definitions from typeshed #4506

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 17 additions & 5 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Extensions to the 'distutils' for large or complex distributions"""

from __future__ import annotations

import functools
import os
import re
import sys
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, TypeVar, overload


sys.path.extend(((vendor_path := os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setuptools', '_vendor')) not in sys.path) * [vendor_path]) # fmt: skip
# workaround for #4476
Expand All @@ -15,7 +18,7 @@
from distutils.errors import DistutilsOptionError

from . import logging, monkey
from . import version as _version_module
from .version import __version__ as __version__
from .depends import Require
from .discovery import PackageFinder, PEP420PackageFinder
from .dist import Distribution
Expand All @@ -33,11 +36,10 @@
'find_namespace_packages',
]

__version__ = _version_module.__version__
_CommandT = TypeVar("_CommandT", bound="_Command")

bootstrap_install_from = None


find_packages = PackageFinder.find
find_namespace_packages = PEP420PackageFinder.find

Expand Down Expand Up @@ -221,7 +223,17 @@ def ensure_string_list(self, option):
"'%s' must be a list of strings (got %r)" % (option, val)
)

def reinitialize_command(self, command, reinit_subcommands=False, **kw):
@overload # type:ignore[override] # Extra **kw param
def reinitialize_command(
self, command: str, reinit_subcommands: bool = False, **kw
) -> _Command: ...
@overload
def reinitialize_command(
self, command: _CommandT, reinit_subcommands: bool = False, **kw
) -> _CommandT: ...
def reinitialize_command(
self, command: str | _Command, reinit_subcommands: bool = False, **kw
) -> _Command:
cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
vars(cmd).update(kw)
return cmd
Expand Down
19 changes: 16 additions & 3 deletions setuptools/command/test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations
from collections.abc import Callable
import os
import operator
import sys
import contextlib
import itertools
from typing import TYPE_CHECKING, Generic, TypeVar, overload
import unittest
from distutils.errors import DistutilsError, DistutilsOptionError
from distutils import log
Expand All @@ -22,6 +25,12 @@
from more_itertools import unique_everseen
from jaraco.functools import pass_none

if TYPE_CHECKING:
from typing_extensions import Self

_T = TypeVar("_T")
_R = TypeVar("_R")


class ScanningLoader(TestLoader):
def __init__(self):
Expand Down Expand Up @@ -63,11 +72,15 @@ def loadTestsFromModule(self, module, pattern=None):


# adapted from jaraco.classes.properties:NonDataProperty
class NonDataProperty:
def __init__(self, fget):
class NonDataProperty(Generic[_T, _R]):
def __init__(self, fget: Callable[[_T], _R]):
self.fget = fget

def __get__(self, obj, objtype=None):
@overload
def __get__(self, obj: None, objtype: object = None) -> Self: ...
@overload
def __get__(self, obj: _T, objtype: object = None) -> _R: ...
def __get__(self, obj: _T | None, objtype: object = None) -> Self | _R:
if obj is None:
return self
return self.fget(obj)
Expand Down
Loading