Skip to content

Arcade should make its type hinting available to other modules via PEP 561 #533

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

Closed
SirGnip opened this issue Dec 7, 2019 · 7 comments
Closed

Comments

@SirGnip
Copy link
Contributor

SirGnip commented Dec 7, 2019

Bug Report

Arcade has type hints, but that type hinting information isn't exposed for other modules to use it. See the mypy docs and PEP 561 for more details.

Actual behavior:

When running mypy against a project that relies on arcade, mypy reports that "arcade" does not provide type hinting:

$ mypy src/
src\myapp.py:4: error: Cannot find implementation or library stub for module named 'arcade'

Expected behavior:

A project that depends on the arcade package should be able to leverage arcade's type hinting.

The fix

A PR is forthcoming...

@pvcraven
Copy link
Member

Is this fixed now with the PR?

@SirGnip
Copy link
Contributor Author

SirGnip commented Jan 2, 2020

Hm. It appears the PR got it further but it is not 100% working. If I install arcade 2.2.1, create a script named "test.py" that contains:

import arcade
print(arcade.Sprite())

...and run mypy on it like this:

$ venv/Scripts/mypy test.py --strict
test.py:2: error: Module has no attribute "Sprite"
Found 1 error in 1 file (checked 1 source file)

...it appears that mypy is able to use arcade's type hinting info (no more "Cannot find implementation or library stub for module named 'arcade'" error). But, it can't find the specific Sprite class. I'm guessing that is because of the import * syntax in arcade/__init__.py? If I create test2.py with this snippet:

from arcade.sprite import Sprite
print(Sprite())

...and run mypy...

$ venv/Scripts/mypy test2.py --strict
Success: no issues found in 1 source file

...mypy reports no issues.

Unfortunately, refactoring arcade/__init__.py and not breaking backwards compatibility with existing scripts (import paths, etc) is beyond the time I have available right now. This might be a helpful starting point on mypy's behavior with "star" imports: python/mypy#4930

@pvcraven
Copy link
Member

pvcraven commented Jan 3, 2020

The master branch has a lot of work on it already, but yeah. It isn't proving to be easy:

https://github.com/pvcraven/arcade/blob/master/arcade/__init__.py

@SirGnip
Copy link
Contributor Author

SirGnip commented Jan 3, 2020

Ah! I hadn't fetched in a couple weeks so I didn't notice this. I'll do a fetch and see how things look with the new init.py.

@SirGnip
Copy link
Contributor Author

SirGnip commented Jan 3, 2020

My mind is mush. I forgot about https://github.com/pvcraven/arcade/issues/537. I'd consider this issue complete and #537 will make it fully functional,

@pvcraven
Copy link
Member

How is this working?

@pvcraven
Copy link
Member

Fixed in current versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants