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

Run mypy on cases_generator #104504

Closed
sobolevn opened this issue May 15, 2023 · 6 comments
Closed

Run mypy on cases_generator #104504

sobolevn opened this issue May 15, 2023 · 6 comments
Assignees
Labels
topic-typing type-feature A feature request or enhancement

Comments

@sobolevn
Copy link
Member

sobolevn commented May 15, 2023

Feature or enhancement

After #104421 is merged, we now have the precedent and the needed infrastructure to run mypy on things that support type annotations in Tools/

Pitch

Maybe we should run it on Tools/cases_generator? It has all annotations in place, it needs very little work. Right now mypy finds only 24 errors.

Full list:

» mypy .
parser.py:22: error: Return value expected  [return-value]
                return
                ^~~~~~
parser.py:142: error: Missing return statement  [return]
        def definition(self) -> InstDef | Super | Macro | Family | None:
        ^
parser.py:168: error: Module has no attribute "OVERRIDE"  [attr-defined]
            override = bool(self.expect(lx.OVERRIDE))
                                        ^~~~~~~~~~~
parser.py:169: error: Module has no attribute "REGISTER"  [attr-defined]
            register = bool(self.expect(lx.REGISTER))
                                        ^~~~~~~~~~~
parser.py:177: error: Argument 3 to "InstHeader" has incompatible type "str";
expected "Literal['inst', 'op', 'legacy']"  [arg-type]
    ...                 return InstHeader(override, register, kind, name, inp, outp...
                                                              ^~~~
parser.py:200: error: Incompatible return value type (got
"List[Union[StackEffect, CacheEffect, Node]]", expected
"Optional[List[Union[StackEffect, CacheEffect]]]")  [return-value]
                        return [inp] + rest
                               ^~~~~~~~~~~~
parser.py:202: error: List item 0 has incompatible type "Node"; expected
"Union[StackEffect, CacheEffect]"  [list-item]
                return [inp]
                        ^~~
parser.py:228: error: Missing return statement  [return]
        def cache_effect(self) -> CacheEffect | None:
        ^
parser.py:241: error: Missing return statement  [return]
        def stack_effect(self) -> StackEffect | None:
        ^
parser.py:249: error: Module has no attribute "IF"  [attr-defined]
                if self.expect(lx.IF):
                               ^~~~~
parser.py:284: error: Missing return statement  [return]
        def super_def(self) -> Super | None:
        ^
parser.py:295: error: Missing return statement  [return]
        def ops(self) -> list[OpName] | None:
        ^
parser.py:304: error: Missing return statement  [return]
        def op(self) -> OpName | None:
        ^
parser.py:309: error: Missing return statement  [return]
        def macro_def(self) -> Macro | None:
        ^
parser.py:320: error: Missing return statement  [return]
        def uops(self) -> list[UOp] | None:
        ^
parser.py:328: error: Incompatible return value type (got "List[Node]", expected
"Optional[List[Union[OpName, CacheEffect]]]")  [return-value]
                return uops
                       ^~~~
parser.py:331: error: Missing return statement  [return]
        def uop(self) -> UOp | None:
        ^
parser.py:384: error: Missing return statement  [return]
        def block(self) -> Block | None:
        ^
generate_cases.py:395: error: Item "None" of "Optional[Context]" has no attribute
"owner"  [union-attr]
            filename = context.owner.filename
                       ^~~~~~~~~~~~~
generate_cases.py:598: error: Incompatible types in assignment (expression has type
"Optional[Node]", variable has type "Union[InstDef, Super, Macro, Family, None]") 
[assignment]
            while thing := psr.definition():
                           ^~~~~~~~~~~~~~~~
generate_cases.py:664: error: Item "None" of "Optional[Family]" has no attribute
"name"  [union-attr]
                                f"Instruction {member} is a member of multiple f...
                                ^
generate_cases.py:675: error: Item "None" of "Optional[Family]" has no attribute
"name"  [union-attr]
                                        f"Component {part.instr.name} of macro {...
                                        ^
test_generator.py:46: error: Missing positional argument "metadata_filename" in call
to "Analyzer"  [call-arg]
        a = generate_cases.Analyzer(temp_input.name, temp_output.name)
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_generator.py:46: error: Argument 1 to "Analyzer" has incompatible type "str";
expected "List[str]"  [arg-type]
        a = generate_cases.Analyzer(temp_input.name, temp_output.name)
                                    ^~~~~~~~~~~~~~~
Found 24 errors in 3 files (checked 5 source files)

If @gvanrossum finds it useful, I can surely work on this.
CC @AlexWaygood

Linked PRs

@sobolevn sobolevn added type-feature A feature request or enhancement topic-typing labels May 15, 2023
@sunmy2019
Copy link
Member

I think it's useful. Tools/ are for internal usage. The risk is relatively small.

@gvanrossum
Copy link
Member

I don't object, and it may occasionally help. I've come this far mostly by using the VS Code type checker (pylance/pyright) in strict mode, and that has definitely helped me. There are also some annoying bits, in particular lexer.py was written in an overly dynamic style. Maybe it should just be fixed. I'm happy to take PRs.

@sobolevn sobolevn self-assigned this May 15, 2023
@sobolevn
Copy link
Member Author

Ok then! I will get back to it after the confence I am making is over :)

@AlexWaygood AlexWaygood changed the title Running mypy on cases_generator Run mypy on cases_generator Jun 7, 2023
@gvanrossum
Copy link
Member

@sobolevn Are you still planning to work on this? Before you go too deep, I expect that the main source of issues is the dynamic nature of lexer.py. We may just have to refactor that to be less introspective. I think it would improve its maintainability.

@sobolevn
Copy link
Member Author

sobolevn commented Jul 3, 2023

Yes, it is still on my TODO list. I can increase the priority :)

corona10 added a commit to corona10/cpython that referenced this issue Aug 17, 2023
corona10 added a commit to corona10/cpython that referenced this issue Aug 18, 2023
@corona10 corona10 self-assigned this Aug 18, 2023
corona10 added a commit that referenced this issue Aug 18, 2023
@corona10
Copy link
Member

@sobolevn

Now the issue looks to be solved.
If you want to reopen the issue, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants