-
Notifications
You must be signed in to change notification settings - Fork 753
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
CI: strict mypy check in github actions #3107
Conversation
mypy_files.txt is a list of files that will fail the CI if mypy finds errors in them
Ah hmmm, I have a PR open for a I suppose I can have a |
There are some decisions here on mypy options that might be worth discussing.
I'm still kind of on the fence about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So idk if there's anything you can do about this, but when I wanted to run this locally, I had the following problem
I ran the command on Windows in Git Bash.
It would keep telling me invalid argument
for each line.
This was because of CRLF line endings. I needed to convert the .txt
file to LF first, and then it worked: dos2unix ./.github/mypy_files.txt
This might be because my Git is configured in such a way that it auto replaces LF with CRLF on clone/pull, and then converts back on commit/push.
Maybe worth making a note about somewhere, not sure
.github/mypy_check.sh
Outdated
cd .. | ||
fi | ||
|
||
xargs mypy --strict --follow-imports=silent --no-warn-unused-ignore --no-warn-return-any --install-types --non-interactive typings < .github/mypy_files.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do import schema
in an options.py file, I get this:
worlds\witness\options.py:3: error: Skipping analyzing "schema": module is installed, but missing library stubs or py.typed marker [import-untyped]
That probably needs to be supressed? Not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add --disable-error-code=import-untyped
But another solution, that is more type safe, but also takes more work, is to make our own type stubs for libraries we use that don't have type information.
That's what the typings
directory is for in Archipelago. I've been maintaining some kivy
type stubs there for a while.
I improve them once in a while for the things I work on. We don't have typing for all of kivy, because that would be a ton of work. So I just add typing for the parts I work with.
@NewSoupVi I'd like you to comment on the From this line world = self.parent_region.multiworld.worlds[self.player] The type checker doesn't know that return world.shop_prices[name] + prereq_cost It's kind of by chance that you don't get a type error rather than Archipelago/worlds/AutoWorld.py Line 306 in 569c37c
If it weren't for that, you'd need to deal with this even with --no-warn-return-any , but other relevant situations will be similar to this.
The way I would resolve this is with assert isinstance(world, MessengerWorld) (importing Do you think situations like this are worth using |
There are definitely some justifications for "Any", and I think forcing compliant worlds to use Here is a situation I ran into:
So I would have to do this:
But, because "Any" is allowed, I was able to just do this instead:
which was nice. I can also see arguments against allowing "Any", but I feel like if we make it super hard for worlds to comply with this, it's probably less likely that people are going to jump on board. I feel like I already have a high tolerance for a Python dev for putting |
I tried to refactor Witness to be mypy compliant. It exposed some genuine bugs, which is cool. It also shows some huge structural problems and oddities of my implementation that will now stare me in the face until I fix them, which is great as well. The only annoying thing is that since core is not mypy compliant, I can't fix two of the errors. I would have to go into core myself and make PRs to make those files mypy compliant. I think potentially disabling Edit: I can also think of a case here where for example an ap randomizer wraps and existing randomizerthat is also written in Python (OoT is an example), and in that case I would also think it's unfair to expect "import-untyped" to be complied with |
This particular option isn't about any usage of Even without allowing the return of If you remove the The purpose of this feature is to stop problems from escaping the function and spreading. |
Oh, that's my bad (I'm completely new to the world of mypy haha). In that case, I think I might be on board? In the example you gave, I absolutely think the world should be cast to MessengerWorld. |
I think I want to keep
This is exactly why I said "Adding all worlds doesn't need to be a goal", and should be opt-in.
|
Interesting. I don't know if I'd personally be motivated to go into core to add typing because I can't put my world in otherwise, so I might just, like, run the mypy locally and be happy that it's still returning 2 errors because of core. |
Something I've noticed while working on cleaning up my world with this, and will undoubtedly be a common question should anyone try to add their own world to this: for i in range(1, 11):
set_rule(world.get_location(f"Location {i}"), lambda state, x=i: state.has("Item", x, world.player)) This will throw the following mypy error, while currently being the most accepted way of solving this problem. Unsure of what solutions are available, if any. It seems this error cannot be disabled without disabling all misc errors. |
This is an issue reported in the mypy issue tracker: python/mypy#15459 In Zillion, I use This brings up another possible point of discussion for this: |
It wasn't as hard as I thought it would be: #3121 |
We might add mypy to the existing pyright check. |
What is this fixing or adding?
mypy_files.txt is a list of files that will fail the CI if mypy finds errors in them
The idea is that we gradually add files and directories to the list as we get them cleaned up.
Eventually it can include all core python source files/directories.
World files and directories could be opt-in by the world maintainer. Adding all worlds doesn't need to be a goal.
This will help keep typing issues from creeping back in after they have been cleaned up.
The check that is done by CI is in a bash script
.github/mypy_check.sh
A few minor typing changes are included here that are needed to finish cleaning these starting files.
How was this tested?
running the
.github/mypy_check.sh
script