Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7.7k
[Python] Do not use mutable default argument#4613
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bf7e33e0c3f787c77ac13027157f01c8647da67f9fde4e997e90ac04File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -155,14 +155,6 @@ class Configuration(object): | ||
| @logger_file.setter | ||
| def logger_file(self, value): | ||
| """The logger file. | ||
| If the logger_file is None, then add stream handler and remove file | ||
| handler. Otherwise, add file handler and remove stream handler. | ||
| :param value: The logger_file path. | ||
| :type: str | ||
| """ | ||
| self.__logger_file = value | ||
| if self.__logger_file: | ||
| # If set logging file, | ||
| @@ -174,7 +166,7 @@ class Configuration(object): | ||
| @property | ||
| def debug(self): | ||
| """Debug status | ||
| """The debug status. | ||
| :param value: The debug status, True or False. | ||
| :type: bool | ||
| @@ -183,11 +175,6 @@ class Configuration(object): | ||
| @debug.setter | ||
| def debug(self, value): | ||
| """Debug status | ||
| :param value: The debug status, True or False. | ||
| :type: bool | ||
| """ | ||
| self.__debug = value | ||
| if self.__debug: | ||
| # if debug status is True, turn on debug logging | ||
| @@ -216,18 +203,11 @@ class Configuration(object): | ||
| @logger_format.setter | ||
| def logger_format(self, value): | ||
| """The logger format. | ||
| The logger_formatter will be updated when sets logger_format. | ||
| :param value: The format string. | ||
| :type: str | ||
| """ | ||
| self.__logger_format = value | ||
| self.logger_formatter = logging.Formatter(self.__logger_format) | ||
| def get_api_key_with_prefix(self, identifier): | ||
| """Gets API key (with prefix if set). | ||
| """Get API key (with prefix if set). | ||
| :param identifier: The identifier of apiKey. | ||
| :return: The token for api key authentication. | ||
| @@ -243,7 +223,7 @@ class Configuration(object): | ||
| return key | ||
| def get_basic_auth_token(self): | ||
| """Gets HTTP basic authentication header (string). | ||
| """Get HTTP basic authentication header (string). | ||
| :return: The token for basic HTTP authentication. | ||
| """ | ||
| @@ -252,7 +232,7 @@ class Configuration(object): | ||
| ).get('authorization') | ||
| def auth_settings(self): | ||
| """Gets Auth Settings dict for api client. | ||
| """Get Auth Settings dict for api client. | ||
| :return: The Auth Settings information dict. | ||
| """ | ||
| @@ -303,7 +283,7 @@ class Configuration(object): | ||
| } | ||
| def to_debug_report(self): | ||
| """Gets the essential information for debugging. | ||
| """Get the essential information for debugging. | ||
| :return: The report for debugging. | ||
| """ | ||
| @@ -315,7 +295,7 @@ class Configuration(object): | ||
| format(env=sys.platform, pyversion=sys.version) | ||
| def get_host_settings(self): | ||
| """Gets an array of host settings | ||
| """Get an array of host settings | ||
| :return: An array of host settings | ||
| """ | ||
| @@ -349,41 +329,38 @@ class Configuration(object): | ||
| {{/servers}} | ||
| ] | ||
| def get_host_from_settings(self, index, variables={}): | ||
| """Gets host URL based on the index and variables | ||
| def get_host_from_settings(self, index, variables=None): | ||
| """Get host URL based on the index and variables. | ||
| :param index: array index of the host settings | ||
| :param variables: hash of variable and the corresponding value | ||
| :param variables: mapping of variable and the corresponding value | ||
jirikuncar marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| :return: URL based on host settings | ||
| """ | ||
| variables = {} if variables is None else variables | ||
jirikuncar marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| servers = self.get_host_settings() | ||
| # check array index out of bound | ||
| if index < 0 or index >= len(servers): | ||
| try: | ||
| server = servers[index] | ||
jirikuncar marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| except IndexError: | ||
| raise ValueError( | ||
| "Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501 | ||
| .format(index, len(servers))) | ||
| "Invalid index {0} when selecting the host settings. " | ||
| "Must be less than {1}".format(index, len(servers))) | ||
| server = servers[index] | ||
| url = server['url'] | ||
| # go through variable and assign a value | ||
| for variable_name in server['variables']: | ||
| if variable_name in variables: | ||
| if variables[variable_name] in server['variables'][ | ||
| variable_name]['enum_values']: | ||
| url = url.replace("{" + variable_name + "}", | ||
| variables[variable_name]) | ||
| else: | ||
| raise ValueError( | ||
| "The variable `{}` in the host URL has invalid value {}. Must be {}." # noqa: E501 | ||
| .format( | ||
| variable_name, variables[variable_name], | ||
| server['variables'][variable_name]['enum_values'])) | ||
| else: | ||
| # use default value | ||
| url = url.replace( | ||
| "{" + variable_name + "}", | ||
| server['variables'][variable_name]['default_value']) | ||
| # go through variables and replace placeholders | ||
| for variable_name, variable in server['variables'].items(): | ||
| used_value = variables.get( | ||
| variable_name, variable['default_value']) | ||
| if 'enum_values' in variable \ | ||
| and used_value not in variable['enum_values']: | ||
| raise ValueError( | ||
| "The variable `{0}` in the host URL has invalid value " | ||
| "{1}. Must be {2}.".format( | ||
| variable_name, variables[variable_name], | ||
| variable['enum_values'])) | ||
| url = url.replace("{" + variable_name + "}", used_value) | ||
| return url | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Please add a type description to this docstring
We are losing the information when we delete it from the setter
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.
@spacether I don't get your comment.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, my mistake, I missed the remaining bool type here. This is good.