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

fix: mypy "has-type" check #848

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

bartsanchez
Copy link
Contributor

No description provided.

@@ -106,7 +106,7 @@ class Number:

def __init__(self, value):
if isinstance(value, Number):
self.value = value.value
self.value: Any = value.value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be:

self.value: int | None = value.value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, changed!

@@ -440,7 +440,7 @@ def optimize(self, patterns_list):
"c": str(self.cpu.C) if self.cpu.C is not None else new_tmp_val(),
"z": str(self.cpu.Z) if self.cpu.Z is not None else new_tmp_val(),
}.get(x.lower(), new_tmp_val())
evaluator.UNARY[FN.IS_REQUIRED] = lambda x: self.is_used([x], i + len(p.patt))
evaluator.UNARY[FN.IS_REQUIRED] = lambda x: self.is_used([x], i + len(p.patt)) # type: ignore[has-type]
Copy link
Collaborator

@boriel boriel Oct 28, 2024

Choose a reason for hiding this comment

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

Here i is int and p is of type OptPattern.

Suggestion:

  • add from src.arch.z80.peephole.engine import OptPattern at the beginning of the file.
  • change the function signature to: def optimize(self, patterns_list: Sequence[OptPattern]) -> None:
  • Add these to lines below the function header:
    i: int
    p: OptPattern

This way we can get rid of the # type: ignore line 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the variables below the function header.

Copy link
Collaborator

@boriel boriel left a comment

Choose a reason for hiding this comment

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

I think it's better to type the missing variables.
What do you think?

@boriel boriel merged commit 24fee37 into boriel-basic:main Oct 28, 2024
1 check passed
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.

2 participants