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 type annotation issues with VS Code and generating docs #911

Closed
benhoyt opened this issue Feb 28, 2023 · 3 comments
Closed

Fix type annotation issues with VS Code and generating docs #911

benhoyt opened this issue Feb 28, 2023 · 3 comments

Comments

@benhoyt
Copy link
Collaborator

benhoyt commented Feb 28, 2023

There seems to be some inconsistency with our type annotations that's causing VS Code problems. From David Anderson, who raised this issue here:

David: It would be good to limit the use of the Any type. E.g., self.unit.get_container().exec returns the Any type

Me: In this specific case, exec() does not return Any, but ExecProcess

David: It seems that the reason is that the import fails in VSCode because the ExecProcess is imported from pebble rather than ops.pebble in model.py. When I change the import from pebble to ops.pebble the type hint is correctly identified.

The other thing is that the class for the type hint (ExecProcess) is actually imported on line 63 where line 59 says from pebble import (..., ExecProcess, ...). Thats the line I had to change to from ops.pebble import (..., ExecProcess, ...) (other imports omitted), referring to model.py here

The pebble import is on line 54, I'm not sure how that line interacts with line 59

if the type hint on line 2297 in model.py was changed to "pebble.ExecProcess" VSCode is fine with that too

@benhoyt
Copy link
Collaborator Author

benhoyt commented Jun 14, 2023

@jdkandersson Can you please confirm this is fixed in VSCode on the main branch, by #944 and #942? I suspect it won't be an issue any more.

@jdkandersson
Copy link

Yes looks like this got fixed, thanks!
Screenshot 2023-06-14 at 12 55 59 pm

@benhoyt
Copy link
Collaborator Author

benhoyt commented Jun 14, 2023

Nice, thank you for checking!

@benhoyt benhoyt closed this as completed Jun 14, 2023
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

No branches or pull requests

2 participants