URL: https://github.com/freeipa/freeipa/pull/2136 Author: tiran Title: #2136: [Backport][ipa-4-6] Fix pylint 2.0 return-related violations Action: opened
PR body: """ Manual backport of PR #2135 to 4.6 branch. Aiming to support pylint 2.0 some functions and methods must have their return statements updated in order to fix two new violations: - `useless-return` (R1711): Useless return at end of function or method Emitted when a single "return" or "return None" statement is found at the end of function or method definition. This statement can safely be removed because Python will implicitly return None - `inconsistent-return-statements` (R1710): Either all return statements in a function should return an expression, or none of them should. According to PEP8, if any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable) Issue: https://pagure.io/freeipa/issue/7614 Signed-off-by: Armando Neto <abiag...@redhat.com> """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/2136/head:pr2136 git checkout pr2136
From a073737ca7ea03adfa10d9e331ca61e962a56a59 Mon Sep 17 00:00:00 2001 From: Armando Neto <abiag...@redhat.com> Date: Tue, 10 Jul 2018 17:14:04 -0300 Subject: [PATCH] Fix pylint 2.0 return-related violations Aiming to support pylint 2.0 some functions and methods must have their return statements updated in order to fix two new violations: - `useless-return` (R1711): Useless return at end of function or method Emitted when a single "return" or "return None" statement is found at the end of function or method definition. This statement can safely be removed because Python will implicitly return None - `inconsistent-return-statements` (R1710): Either all return statements in a function should return an expression, or none of them should. According to PEP8, if any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable) Issue: https://pagure.io/freeipa/issue/7614 Signed-off-by: Armando Neto <abiag...@redhat.com> --- ipaclient/install/ipadiscovery.py | 1 + ipalib/frontend.py | 2 +- ipalib/parameters.py | 1 - ipaplatform/base/services.py | 20 ++++++++------------ ipapython/install/core.py | 5 ++--- ipaserver/dcerpc.py | 3 ++- ipaserver/dnssec/syncrepl.py | 1 + ipaserver/install/adtrust.py | 4 ++-- ipaserver/install/bindinstance.py | 1 + ipaserver/install/cainstance.py | 1 + ipaserver/install/ipa_cacert_manage.py | 2 ++ ipaserver/install/ipa_server_certinstall.py | 1 + ipaserver/install/krbinstance.py | 2 +- ipaserver/install/ldapupdate.py | 2 +- ipaserver/install/server/upgrade.py | 1 + ipaserver/install/service.py | 2 +- ipaserver/p11helper.py | 1 + ipaserver/plugins/aci.py | 1 + ipaserver/plugins/baseldap.py | 1 + ipaserver/plugins/config.py | 4 ++-- ipaserver/plugins/dns.py | 18 +++++++++++------- ipaserver/plugins/dogtag.py | 2 +- ipaserver/plugins/hbacrule.py | 3 +-- ipaserver/plugins/permission.py | 4 ++++ ipaserver/plugins/realmdomains.py | 1 + ipaserver/plugins/selinuxusermap.py | 2 -- ipaserver/rpcserver.py | 8 ++++---- ipaserver/secrets/client.py | 2 ++ 28 files changed, 55 insertions(+), 41 deletions(-) diff --git a/ipaclient/install/ipadiscovery.py b/ipaclient/install/ipadiscovery.py index a8283d8e6a..4800325575 100644 --- a/ipaclient/install/ipadiscovery.py +++ b/ipaclient/install/ipadiscovery.py @@ -549,6 +549,7 @@ def ipadnssearchkrbrealm(self, domain=None): continue if realm: return realm + return None def ipadnssearchkrbkdc(self, domain=None): kdc = None diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 5fc24427b8..b6e6147237 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -1155,7 +1155,7 @@ def register_interactive_prompt_callback(cls, callback, first=False): cls.register_callback('interactive_prompt', callback, first) def interactive_prompt_callback(self, kw): - return + pass class LocalOrRemote(Command): diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 62d555129b..5c8f94fe11 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -2005,7 +2005,6 @@ def _rule_required(self, _, value): raise ValidationError( name=self.get_param_name(), error=ugettext('incomplete time value') ) - return None class DNParam(Param): diff --git a/ipaplatform/base/services.py b/ipaplatform/base/services.py index 2cdee6c5a6..29b92e7ffa 100644 --- a/ipaplatform/base/services.py +++ b/ipaplatform/base/services.py @@ -140,8 +140,6 @@ def start(self, instance_name="", capture_output=True, wait=True, with open(paths.SVC_LIST_FILE, 'w') as f: json.dump(svc_list, f) - return - def stop(self, instance_name="", capture_output=True, update_service_list=True): """ @@ -163,14 +161,12 @@ def stop(self, instance_name="", capture_output=True, with open(paths.SVC_LIST_FILE, 'w') as f: json.dump(svc_list, f) - return - def reload_or_restart(self, instance_name="", capture_output=True, wait=True): - return + pass def restart(self, instance_name="", capture_output=True, wait=True): - return + pass def is_running(self, instance_name="", wait=True): return False @@ -185,22 +181,22 @@ def is_masked(self, instance_name=""): return False def enable(self, instance_name=""): - return + pass def disable(self, instance_name=""): - return + pass def mask(self, instance_name=""): - return + pass def unmask(self, instance_name=""): - return + pass def install(self, instance_name=""): - return + pass def remove(self, instance_name=""): - return + pass class SystemdService(PlatformService): diff --git a/ipapython/install/core.py b/ipapython/install/core.py index 2ed41f63e2..d8e04f1b17 100644 --- a/ipapython/install/core.py +++ b/ipapython/install/core.py @@ -275,8 +275,6 @@ def knobs(cls): def group(cls): assert not hasattr(super(Configurable, cls), 'group') - return None - def __init__(self, **kwargs): """ Initialize the configurable. @@ -339,7 +337,7 @@ def _get_components(self): raise TypeError("{0} is not composite".format(self)) def _get_fallback(self): - return None + pass @abc.abstractmethod def _configure(self): @@ -362,6 +360,7 @@ def run(self): self.validate() if self.__state == _EXECUTE_PENDING: return self.execute() + return None def validate(self): """ diff --git a/ipaserver/dcerpc.py b/ipaserver/dcerpc.py index fea58886cd..cb4a2a67a0 100644 --- a/ipaserver/dcerpc.py +++ b/ipaserver/dcerpc.py @@ -749,6 +749,7 @@ def __search_in_dc(self, info, host, port, filter, attrs, scope, logger.warning('%s', msg) return entries + return None def __retrieve_trusted_domain_gc_list(self, domain): """ @@ -1051,7 +1052,7 @@ def generate_ftinfo(self, another_domain): Only top level name and top level name exclusions are handled here. """ if not another_domain.ftinfo_records: - return + return None ftinfo_records = [] info = lsa.ForestTrustInformation() diff --git a/ipaserver/dnssec/syncrepl.py b/ipaserver/dnssec/syncrepl.py index f23bf97ef8..67305b7f7b 100644 --- a/ipaserver/dnssec/syncrepl.py +++ b/ipaserver/dnssec/syncrepl.py @@ -42,6 +42,7 @@ def syncrepl_get_cookie(self): return cookie else: logger.debug('Current cookie is: None (not received yet)') + return None def syncrepl_set_cookie(self, cookie): logger.debug('New cookie is: %s', cookie) diff --git a/ipaserver/install/adtrust.py b/ipaserver/install/adtrust.py index f4a0b0c1c6..f4496adb0e 100644 --- a/ipaserver/install/adtrust.py +++ b/ipaserver/install/adtrust.py @@ -262,7 +262,7 @@ def retrieve_potential_adtrust_agents(api): except (errors.DatabaseError, errors.NetworkError) as e: logger.error( "Could not retrieve a list of existing IPA masters: %s", e) - return + return None try: # search for existing AD trust agents @@ -270,7 +270,7 @@ def retrieve_potential_adtrust_agents(api): servrole=u'AD trust agent', all=True)['result'] except (errors.DatabaseError, errors.NetworkError) as e: logger.error("Could not retrieve a list of adtrust agents: %s", e) - return + return None dl_enabled_master_cns = {m['cn'][0] for m in dl_enabled_masters} adtrust_agents_cns = {m['cn'][0] for m in adtrust_agents} diff --git a/ipaserver/install/bindinstance.py b/ipaserver/install/bindinstance.py index 7c858aab44..5e77a1c66c 100644 --- a/ipaserver/install/bindinstance.py +++ b/ipaserver/install/bindinstance.py @@ -137,6 +137,7 @@ def named_conf_get_directive(name, section=NAMED_SECTION_IPA, str_val=True): if match and name == match.group('name'): return match.group('value') + return None def named_conf_set_directive(name, value, section=NAMED_SECTION_IPA, str_val=True): diff --git a/ipaserver/install/cainstance.py b/ipaserver/install/cainstance.py index 34a7982b01..75e533a241 100644 --- a/ipaserver/install/cainstance.py +++ b/ipaserver/install/cainstance.py @@ -172,6 +172,7 @@ def find_substring(data, value): for d in data: if d.startswith(value): return get_value(d) + return None def get_defList(data): diff --git a/ipaserver/install/ipa_cacert_manage.py b/ipaserver/install/ipa_cacert_manage.py index 6f8b0baa4b..ebe3f3776d 100644 --- a/ipaserver/install/ipa_cacert_manage.py +++ b/ipaserver/install/ipa_cacert_manage.py @@ -126,6 +126,8 @@ def run(self): return self.renew() elif command == 'install': return self.install() + else: + raise NotImplementedError finally: api.Backend.ldap2.disconnect() diff --git a/ipaserver/install/ipa_server_certinstall.py b/ipaserver/install/ipa_server_certinstall.py index 584ca69c83..6bbf3f667e 100644 --- a/ipaserver/install/ipa_server_certinstall.py +++ b/ipaserver/install/ipa_server_certinstall.py @@ -225,6 +225,7 @@ def install_kdc_cert(self): profile='KDCs_PKINIT_Certs') except RuntimeError as e: raise admintool.ScriptError(str(e)) + return None krb = krbinstance.KrbInstance() krb.init_info( diff --git a/ipaserver/install/krbinstance.py b/ipaserver/install/krbinstance.py index a3079bd630..2f28deb86c 100644 --- a/ipaserver/install/krbinstance.py +++ b/ipaserver/install/krbinstance.py @@ -63,7 +63,7 @@ def get_pkinit_request_ca(): {'cert-file': paths.KDC_CERT}) if pkinit_request_id is None: - return + return None return certmonger.get_request_value(pkinit_request_id, 'ca-name') diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py index 15fa22a67d..ffa287476b 100644 --- a/ipaserver/install/ldapupdate.py +++ b/ipaserver/install/ldapupdate.py @@ -111,7 +111,7 @@ def safe_output(attr, values): return 'XXXXXXXX' if values is None: - return + return None is_list = type(values) in (tuple, list) diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py index 7faaacd5d2..0cc25fa6e5 100644 --- a/ipaserver/install/server/upgrade.py +++ b/ipaserver/install/server/upgrade.py @@ -1201,6 +1201,7 @@ def find_subject_base(): logger.error('Unable to determine certificate subject base. ' 'certmap.conf will not be updated.') + return None def uninstall_selfsign(ds, http): diff --git a/ipaserver/install/service.py b/ipaserver/install/service.py index 39dc49e872..baefc00769 100644 --- a/ipaserver/install/service.py +++ b/ipaserver/install/service.py @@ -320,7 +320,7 @@ def __init__(self, service_name, service_desc=None, sstore=None, def principal(self): if any(attr is None for attr in (self.realm, self.fqdn, self.service_prefix)): - return + return None return unicode( kerberos.Principal( diff --git a/ipaserver/p11helper.py b/ipaserver/p11helper.py index f0c2540752..c63a6a019d 100644 --- a/ipaserver/p11helper.py +++ b/ipaserver/p11helper.py @@ -929,6 +929,7 @@ def get_slot(self): if self.token_label == char_array_to_unicode( token_info_ptr[0].label, 32).rstrip(): return slot + return None def finalize(self): """ diff --git a/ipaserver/plugins/aci.py b/ipaserver/plugins/aci.py index bc766c38cc..743c73ddbf 100644 --- a/ipaserver/plugins/aci.py +++ b/ipaserver/plugins/aci.py @@ -411,6 +411,7 @@ def validate_permissions(ugettext, perm): perm = perm.strip().lower() if perm not in _valid_permissions_values: return '"%s" is not a valid permission' % perm + return None def _normalize_permissions(perm): diff --git a/ipaserver/plugins/baseldap.py b/ipaserver/plugins/baseldap.py index 2da4ea3a14..22764e69d9 100644 --- a/ipaserver/plugins/baseldap.py +++ b/ipaserver/plugins/baseldap.py @@ -319,6 +319,7 @@ def validate_externalhost(ugettext, hostname): validate_hostname(hostname, check_fqdn=False, allow_underscore=True) except ValueError as e: return unicode(e) + return None external_host_param = Str('externalhost*', validate_externalhost, diff --git a/ipaserver/plugins/config.py b/ipaserver/plugins/config.py index d367c3c5aa..60bea60fab 100644 --- a/ipaserver/plugins/config.py +++ b/ipaserver/plugins/config.py @@ -92,10 +92,10 @@ def validate_search_records_limit(ugettext, value): Values 0 and -1 are valid, as they represent unlimited. """ if value in {-1, 0}: - return + return None if value < 10: return _('must be at least 10') - + return None @register() class config(LDAPObject): diff --git a/ipaserver/plugins/dns.py b/ipaserver/plugins/dns.py index 016be0c6f1..3c006c5701 100644 --- a/ipaserver/plugins/dns.py +++ b/ipaserver/plugins/dns.py @@ -401,7 +401,7 @@ def _validate_ipnet(ugettext, ipnet): def _validate_bind_aci(ugettext, bind_acis): if not bind_acis: - return + return None bind_acis = bind_acis.split(';') if bind_acis[-1]: @@ -422,10 +422,11 @@ def _validate_bind_aci(ugettext, bind_acis): return unicode(e) except UnboundLocalError: return _(u"invalid address format") + return None def _normalize_bind_aci(bind_acis): if not bind_acis: - return + return None bind_acis = bind_acis.split(';') normalized = [] for bind_aci in bind_acis: @@ -729,7 +730,7 @@ def get_parts_from_kw(self, kw, raise_on_none=True): vals = tuple(kw.get(part_name) for part_name in part_names) if all(val is None for val in vals): - return + return None if raise_on_none: for val_id,val in enumerate(vals): @@ -789,17 +790,17 @@ def _normalize_parts(self, value): def _rule_validatedns(self, _, value): if not self.validatedns: - return + return None if value is None: - return + return None if not self.supported: return _('DNS RR type "%s" is not supported by bind-dyndb-ldap plugin') \ % self.rrtype if self.parts is None: - return + return None # validate record format values = self._get_part_values(value) @@ -1282,6 +1283,8 @@ def _validate_naptr_flags(ugettext, flags): for flag in flags: if flag not in allowed_flags: return _('flags must be one of "S", "A", "U", or "P"') + return None + class NAPTRRecord(DNSRecord): rrtype = 'NAPTR' @@ -1370,6 +1373,7 @@ def _sig_time_validator(ugettext, value): time.strptime(value, time_format) except ValueError: return _('the value does not follow "YYYYMMDDHHMMSS" time format') + return None class SIGRecord(UnsupportedDNSRecord): @@ -1460,7 +1464,7 @@ def _normalize_uri_target(uri_target): # RFC 7553 section 4.4: The Target MUST NOT be an empty URI (""). # minlength in param will detect this if not uri_target: - return + return None return u'"{0}"'.format(uri_target) diff --git a/ipaserver/plugins/dogtag.py b/ipaserver/plugins/dogtag.py index b6c9edc382..3d2c53fbc9 100644 --- a/ipaserver/plugins/dogtag.py +++ b/ipaserver/plugins/dogtag.py @@ -1284,7 +1284,7 @@ def ca_host(self): def __enter__(self): """Log into the REST API""" if self.cookie is not None: - return + return None # Refresh the ca_host property object.__setattr__(self, '_ca_host', None) diff --git a/ipaserver/plugins/hbacrule.py b/ipaserver/plugins/hbacrule.py index 5b77a6c79d..2579ebc2bb 100644 --- a/ipaserver/plugins/hbacrule.py +++ b/ipaserver/plugins/hbacrule.py @@ -118,8 +118,7 @@ def is_all(options, attribute): value = options[attribute].lower() if value == 'all': return True - else: - return False + return False @register() diff --git a/ipaserver/plugins/permission.py b/ipaserver/plugins/permission.py index 30f8663c9f..023ecf74fb 100644 --- a/ipaserver/plugins/permission.py +++ b/ipaserver/plugins/permission.py @@ -127,6 +127,7 @@ def strip_ldap_prefix(uri): def prevalidate_filter(ugettext, value): if not value.startswith('(') or not value.endswith(')'): return _('must be enclosed in parentheses') + return None class DNOrURL(DNParam): @@ -148,6 +149,7 @@ def validate_type(ugettext, typestr): return _('"%s" is not an object type') % typestr if not getattr(obj, 'permission_filter_objectclasses', None): return _('"%s" is not a valid permission type') % typestr + return None def _disallow_colon(option): @@ -904,6 +906,8 @@ def preprocess_options(self, options, options['ipapermtargetfilter'] = list(options.get( 'ipapermtargetfilter') or []) + filter_ops['add'] + return None + def validate_permission(self, entry): ldap = self.Backend.ldap2 diff --git a/ipaserver/plugins/realmdomains.py b/ipaserver/plugins/realmdomains.py index 13631e47cc..80c5c29837 100644 --- a/ipaserver/plugins/realmdomains.py +++ b/ipaserver/plugins/realmdomains.py @@ -62,6 +62,7 @@ def _domain_name_validator(ugettext, value): validate_domain_name(value, allow_slash=False) except ValueError as e: return unicode(e) + return None @register() diff --git a/ipaserver/plugins/selinuxusermap.py b/ipaserver/plugins/selinuxusermap.py index 2886f35360..fcbaaf14e0 100644 --- a/ipaserver/plugins/selinuxusermap.py +++ b/ipaserver/plugins/selinuxusermap.py @@ -140,8 +140,6 @@ def validate_selinuxuser_inlist(ldap, user): reason=_('SELinux user %(user)s not found in ' 'ordering list (in config)') % dict(user=user)) - return - @register() class selinuxusermap(LDAPObject): diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py index 69aac69f94..3c831a5588 100644 --- a/ipaserver/rpcserver.py +++ b/ipaserver/rpcserver.py @@ -196,7 +196,7 @@ def read_input(environ): try: length = int(environ.get('CONTENT_LENGTH')) except (ValueError, TypeError): - return + return None return environ['wsgi.input'].read(length).decode('utf-8') @@ -613,13 +613,13 @@ def get_environ_creds(self, environ): ccache_name = environ.get('KRB5CCNAME') if ccache_name is None: logger.debug('no ccache, need login') - return + return None # ... make sure we have a name ... principal = environ.get('GSS_NAME') if principal is None: logger.debug('no Principal Name, need login') - return + return None # ... and use it to resolve the ccache name (Issue: 6972 ) gss_name = gssapi.Name(principal, gssapi.NameType.kerberos_principal) @@ -630,7 +630,7 @@ def get_environ_creds(self, environ): if not creds: logger.debug( 'ccache expired or invalid, deleting session, need login') - return + return None return ccache_name diff --git a/ipaserver/secrets/client.py b/ipaserver/secrets/client.py index 83402bd236..16e7856185 100644 --- a/ipaserver/secrets/client.py +++ b/ipaserver/secrets/client.py @@ -114,3 +114,5 @@ def fetch_key(self, keyname, store=True): self.keystore.set('keys/%s' % keyname, value) else: return value + + return None
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/freeipa-devel@lists.fedorahosted.org/message/TX7RWEIS7KAYWT5VAEIG2LMYBUYGVKMN/