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

Ability to inspect type hints of live objects using .pyi files #1934

Closed
chadrik opened this issue Jul 23, 2016 · 2 comments
Closed

Ability to inspect type hints of live objects using .pyi files #1934

chadrik opened this issue Jul 23, 2016 · 2 comments

Comments

@chadrik
Copy link
Contributor

chadrik commented Jul 23, 2016

It would be very useful to be able to inspect the type annotations of live objects whose types are defined in pyi files. Merging type annotation with inspect.getargspec would open up a word of possibilities in python, such as automatic UI generation for functions/classes.

As an experiment, I tried the following (yes I know imp is deprecated):

from typing import get_type_hints

import imp
filepath = '/Users/chad/dev/mypy/typeshed/stdlib/2.7/itertools.pyi'

with open(filepath, 'r') as f:
    mod = imp.load_module('itertools', f, filepath, ('.pyi', 'r', 1))
print(get_type_hints(mod.repeat))

This failed because of the use of @overload in the pyi file. Commenting these out got the test working. So, there's at least two problems to solve:

@gvanrossum
Copy link
Member

Sorry, this just isn't going to happen any time soon. Apart from overload there are other reasons why the code in stubs just isn't importable (e.g. forward references).

Your request also blurs the line between mypy and runtime support.

@pirate
Copy link

pirate commented Jul 15, 2018

For anyone reading this issue in 2018 looking for automatic runtime type inference, I found this helpful: https://github.com/dropbox/pyannotate

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

No branches or pull requests

3 participants