Skip to content

Conversation

@bergercookie
Copy link
Contributor

@bergercookie bergercookie commented Nov 9, 2020

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.

Fix error when `dependencies` Cargo key is not found
Co-authored-by: Jeremy Kolb <[email protected]>
from colcon_core.environment_variable import EnvironmentVariable

"""Environment variable to override the Cargo executable"""
# Environment variable to override the Cargo executable
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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)

Copy link
Contributor Author

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:
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants