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

Several type annotations in _interpreters and _interpqueues are wrong #13351

Open
agronholm opened this issue Dec 31, 2024 · 6 comments
Open
Labels
stubs: false positive Type checkers report false errors

Comments

@agronholm
Copy link
Contributor

  1. _interpreters.exec() is annotated as returning None, while on error it actually returns a namespace (though this fact is largely undocumented)
  2. _interpreters.exec() is annotated as only taking str as the code argument, though it's documented to also accept code objects:

Functions (and code objects) are also supported, with some restrictions.
The code/function must not take any arguments or be a closure
(i.e. have cell vars). Methods and other callables are not supported.

  1. _interpqueues.create() takes 3 mandatory arguments (create(maxsize, fmt, unboundop) -> qid), but the type stub says it takes 2
  2. _interpqueues.get() returns a 3-tuple (item, fmt, unboundop), not 2-tuple as annotated in typeshed
  3. _interpqueues.put takes 4 arguments (qid, item, fmt, unboundop), not 3 as annotated in typeshed (admittedly its own docstring is also wrong!)

I believe the annotations may have been correct at the time they were added, but changes have been made to them in the CPython repository since then.

@AlexWaygood
Copy link
Member

PR(s) welcome!

(PRs to improve introspectability in CPython would also be welcome -- I'm guessiong these would probably have all been caught by our tests if inspect.signature() produced good results for these functions!)

@AlexWaygood AlexWaygood added the stubs: false positive Type checkers report false errors label Dec 31, 2024
@max-muoto
Copy link
Contributor

Thanks for documenting this @agronholm! I originally annotated these back during the beta period, I'll go through again and make sure these are up to date and put up a PR.

@max-muoto
Copy link
Contributor

Just put up a PR fixing these: #13355

@ZeroIntensity
Copy link
Member

_interpreters.exec() is annotated as returning None, while on error it actually returns a namespace (though this fact is largely undocumented)

It's namespace | None. It only returns a namespace if an exception occurred.

@agronholm
Copy link
Contributor Author

_interpreters.exec() is annotated as returning None, while on error it actually returns a namespace (though this fact is largely undocumented)

It's namespace | None. It only returns a namespace if an exception occurred.

Isn't that what I said too?

@ZeroIntensity
Copy link
Member

Ah, I misinterpreted/misread it--I saw "on error" as "erroneously." Sorry 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

No branches or pull requests

4 participants