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

Feature: support type stubs? #77

Closed
tlambert03 opened this issue May 30, 2022 · 3 comments · Fixed by #78
Closed

Feature: support type stubs? #77

tlambert03 opened this issue May 30, 2022 · 3 comments · Fixed by #78
Labels
feature New feature or request

Comments

@tlambert03
Copy link
Contributor

tlambert03 commented May 30, 2022

As mentioned in #75 (comment), one benefit of static API analysis is the ability to pick up stuff like @typing.overload-decorated functions, and other stuff that doesn't make it into a runtime representation.

This got me thinking: would it be within scope to support type stub / .pyi files?

as an example, consider this terrible, awful, very bad module:

# mymodule.py
globals()['f'] = lambda x: str(x)

Yes, this is a silly thing to do, but there are some cases where meta-programming is particularly powerful in python, so it's not out of the realm of "reasonable" possibilities to inject names into a namespace dynamically. If I'm ever tempted to do something like that, I'd always provide a type stub:

# mymodule.pyi
def f(x: int) -> str: ...

currently, griffe would find nothing:

from griffe import load
mod = load('mymodule')
print(mod.members)  # {}

... but perhaps it could also look for type stubs to find that info? Whether a type stub should simply override an actual py module, or whether there should be some attempt to merge is another question. (I'd tend to simply override if present, as type checkers seem to do)

@tlambert03 tlambert03 added the feature New feature or request label May 30, 2022
@pawamoy
Copy link
Member

pawamoy commented May 30, 2022

It's already supported! But maybe I forgot to support the case where the name passed to load_module is found as a file and not a folder.

@tlambert03
Copy link
Contributor Author

Excellent! Sorry I missed that 😂

@tlambert03
Copy link
Contributor Author

Found one more case where stubs are being missed:

my_package/
├── __init__.py
└── __init__.pyi

The top level __init__.pyi is never getting merged. Fix submitted in #78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants