-
Notifications
You must be signed in to change notification settings - Fork 20
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
Use mypy annotations #9
base: main
Are you sure you want to change the base?
Conversation
e87182a
to
49dd3bb
Compare
Fix error when `dependencies` Cargo key is not found
49dd3bb
to
0ebebcf
Compare
import os | ||
import shutil | ||
|
||
from colcon_core.environment_variable import EnvironmentVariable | ||
|
||
"""Environment variable to override the Cargo executable""" | ||
# Environment variable to override the Cargo executable |
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.
I'd keep this as docstring
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.
Depends what you use to generate the documentation, but if we're talking about sphinx, it doesn't support extracting docstrings from variables unfortunately
return os.environ[environment_variable] | ||
|
||
which = shutil.which(executable_name) | ||
if which: |
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.
This already returns None
if the executable_name
can't be found, so it can be simplified as:
return shutil.which(executable_name)
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.
yes, agree, I 'll change it back
if value: | ||
return value | ||
return shutil.which(executable_name) | ||
if environment_variable in os.environ: |
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.
This change is equivalent to the existing code, why the change?
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.
I find queyring directly the os.environ
more readable in a couple of ways:
- There's no need for the intermediate
value
variable, which doesn't say much about the value it holds anyway - the environment in python is just a dictionary, so using an
os
function,getenv
, to manipulate it sounds unnecessary since there are already established ways of querying a dictionary.
In any case, it's not terribly important, I can revert the change if you think it was better before.
Since colcon packages mandate Pytyhon 3.5 or higher, we can use explicit mypy annotations to document function parameters and output types instead of docstrings. I'm also removing the docstrings for the types since sphinx can parse and create documentation for mypy types.
Current PR also includes: Fix KeyError exception when
dependencies
Cargo key is not found (it's tightly coupled with the change in mypy types - hence I can't make a separate PR for it.