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 <eric.barrett@windriver.com>
This commit is contained in:
Eric Barrett 2019-04-15 17:06:14 -04:00
parent 687ed8c747
commit 24c42133f8
5 changed files with 12 additions and 14 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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 Dont put vim configuration in source files (off by default). SHOULD BE ENABLED.
# H203 Use assertIs(Not)None to check for None (off by default).