-
Notifications
You must be signed in to change notification settings - Fork 164
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
graphviz typing error #1357
Comments
I need to check if this still applies to main with the latest commit after #1291. I believe the answer will be no.
|
Ah, sorry. I forgot to check main before opening the issue. It does look as though this is solved in main. An Thanks again for the quick response and a great package :) |
I have quite a few typing PRs open. Once Matthew has time to review them, I will work on the I think the ignore was there initially because Pillow didn't have type stubs initially. And then we never updated it |
Both mypy and pyright can be configured to emit an error if there is an unusued |
I have revisited this with For graphviz specifically:
We annotated the argument with |
That's very surprising, @IvanIsCoding. How did you run pyright? When I use # t.py
from __future__ import annotations
from typing import reveal_type
import rustworkx
import rustworkx.visualization
g1: rustworkx.PyGraph[int, int] = rustworkx.PyGraph()
img = rustworkx.visualization.graphviz_draw(g1)
reveal_type(img)
g2 = rustworkx.PyGraph[int, int]()
img = rustworkx.visualization.graphviz_draw(g2)
reveal_type(img)
g3 = rustworkx.PyGraph()
img = rustworkx.visualization.graphviz_draw(g3)
reveal_type(img) Adding
I get no errors:
Maybe I did notice that the script I listed in the original post above still doesn't pass |
@barakatzir I just ran There are lots of errors ranging from errors propagating from the NumPy stubs to many other complaints about rustworkx. I will try to understand and possibly address them but overall for now I will say the output from |
Wow! That is a very long list. |
Okay, so (.venv) $ pyright --verifytypes rustworkx --ignoreexternal
Module name: "rustworkx"
Package directory: "/home/barak-katzir/dev/rustworkx-check/.venv/lib/python3.12/site-packages/rustworkx"
Module directory: "/home/barak-katzir/dev/rustworkx-check/.venv/lib/python3.12/site-packages/rustworkx"
Path of py.typed file: "/home/barak-katzir/dev/rustworkx-check/.venv/lib/python3.12/site-packages/rustworkx/py.typed"
Public modules: 7
rustworkx
rustworkx.generators
rustworkx.rustworkx
rustworkx.visit
rustworkx.visualization
rustworkx.visualization.graphviz
rustworkx.visualization.matplotlib
Symbols used in public interface:
rustworkx.bipartite_layout
/home/barak-katzir/dev/rustworkx-check/.venv/lib/python3.12/site-packages/rustworkx/__init__.pyi:461:5 - error: Type annotation for parameter "aspect_ratio" is missing
Symbols exported by "rustworkx": 707
With known type: 706
With ambiguous type: 0
With unknown type: 1
(Ignoring unknown types imported from other packages)
Other symbols referenced but not exported by "rustworkx": 59
With known type: 59
With ambiguous type: 0
With unknown type: 0
Symbols without documentation:
Functions without docstring: 586
Functions without default param: 288
Classes without docstring: 89
Type completeness score: 99.9%
Completed in 1.258sec When I locally fix the annotation, |
Note that if you want to add both If you do plan to add both I suggest you set This is only really problematic if you want them to emit an error for unnecessary ignores and their diagnosis differ (which does happen), but I think it is better to have separate ignores nonetheless (for I'm mentioning to hopefully save you time. I wasted a good hour on re-ignoring stuff in a private project. |
Information
graphviz_draw
has wrong documentation of return type both in type annotation and docstring. It is marked asPIL.Image
when in fact it should bePIL.Image.Image
.This confused me for a good while, since the module is both camel cased and has the same name as the correct return type...
"Doctesting" with pyright,
pyright --verifytypes rustworkx
, reports the wrong documentation in the type annotation (mypy -p rustworkx
misses it due to a# type: ignore
on that line) .Steps to reproduce the problem
Use
graphviz_draw
anywhere and check your script and check with pyright or mypy, the return type is inferred incorrectly.In runtime
python script.py
reports correctlyRuntime type is 'PngImageFile'
(PngImageFile
is a subtype ifImage.Image
).The two type checkers fail, one has missing inferred type and the other is wrong:
pyright
then output isscript.py:8:13 - information: Type of "img" is "Unknown"
.mypy
then output isscript.py:8: note: Revealed type is "None"
.The text was updated successfully, but these errors were encountered: