Skip to content
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

{Pylint} Fix arguments-renamed #30345

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ disable=
consider-using-f-string,
unspecified-encoding,
use-maxsplit-arg,
arguments-renamed,
consider-using-in,
consider-using-dict-items,
consider-using-enumerate,
Expand Down
9 changes: 4 additions & 5 deletions src/azure-cli-core/azure/cli/core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,14 +1291,13 @@ def _flatten_kwargs(self, kwargs, default_source_name):
return arg_source_copy
return merged_kwargs

# pylint: disable=arguments-differ
def command(self, name, method_name=None, **kwargs):
def command(self, name, handler_name=None, **kwargs):
"""
Register a CLI command.
:param name: Name of the command as it will be called on the command line
:type name: str
:param method_name: Name of the method the command maps to
:type method_name: str
:param handler_name: Name of the method the command maps to
:type handler_name: str
:param kwargs: Keyword arguments. Supported keyword arguments include:
- client_factory: Callable which returns a client needed to access the underlying command method. (function)
- confirmation: Prompt prior to the action being executed. This is useful if the action
Expand All @@ -1315,7 +1314,7 @@ def command(self, name, method_name=None, **kwargs):
- max_api: Maximum API version required for commands within the group (string)
:rtype: None
"""
return self._command(name, method_name=method_name, **kwargs)
return self._command(name, method_name=handler_name, **kwargs)

def custom_command(self, name, method_name=None, **kwargs):
"""
Expand Down
31 changes: 16 additions & 15 deletions src/azure-cli-core/azure/cli/core/commands/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ def _ignore_if_not_registered(self, dest):
if not match:
super().argument(dest, arg_type=ignore_type)

# pylint: disable=arguments-differ
Copy link
Member Author

@jiasli jiasli Dec 4, 2024

Choose a reason for hiding this comment

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

Putting # pylint: disable=arguments-differ here is incorrect as it disables all arguments-differs below, including ignore(), not only for argument().

def argument(self, dest, arg_type=None, **kwargs):
def argument(self, argument_dest, arg_type=None, **kwargs):
self._check_stale()
if not self._applicable():
return
Expand All @@ -384,11 +383,11 @@ def argument(self, dest, arg_type=None, **kwargs):
min_api=min_api,
max_api=max_api,
operation_group=operation_group):
super().argument(dest, **merged_kwargs)
super().argument(argument_dest, **merged_kwargs)
else:
self._ignore_if_not_registered(dest)
self._ignore_if_not_registered(argument_dest)

def positional(self, dest, arg_type=None, **kwargs):
def positional(self, argument_dest, arg_type=None, **kwargs):
self._check_stale()
if not self._applicable():
return
Expand All @@ -405,9 +404,9 @@ def positional(self, dest, arg_type=None, **kwargs):
min_api=min_api,
max_api=max_api,
operation_group=operation_group):
super().positional(dest, **merged_kwargs)
super().positional(argument_dest, **merged_kwargs)
else:
self._ignore_if_not_registered(dest)
self._ignore_if_not_registered(argument_dest)

def expand(self, dest, model_type, group_name=None, patches=None):
# TODO:
Expand Down Expand Up @@ -467,15 +466,17 @@ def _expansion_validator_impl(namespace):
options_list=dest_option,
validator=get_complex_argument_processor(expanded_arguments, dest, model_type))

def ignore(self, *args):
def ignore(self, *args): # pylint: disable=arguments-differ
# It is expected that this method's signature differs from its base class, as it can be used to ignore
# multiple arguments in one method call.
Comment on lines +469 to +471
Copy link
Member Author

Choose a reason for hiding this comment

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

Some examples:

c.ignore('source_virtual_machine', 'os_blob_uri', 'os_disk', 'os_snapshot', 'data_blob_uris', 'data_disks', 'data_snapshots')

c.ignore('ignore_this', 'ignore_that')

self._check_stale()
if not self._applicable():
return

for arg in args:
super().ignore(arg)

def extra(self, dest, arg_type=None, **kwargs):
def extra(self, argument_dest, arg_type=None, **kwargs):

merged_kwargs = self._flatten_kwargs(kwargs, arg_type)
resource_type = merged_kwargs.get('resource_type', None)
Expand All @@ -487,8 +488,8 @@ def extra(self, dest, arg_type=None, **kwargs):
max_api=max_api,
operation_group=operation_group):
# Restore when knack #132 is fixed
# merged_kwargs.pop('dest', None)
# super(AzArgumentContext, self).extra(dest, **merged_kwargs)
# merged_kwargs.pop('argument_dest', None)
# super(AzArgumentContext, self).extra(argument_dest, **merged_kwargs)
from knack.arguments import CLICommandArgument
self._check_stale()
if not self._applicable():
Expand All @@ -497,11 +498,11 @@ def extra(self, dest, arg_type=None, **kwargs):
if self.command_scope in self.command_loader.command_group_table:
raise ValueError("command authoring error: extra argument '{}' cannot be registered to a group-level "
"scope '{}'. It must be registered to a specific command.".format(
dest, self.command_scope))
argument_dest, self.command_scope))

deprecate_action = self._handle_deprecations(dest, **merged_kwargs)
deprecate_action = self._handle_deprecations(argument_dest, **merged_kwargs)
if deprecate_action:
merged_kwargs['action'] = deprecate_action
merged_kwargs.pop('dest', None)
self.command_loader.extra_argument_registry[self.command_scope][dest] = CLICommandArgument(
dest, **merged_kwargs)
self.command_loader.extra_argument_registry[self.command_scope][argument_dest] = CLICommandArgument(
argument_dest, **merged_kwargs)
22 changes: 11 additions & 11 deletions src/azure-cli/azure/cli/command_modules/ams/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ class JsonBytearrayEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"

def default(self, obj): # pylint: disable=E0202,W0221
Copy link
Member Author

Choose a reason for hiding this comment

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

if isinstance(obj, datetime):
return obj.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))
def default(self, o): # pylint: disable=E0202
if isinstance(o, datetime):
return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))

if isinstance(obj, bytearray):
return bytes(obj).decode('utf-8', 'ignore')
if isinstance(o, bytearray):
return bytes(o).decode('utf-8', 'ignore')

try:
return obj.toJSON()
return o.toJSON()
except Exception: # pylint: disable=W0703
obj = vars(obj)
obj.pop('additional_properties', None)
keys = list(obj.keys())
o = vars(o)
o.pop('additional_properties', None)
keys = list(o.keys())
for key in keys:
obj[snake_to_camel_case(key)] = obj.pop(key)
return obj
o[snake_to_camel_case(key)] = o.pop(key)
return o


def create_ip_range(resource_name, ip):
Expand Down