Skip to content

Conversation

@MVrachev
Copy link
Collaborator

Description of the changes being introduced by the pull request:
This quote from the Google Python style guide made me realize
why empty list as a default value for an argument could be
dangerous:

Default arguments are evaluated once at module load time. This may cause problems if the argument is a mutable object such as a list or a dictionary. If the function modifies the object (e.g., by appending an item to a list), the default value is modified.

Read more here:
https://google.github.io/styleguide/pyguide.html#2123-cons

Also, currently, we are importing the "utils" module in tests/utils
with "import utils".
This could become a problem when there is another module with
the same general name "utils" and could lead to import mistakes.

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@MVrachev MVrachev changed the title Fix imports and default Fix imports and default value for function arg Nov 19, 2020
@MVrachev MVrachev force-pushed the fix-imports-and-default branch from 3a169f4 to d8d68e7 Compare November 19, 2020 13:09
Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default value is only dangerous if the function actually modified the value -- but as defensive and consistent programming these both look like solid changes to me.

@MVrachev MVrachev force-pushed the fix-imports-and-default branch from d8d68e7 to 7957582 Compare November 19, 2020 13:38
This quote from the Google Python style guide made me realize
why empty list as a default value for an argument could be
dangerous:

"Default arguments are evaluated once at module load time.
This may cause problems if the argument is a mutable object
such as a list or a dictionary. If the function modifies the object
(e.g., by appending an item to a list), the default value is modified."

Read more here:
https://google.github.io/styleguide/pyguide.html#2123-cons

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
Currently, we are importing the "utils" module in tests/utils
with "import utils".
This could become a problem when there is another module with
the same general name "utils" and could lead to import mistakes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
@MVrachev MVrachev force-pushed the fix-imports-and-default branch from 7957582 to 028d1bc Compare November 23, 2020 20:17
Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like good improvements, particularly the empty list as default argument fix. Thanks @MVrachev!

@joshuagl joshuagl merged commit e005801 into theupdateframework:develop Nov 25, 2020
@MVrachev MVrachev deleted the fix-imports-and-default branch November 25, 2020 17:00
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

Successfully merging this pull request may close these issues.

3 participants