From 24c42133f8b172a784e3bc8d61f73b15fb4f80f6 Mon Sep 17 00:00:00 2001 From: Eric Barrett Date: Mon, 15 Apr 2019 17:06:14 -0400 Subject: [PATCH] Fix Flake8 Bugbear Errors Flake8 is failing due to bugbear updating with new error codes: B009: Do not call getattr with a constant attribute value B010: Do not call setattr with a constant attribute value Fix these errors by using normal property access instead Change-Id: Ib857d229ae86e88cb5dbf69e826b25d6018c8547 Signed-off-by: Eric Barrett --- .../sm_api/openstack/common/db/sqlalchemy/session.py | 2 +- service-mgmt-client/sm-client/sm_client/client.py | 2 +- .../sm-client/sm_client/v1/smc_service_shell.py | 10 +++++----- .../sm-client/sm_client/v1/smc_servicegroup_shell.py | 8 ++++---- tox.ini | 4 +--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/session.py b/service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/session.py index cd0f2008..3f4bbd6d 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/session.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/db/sqlalchemy/session.py @@ -698,4 +698,4 @@ def _patch_mysqldb_with_stacktrace_comments(): qq = q old_mysql_do_query(self, qq) - setattr(MySQLdb.cursors.BaseCursor, '_do_query', _do_query) + MySQLdb.cursors.BaseCursor._do_query = _do_query diff --git a/service-mgmt-client/sm-client/sm_client/client.py b/service-mgmt-client/sm-client/sm_client/client.py index 7bba06d0..2cd65c20 100644 --- a/service-mgmt-client/sm-client/sm_client/client.py +++ b/service-mgmt-client/sm-client/sm_client/client.py @@ -108,5 +108,5 @@ def get_client(api_version, **kwargs): def Client(version, *args, **kwargs): module = utils.import_versioned_module(version, 'client') - client_class = getattr(module, 'Client') + client_class = module.Client return client_class(*args, **kwargs) diff --git a/service-mgmt-client/sm-client/sm_client/v1/smc_service_shell.py b/service-mgmt-client/sm-client/sm_client/v1/smc_service_shell.py index e47aaa9b..a3c82bf6 100644 --- a/service-mgmt-client/sm-client/sm_client/v1/smc_service_shell.py +++ b/service-mgmt-client/sm-client/sm_client/v1/smc_service_shell.py @@ -34,9 +34,9 @@ def do_service_list(cc, args): clean_list = [x for x in service if x.state != 'initial'] for s in clean_list: if s.status: - setattr(s, 'state', s.state + '-' + s.status) + s.state = (s.state + '-' + s.status) if getattr(s, 'node_name', None) is None: - setattr(s, 'node_name', socket.gethostname()) + s.node_name = socket.gethostname() utils.print_list(clean_list, fields, field_labels, sortby=1) @@ -56,8 +56,8 @@ def do_service_show(cc, args): print("Service %s could not be found" % args.service) return if service.status: - setattr(service, 'state', service.state + '-' + service.status) - setattr(service, 'service_name', service.name) + service.state = (service.state + '-' + service.status) + service.service_name = service.name if getattr(service, 'node_name', None) is None: - setattr(service, 'hostname', socket.gethostname()) + service.hostname = socket.gethostname() _print_service_show(service) diff --git a/service-mgmt-client/sm-client/sm_client/v1/smc_servicegroup_shell.py b/service-mgmt-client/sm-client/sm_client/v1/smc_servicegroup_shell.py index b8dedd90..44e9702d 100644 --- a/service-mgmt-client/sm-client/sm_client/v1/smc_servicegroup_shell.py +++ b/service-mgmt-client/sm-client/sm_client/v1/smc_servicegroup_shell.py @@ -28,7 +28,7 @@ def do_servicegroup_list(cc, args): field_labels = ['uuid', 'service_group_name', 'hostname', 'state'] for s in servicegroup: if s.status: - setattr(s, 'state', s.state + '-' + s.status) + s.state = (s.state + '-' + s.status) utils.print_list(servicegroup, fields, field_labels, sortby=1) @@ -48,7 +48,7 @@ def do_servicegroup_show(cc, args): print("Service group %s could not be found" % args.servicegroup) return if servicegroup.status: - setattr(servicegroup, 'state', servicegroup.state + '-' + - servicegroup.status) - setattr(servicegroup, 'hostname', servicegroup.node_name) + servicegroup.state = (servicegroup.state + '-' + + servicegroup.status) + servicegroup.hostname = servicegroup.node_name _print_servicegroup_show(servicegroup) diff --git a/tox.ini b/tox.ini index a1c8139f..43a8f211 100644 --- a/tox.ini +++ b/tox.ini @@ -71,12 +71,10 @@ commands = # F821 undefined name 'e' # - bugbear - # B008 Do not perform calls in argument defaults. The call is performed only once at function definition time. -# B009: Do not call getattr with a constant attribute value -# B010: Do not call setattr with a constant attribute value ignore= E402, H102,H104,H105,H106,H306,H401,H403,H404,H405,H501, F811,F821, - B008,B009,B010 + B008 # Enable checks which are off by default # H106 Don’t put vim configuration in source files (off by default). SHOULD BE ENABLED. # H203 Use assertIs(Not)None to check for None (off by default).