-
Notifications
You must be signed in to change notification settings - Fork 345
Code that uses import arcade
doesn't type check properly with mypy
#537
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
Comments
I like the idea of changing the |
Working on this now. Wrote a program to auto-pull out a lot of this. There's a lot of dependency stuff to slog through, and other bugs that popped up. |
…r with MyPy and be more python-proper.
I fetched the current master and ran the mypy tests documented in #533 . They came back clean. So, the |
Yes! Great news. |
Good news / bad news. :) As I said, type checking is happy, but I just discovered runtime isn't. Complaining about |
Yeah, I haven't figured that one out yet. |
Ok, looks like I need to prepend a period.
|
Mypy now running clean in the codebase. |
I pulled the most recent master down and mypy runs cleanly for me as well. |
Closed with release of 2.2.7. |
Bug Report
When using
mypy
to type check projects that depend on arcade,mypy
is unable to handle code imported from arcade.Actual behavior:
When using
mypy
to type check code that imports arcade with the style in the documentation & example code,mypy
reports errors like "Module has no attribute ..."Expected behavior:
It is expected that code that relies on
import arcade
should type hint cleanly withmypy
.Steps to reproduce/example code:
The code snippet below uses the suggested
import arcade
style of importing the arcade package. It runs as expected. However, when you type check it withmypy
, errors are returned:The Sprite is obviously there because the code runs as expected.
mypy
can't find it.Same behavior with a slightly different import method:
Interestingly, a more explicit method of importing arcade both runs and type checks properly. However, this style of importing isn't in the documentation or arcade example code:
I'm guessing this is happening because of the
from arcade.sprite import *
style imports arcade does in its__init__.py
flie to get everything into thearcade
namespace. Maybemypy
can't follow the imports and fails? In general, I believe the*
style of importing is discouraged.The fix might be to change the
from arcade.sprite import *
style imports in__init__.py
tofrom arcade.sprite import Sprite, AnimationKeyframe, AnimatedTimeBasedSprite, AnimatedWalkingSprite, get_distance_between_sprites
. Obviously more verbose and a bit more to maintain. But, it is explicit.The text was updated successfully, but these errors were encountered: