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

Don't ignore missing stubs in setuptools #10058

Merged

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Apr 17, 2023

#10057 (comment)

Given the push for the deprecation of distutils, it'd be a good idea indeed to ensure that all stubs in setuptools are accounted for.

  • Fixed stubtest_allowlist entries
  • Removed ignore_missing_stub = true
  • Added missing __all__
  • Added new default values
  • Standardized imports (there was a mix of relative and absolute)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

stubs/setuptools/pkg_resources/__init__.pyi Show resolved Hide resolved
Comment on lines 35 to 36
def __enter__(self) -> None: ...
def __exit__(self, _exc_type, _exc_value, _traceback) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unannotated, but I don't think that should imply None since the body is just ....

Copy link
Collaborator Author

@Avasam Avasam Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it fine if all setuptool classes that implement the EditableStrategy protocol have the same return type for their methods? (None for __call__ and __exit__, Self for __enter__)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for __exit__, but it feels too restrictive for __enter__.

path_entries: Incomplete
def __init__(self, dist: Distribution, name: str, path_entries: list[Path]) -> None: ...
def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ...
def __enter__(self): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __enter__(self): ...
def __enter__(self) -> Self: ...

(Plus import)

build_lib: Incomplete
def __init__(self, dist: Distribution, name: str, auxiliary_dir: _Path, build_lib: _Path) -> None: ...
def __call__(self, wheel: _WheelFile, files: list[str], mapping: dict[str, str]): ...
def __enter__(self): ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __enter__(self): ...
def __enter__(self) -> Self: ...


__all__ = ["Require", "find_module", "get_module_constant", "extract_constant"]

def find_module(module, paths=None) -> tuple[IO[Any], str, tuple[str, Literal["", "r", "rb"], Literal[7, 6, 1, 2, 3, -1]]]: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def find_module(module, paths=None) -> tuple[IO[Any], str, tuple[str, Literal["", "r", "rb"], Literal[7, 6, 1, 2, 3, -1]]]: ...
def find_module(module, paths=None) -> tuple[IO[Any], str | None, tuple[str, Literal["", "r", "rb"], Literal[7, 6, 1, 2, 3, -1]]]: ...

I see some paths where it's None.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't finish looking at this, but here's a partial review I started -- mostly a few suggestions for some type annotations that look fairly obvious :)

requirements: Iterable[Requirement],
env: Environment | None = None,
installer: _InstallerType | None = None,
replace_conflicting=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
replace_conflicting=False,
replace_conflicting: bool = False,

) -> list[Distribution]: ...
def add(self, dist: Distribution, entry: str | None = None, insert: bool = True, replace: bool = False) -> None: ...
def subscribe(self, callback: Callable[[Distribution], object]) -> None: ...
def subscribe(self, callback: Callable[[Distribution], object], existing=True) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def subscribe(self, callback: Callable[[Distribution], object], existing=True) -> None: ...
def subscribe(self, callback: Callable[[Distribution], object], existing: bool = True) -> None: ...

@@ -89,6 +97,7 @@ class Requirement:
# TODO: change this to packaging.markers.Marker | None once we can import
# packaging.markers
marker: Incomplete | None
def __init__(self, requirement_string) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll be the same as https://github.com/pypa/packaging/blob/55584fb5ca327ba38b74ca5c668125caaebd9a5d/src/packaging/requirements.py#L33

Suggested change
def __init__(self, requirement_string) -> None: ...
def __init__(self, requirement_string: str) -> None: ...

Comment on lines 154 to 159
def __lt__(self, other) -> bool: ...
def __le__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __ge__(self, other) -> bool: ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __lt__(self, other) -> bool: ...
def __le__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __ge__(self, other) -> bool: ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
def __lt__(self, other: Distribution) -> bool: ...
def __le__(self, other: Distribution) -> bool: ...
def __gt__(self, other: Distribution) -> bool: ...
def __ge__(self, other: Distribution) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

@@ -164,15 +184,17 @@ class Distribution(NullProvider, IResourceProvider, IMetadataProvider):
) -> Distribution: ...
@classmethod
def from_filename(cls, filename: str, metadata: _MetadataType = None, **kw: str | None | int) -> Distribution: ...
def activate(self, path: list[str] | None = None) -> None: ...
def activate(self, path: list[str] | None = None, replace=False) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def activate(self, path: list[str] | None = None, replace=False) -> None: ...
def activate(self, path: list[str] | None = None, replace: bool = False) -> None: ...


class IResourceManager:
@type_check_only
class IResourceManager(Protocol):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this class doesn't exist at runtime, should it maybe be private?

Suggested change
class IResourceManager(Protocol):
class _IResourceManager(Protocol):

Copy link
Collaborator Author

@Avasam Avasam Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what @type_check_only is for? Granted support is still limited in mypy (python/mypy#15146, python/mypy#9531)

The source docstrings do call it IResourceManager, so it's the right name, makes it easier to find and import, whilst being safer with checkers that support the annotation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, mypy has been pretty slow to implement this feature :)

Elsewhere in typeshed, though, we generally don't rely on a feature unless it's supported by all major type checkers. We use @type_check_only in a few places already, but those are basically all very special cases (builtins.pyi, typing.pyi) where our standard option of making the name private isn't available.

@github-actions

This comment has been minimized.

@Avasam
Copy link
Collaborator Author

Avasam commented Apr 29, 2023

Oh neat, you can request review from more than one person now on GitHub.

@github-actions

This comment has been minimized.

@Avasam
Copy link
Collaborator Author

Avasam commented Apr 29, 2023

Pretty sure pyright is failing here because types-setuptools is installed (https://github.com/python/typeshed/actions/runs/4839817600/jobs/8625083762?pr=10058#step:4:55). (notice there's no error for FileMetadata, PathMetadata and EggMetadata). Same errors locally with types-setuptools installed.

@AlexWaygood
Copy link
Member

Pretty sure pyright is failing here because types-setuptools is installed (https://github.com/python/typeshed/actions/runs/4839817600/jobs/8625083762?pr=10058#step:4:55). (notice there's no error for FileMetadata, PathMetadata and EggMetadata). Same errors locally with types-setuptools installed.

Seems your diagnosis was spot on!

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2023

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra
Copy link
Member

Looks good, @AlexWaygood any further feedback?

@Avasam feel free to mark conversations as "resolved" if you have addressed them.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't reviewed in depth, but all my previous points have been addressed, nothing stands out as weird from a skim-read, and I trust @JelleZijlstra to do a thorough review :)

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't reviewed in depth, but all my previous points have been addressed, nothing stands out as weird from a skim-read, and I trust @JelleZijlstra to do a thorough review :)

@AlexWaygood AlexWaygood merged commit b5c9d8d into python:main May 19, 2023
@Avasam Avasam deleted the Don't-ignore-missing-stubs-in-setuptools branch November 28, 2023 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants