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

Fixes most mypy errors and run it on CI #82

Merged
merged 15 commits into from
Aug 1, 2023

Conversation

guilhermeleobas
Copy link
Contributor

This PR fixes most mypy errors and enable it on CI.

@guilhermeleobas guilhermeleobas marked this pull request as ready for review July 5, 2023 19:37
Copy link
Contributor

@kc611 kc611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with the comments above, could you give this PR a run of pre-commit after these changes. (Specifically black recommended some changes)

numba_rvsdg/core/transformations.py Outdated Show resolved Hide resolved
numba_rvsdg/core/datastructures/basic_block.py Outdated Show resolved Hide resolved
.github/workflows/test.yml Outdated Show resolved Hide resolved
@guilhermeleobas
Copy link
Contributor Author

Hi @kc611, thanks for the review. Do you have any other comments or request in this PR?

Copy link
Contributor

@kc611 kc611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this PR LGTM!

@guilhermeleobas
Copy link
Contributor Author

Thank you

@esc
Copy link
Member

esc commented Jul 12, 2023

@guilhermeleobas I gave this another review and noticed that I can't run mypy from the command line, but only via pre-commit:

 💣 zsh» mypy numba_rvsdg
numba_rvsdg/rendering/rendering.py:14: error: Skipping analyzing "graphviz": module is installed, but missing library stubs or py.typed marker
numba_rvsdg/rendering/rendering.py:14: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 10 source files)

What else do I need for this to pass?

Copy link
Member

@esc esc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this and it seems, beyond the annotations there has been some functional changes. Specifically, the following example, which works on main at 93ad199 will raise an exception while trying to render:

from numba_rvsdg.rendering.rendering import render_func

def foo(x):
    c = 0
    for i in range(x):
        c += i
        if c <= 0:
            continue
        else:
            for j in range(c):
                c += j
                if c > 100:
                    break
    return c

render_func(foo)

And the exception is:

Traceback (most recent call last):
  File "/Users/esc/git/numba-rvsdg/example2.py", line 16, in <module>
    render_func(foo)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 332, in render_func
    render_flow(ByteFlow.from_bytecode(func))
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 368, in render_flow
    ByteFlowRenderer().render_byteflow(bflow).view("branch restructured")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 200, in render_byteflow
    self.render_block(self.g, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 75, in render_block
    self.render_region_block(digraph, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 154, in render_region_block
    self.render_block(subg, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 75, in render_block
    self.render_region_block(digraph, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 154, in render_region_block
    self.render_block(subg, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 75, in render_block
    self.render_region_block(digraph, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 154, in render_region_block
    self.render_block(subg, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 75, in render_block
    self.render_region_block(digraph, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 154, in render_region_block
    self.render_block(subg, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 75, in render_block
    self.render_region_block(digraph, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 154, in render_region_block
    self.render_block(subg, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 75, in render_block
    self.render_region_block(digraph, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 154, in render_region_block
    self.render_block(subg, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 75, in render_block
    self.render_region_block(digraph, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 154, in render_region_block
    self.render_block(subg, name, block)
  File "/Users/esc/git/numba-rvsdg/numba_rvsdg/rendering/rendering.py", line 77, in render_block
    raise Exception("unreachable")
Exception: unreachable

numba_rvsdg/core/datastructures/scfg.py Outdated Show resolved Hide resolved
numba_rvsdg/core/transformations.py Outdated Show resolved Hide resolved
numba_rvsdg/core/transformations.py Outdated Show resolved Hide resolved
numba_rvsdg/networkx_vendored/scc.py Show resolved Hide resolved
@@ -1,3 +1,5 @@
# mypy: ignore-errors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests here seem to be annotated, can we include this file too?

@guilhermeleobas
Copy link
Contributor Author

guilhermeleobas commented Jul 12, 2023

@guilhermeleobas I gave this another review and noticed that I can't run mypy from the command line, but only via pre-commit:

 💣 zsh» mypy numba_rvsdg
numba_rvsdg/rendering/rendering.py:14: error: Skipping analyzing "graphviz": module is installed, but missing library stubs or py.typed marker
numba_rvsdg/rendering/rendering.py:14: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 10 source files)

What else do I need for this to pass?

You need to install three packages: types-filelock types-pyyaml types-setuptools. If you run mypy from pre-commit, it will automatically install those for you

Not much we can do here, as graphviz doesn't follow PEP-561: It doesn't ship with a py.typed file. See:
xflr6/graphviz#180

@guilhermeleobas
Copy link
Contributor Author

@esc, I fixed the bug you reported in c1a6177

@esc
Copy link
Member

esc commented Jul 13, 2023

@guilhermeleobas I gave this another review and noticed that I can't run mypy from the command line, but only via pre-commit:

 💣 zsh» mypy numba_rvsdg
numba_rvsdg/rendering/rendering.py:14: error: Skipping analyzing "graphviz": module is installed, but missing library stubs or py.typed marker
numba_rvsdg/rendering/rendering.py:14: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 10 source files)

What else do I need for this to pass?

You need to install three packages: types-filelock types-pyyaml types-setuptools. If you run mypy from pre-commit, it will automatically install those for you

Not much we can do here, as graphviz doesn't follow PEP-561: It doesn't ship with a py.typed file. See: xflr6/graphviz#180

OK. Do you know why running it with pre-commit will make it pass, but using mypy directly will not?

@esc
Copy link
Member

esc commented Jul 13, 2023

@esc, I fixed the bug you reported in c1a6177

Looks good, thank you, I can confirm that it works.

@kc611
Copy link
Contributor

kc611 commented Jul 20, 2023

Is this PR waiting on anything?

If not, can we go ahead with merging it?

@guilhermeleobas
Copy link
Contributor Author

Is this PR waiting on anything?

Not that I am aware of

@guilhermeleobas
Copy link
Contributor Author

@guilhermeleobas I gave this another review and noticed that I can't run mypy from the command line, but only via pre-commit:

 💣 zsh» mypy numba_rvsdg
numba_rvsdg/rendering/rendering.py:14: error: Skipping analyzing "graphviz": module is installed, but missing library stubs or py.typed marker
numba_rvsdg/rendering/rendering.py:14: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 10 source files)

What else do I need for this to pass?

You need to install three packages: types-filelock types-pyyaml types-setuptools. If you run mypy from pre-commit, it will automatically install those for you
Not much we can do here, as graphviz doesn't follow PEP-561: It doesn't ship with a py.typed file. See: xflr6/graphviz#180

OK. Do you know why running it with pre-commit will make it pass, but using mypy directly will not?

Perhaps it is related to pypa/pip#9502

Copy link
Contributor

@kc611 kc611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

The skipping of graphviz checking by mypy can be made into an separate issue for now. There doesn't seem to be a clear reason as to why it is happening and is anyways beyond the scope of the changes being implemented in this PR.

@esc
Copy link
Member

esc commented Aug 1, 2023

LGTM!

The skipping of graphviz checking by mypy can be made into an separate issue for now. There doesn't seem to be a clear reason as to why it is happening and is anyways beyond the scope of the changes being implemented in this PR.

OK!

@esc esc merged commit cd671f0 into numba:main Aug 1, 2023
2 checks passed
@esc
Copy link
Member

esc commented Aug 1, 2023

@guilhermeleobas thank you for the patch. @kc611 thank you for the review.

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

Successfully merging this pull request may close these issues.

3 participants