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

Add setuptools stubs #5762

Merged
merged 26 commits into from
Sep 19, 2021
Merged

Add setuptools stubs #5762

merged 26 commits into from
Sep 19, 2021

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Jul 11, 2021

Still work in progress: There are mypy failures.

@srittau
Copy link
Collaborator Author

srittau commented Jul 25, 2021

I'm unclear why pytype fails, maybe @rchen152 has some ideas.

@srittau srittau marked this pull request as ready for review July 25, 2021 11:47
@rchen152
Copy link
Collaborator

Huh, pytype thinks SetuptoolsDeprecationWarning is a module - maybe because of how it's imported? Looking into it.

@rchen152
Copy link
Collaborator

Still trying to figure out how to fix this, but in the meantime, I did find a workaround: if you replace all from .. import <SomeClass> statements with from setuptools import <SomeClass>, that appears to make pytype happy.

@srittau
Copy link
Collaborator Author

srittau commented Jul 27, 2021

stubtest crashes. Maybe @hauntsaninja has an idea.

@hauntsaninja
Copy link
Collaborator

Looks like something in setuptools that looks like a function raises on inspect.signature. We could also just catch TypeError here: https://github.com/python/mypy/blob/6fd2dc2403889f7104648d8bfbb8df3f5e83b63f/mypy/stubtest.py#L670

@Akuli
Copy link
Collaborator

Akuli commented Jul 27, 2021

Apparently stubtest has an instance of NonDataProperty:

>>> from setuptools.command.test import NonDataProperty
>>> import inspect
>>> inspect.signature(NonDataProperty)
<Signature (fget)>
>>> inspect.signature(NonDataProperty(print))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/inspect.py", line 3083, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
  File "/usr/lib/python3.7/inspect.py", line 2833, in from_callable
    follow_wrapper_chains=follow_wrapped)
  File "/usr/lib/python3.7/inspect.py", line 2208, in _signature_from_callable
    raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: <setuptools.command.test.NonDataProperty object at 0x7f67b94a3ef0> is not a callable object
>>> 

hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this pull request Jul 27, 2021
hauntsaninja pushed a commit to hauntsaninja/mypy that referenced this pull request Jul 27, 2021
@srittau srittau marked this pull request as draft July 27, 2021 17:29
@srittau
Copy link
Collaborator Author

srittau commented Jul 27, 2021

Let's wait for the next mypy release: python/mypy#10884, also this requires updated distutils.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Jul 27, 2021

Here's a fix in stubtest: python/mypy#10884
Might be easiest to just remove setuptools.command.test.test.test_args from this PR to unblock (or avoid typing it as a method)

@hauntsaninja
Copy link
Collaborator

@srittau I pushed a workaround, so CI is now green if you want to merge.

@srittau
Copy link
Collaborator Author

srittau commented Aug 2, 2021

Should we merge this, though? It will not work with current mypy as it requires newer stdlib stubs. I'm 50/50 on merging now vs after the next mypy release.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 2, 2021

Well, I figured it's nice to have the option! :-)
I think I'd lean towards merging: other type checkers can benefit, a mypy release probably isn't imminent (if I had to guess, I'd say the next one would be around Python 3.10 release), setuptools.__init__ should work and that's 99% of setuptools usage.

@srittau srittau marked this pull request as ready for review August 2, 2021 23:18
rchen152 added a commit to google/pytype that referenced this pull request Aug 3, 2021
We made the (erroneous) assumption that "from . import X" can only import a
module, which was causing trouble for typeshed. See
python/typeshed#5762 (comment) for
context. Fixing this exposed another bug where load_pytd.Module.is_package
didn't work correctly for stubs that ship with pytype, which I also fixed.

PiperOrigin-RevId: 388369899
@rchen152
Copy link
Collaborator

rchen152 commented Aug 3, 2021

I know you've already worked around the pytype issue, but anyway, pytype release 2021.08.03 should fix it ^^

@srittau
Copy link
Collaborator Author

srittau commented Aug 9, 2021

I marked it as ready to merge if someone has time to review it and thinks we should merge now.

@JelleZijlstra JelleZijlstra merged commit db69e41 into python:master Sep 19, 2021
@srittau srittau deleted the setuptools branch September 19, 2021 20:58
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.

5 participants