Use mypy annotations#9
Open
bergercookie wants to merge 3 commits into
Open
Conversation
e87182a to
49dd3bb
Compare
Fix error when `dependencies` Cargo key is not found
49dd3bb to
0ebebcf
Compare
kjeremy
reviewed
Nov 18, 2020
esteve
requested changes
May 6, 2021
| from colcon_core.environment_variable import EnvironmentVariable | ||
|
|
||
| """Environment variable to override the Cargo executable""" | ||
| # Environment variable to override the Cargo executable |
Contributor
Author
There was a problem hiding this comment.
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: |
Contributor
There was a problem hiding this comment.
This already returns None if the executable_name can't be found, so it can be simplified as:
return shutil.which(executable_name)
Contributor
Author
There was a problem hiding this comment.
yes, agree, I 'll change it back
| if value: | ||
| return value | ||
| return shutil.which(executable_name) | ||
| if environment_variable in os.environ: |
Contributor
There was a problem hiding this comment.
This change is equivalent to the existing code, why the change?
Contributor
Author
There was a problem hiding this comment.
I find queyring directly the os.environ more readable in a couple of ways:
- There's no need for the intermediate
valuevariable, which doesn't say much about the value it holds anyway - the environment in python is just a dictionary, so using an
osfunction,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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
dependenciesCargo key is not found (it's tightly coupled with the change in mypy types - hence I can't make a separate PR for it.