Open JackismyShephard opened 3 months ago
Hi @JackismyShephard did you resolve this issue? (Given https://github.com/gradio-app/gradio/issues/8928)
@abidlabs I have not solved this issue yet, but I might be able to solve it alongside https://github.com/gradio-app/gradio/issues/8928.
@abidlabs I have been able to solve this issue now locally. The problem was that a type stub (.pyi
file) was missing for gradio/__init__.py
. Pyright also complained about gradio.events
missing a stub file, so I added gradio/events.pyi
as well. Both type stubs explicitly export all definitions by setting __all__
appropriately.
I would like to incorporate these changes upstream but I know you render type stub files dynamically so I am not 100% sure how to replicate my manually defined type stubs.
Thanks @JackismyShephard! Just to make sure I understand, why do you need a .pyi file if it just has the same definitions as the .py files? Pyright should just be able to glean that information from the .py files directly?
I think that we just need to add __all__
in the gradio/__init__.py
? I notice that its missing in that file, but included in the other __init__.py
files. Can you see if adding that resolves the typing issues for you? (Perhaps similarly we need to modify gradio.events.py
instead of creating a new .pyi
file?)
@abidlabs I have tried doing as you suggest but that does not fix the error reported by pyright. Pyright is specifically complaining that a stub file is missing so a .pyi
exporting all definitions from the corresponding .py
is needed. Pyright by default infers typing from .py
files if no .pyi
files are present. I think the problem in this case might be that some but not all gradio module files have corresponding type stubs. This might be confusing pyright.
Edit: comment edited (improper initial testing)
Can confirm the "error" still present. However, pyright is still working, including gradio elements.
To get rid of the error (not very satisfactory):
"reportMissingTypeStubs":false
I think the problem in this case might be that some but not all gradio module files have corresponding type stubs. This might be confusing pyright.
After playing with pyright conf, and trying to patch my local gradio package, I have the same feeling too.
I'm experiencing a similar issue but with mypy
.
In app.py:
import gradio as gr
def hello_world(messages: str, history):
return "Hello, World!"
gr.ChatInterface(hello_world).launch()
When I run $ mypy app.py
, I get:
app.py:1: error: Skipping analyzing "gradio": module is installed, but missing library stubs or py.typed marker [import-untyped]
app.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
pip freeze | grep -E -e "gradio|mypy"
gradio==5.5.0
gradio_client==1.4.2
mypy==1.13.0
mypy-extensions==1.0.0
$ gradio enviroment
Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.5.0
gradio_client version: 1.4.2
@0gust1 @programmer-ke I have manually implemented stubs that fix this problem. I guess I could share the stubs if you are interested. Just have to keep in mind that these need to (potentially) be manually updated each time there is a gradio update.
@JackismyShephard if you can share here, we can revisit this issue and try to include them within the gradio
library
@abidlabs Here they are: gradio.zip
These should be up to date with gradio 5.6.0
Describe the bug
I am using pyright with strict mode for type checking in visual studio code. When importing gradio, pyright complains
Stub file not found for "gradio"
. I guess the error should have been fixed after this https://github.com/gradio-app/gradio/issues/6396 was solved, but that is not the case for me.Have you searched existing issues? 🔎
Reproduction
app.py
fileScreenshot
Logs
No response
System Info
Severity
I can work around it