Refactor PyLint "inconsistent-return-statements"

This commit is contained in:
Ivan Kravets
2017-12-15 22:16:37 +02:00
parent bff590e207
commit 42fb589369
14 changed files with 48 additions and 24 deletions

View File

@ -198,12 +198,12 @@ class ContentCache(object):
def set(self, key, data, valid):
if not get_setting("enable_cache"):
return
return False
cache_path = self.get_cache_path(key)
if isfile(cache_path):
self.delete(key)
if not data:
return
return False
if not isdir(self.cache_dir):
os.makedirs(self.cache_dir)
tdmap = {"s": 1, "m": 60, "h": 3600, "d": 86400}
@ -228,7 +228,7 @@ class ContentCache(object):
def delete(self, keys=None):
""" Keys=None, delete expired items """
if not isfile(self._db_path):
return
return None
if not keys:
keys = []
if not isinstance(keys, list):

View File

@ -693,7 +693,7 @@ def GetLibBuilders(env): # pylint: disable=too-many-branches
if lb.name in env.get("LIB_IGNORE", []):
if verbose:
sys.stderr.write("Ignored library %s\n" % lb.path)
return
return None
if compat_mode > 1 and not lb.is_platforms_compatible(
env['PIOPLATFORM']):
if verbose:

View File

@ -50,7 +50,7 @@ class InoToCPPConverter(object):
def convert(self, nodes):
contents = self.merge(nodes)
if not contents:
return
return None
return self.process(contents)
def merge(self, nodes):

View File

@ -72,7 +72,7 @@ def exists(_):
def generate(env):
if system() != "Windows":
return
return None
env.Replace(_long_sources_hook=long_sources_hook)
env.Replace(_long_incflags_hook=long_incflags_hook)

View File

@ -42,6 +42,7 @@ def cli(query, installed, json_output): # pylint: disable=R0912
click.secho(platform, bold=True)
click.echo("-" * terminal_width)
print_boards(boards)
return True
def print_boards(boards):

View File

@ -30,10 +30,8 @@ def cli():
@cli.command("list", short_help="List devices")
@click.option("--json-output", is_flag=True)
def device_list(json_output):
if json_output:
click.echo(json.dumps(util.get_serialports()))
return
return click.echo(json.dumps(util.get_serialports()))
for item in util.get_serialports():
click.secho(item['port'], fg="cyan")
@ -42,6 +40,8 @@ def device_list(json_output):
click.echo("Description: %s" % item['description'])
click.echo("")
return True
@cli.command("monitor", short_help="Monitor device (Serial)")
@click.option("--port", "-p", help="Port, a number or a device name")
@ -154,7 +154,7 @@ def device_monitor(**kwargs): # pylint: disable=too-many-branches
def get_project_options(project_dir, environment):
config = util.load_project_config(project_dir)
if not config.sections():
return
return None
known_envs = [s[4:] for s in config.sections() if s.startswith("env:")]
if environment:
@ -163,7 +163,7 @@ def get_project_options(project_dir, environment):
raise exception.UnknownEnvNames(environment, ", ".join(known_envs))
if not known_envs:
return
return None
if config.has_option("platformio", "env_default"):
env_default = config.get("platformio",

View File

@ -143,6 +143,8 @@ def lib_update(lm, libraries, only_check, json_output):
for library in libraries:
lm.update(library, only_check=only_check)
return True
def print_lib_item(item):
click.secho(item['name'], fg="cyan")
@ -265,11 +267,13 @@ def lib_list(lm, json_output):
return click.echo(json.dumps(items))
if not items:
return
return None
for item in sorted(items, key=lambda i: i['name']):
print_lib_item(item)
return True
@util.memoized
def get_builtin_libs(storage_names=None):
@ -308,6 +312,8 @@ def lib_builtin(storage, json_output):
for item in sorted(storage_['items'], key=lambda i: i['name']):
print_lib_item(item)
return True
@cli.command("show", short_help="Show detailed info about a library")
@click.argument("library", metavar="[LIBRARY]")
@ -381,6 +387,8 @@ def lib_show(library, json_output):
for row in rows:
click.echo(row)
return True
@cli.command("register", short_help="Register a new library")
@click.argument("config_url")
@ -468,3 +476,5 @@ def lib_stats(json_output):
for item in result.get(key, []):
_print_lib_item(item)
click.echo()
return True

View File

@ -257,7 +257,7 @@ def platform_show(platform, json_output): # pylint: disable=too-many-branches
click.echo("Frameworks: %s" % ", ".join(data['frameworks']))
if not data['packages']:
return
return None
if not isinstance(data['packages'][0], dict):
click.echo("Packages: %s" % ", ".join(data['packages']))
@ -287,6 +287,8 @@ def platform_show(platform, json_output): # pylint: disable=too-many-branches
click.echo("------")
print_boards(data['boards'])
return True
@cli.command("install", short_help="Install new development platform")
@click.argument("platforms", nargs=-1, required=True, metavar="[PLATFORM...]")
@ -375,3 +377,5 @@ def platform_update(platforms, only_packages, only_check, json_output):
pm.update(
platform, only_packages=only_packages, only_check=only_check)
click.echo()
return True

View File

@ -93,6 +93,8 @@ WARNING! Don't use `sudo` for the rest PlatformIO commands.
raise exception.UpgradeError("\n".join(
[str(cmd), r['out'], r['err']]))
return True
def get_latest_version():
try:

View File

@ -42,7 +42,12 @@ class CorePackageManager(PackageManager):
("" if sys.version_info < (2, 7, 9) else "s")
])
def install(self, name, requirements=None, *args, **kwargs):
def install( # pylint: disable=keyword-arg-before-vararg
self,
name,
requirements=None,
*args,
**kwargs):
PackageManager.install(self, name, requirements, *args, **kwargs)
self.cleanup_packages()
return self.get_package_dir(name, requirements)
@ -126,3 +131,5 @@ def pioplus_call(args, **kwargs):
if code != 0:
raise exception.ReturnErrorCode(1)
return True

View File

@ -256,10 +256,10 @@ class LibraryManager(BasePkgManager):
except exception.InternetIsOffline as e:
if not silent:
click.secho(str(e), fg="yellow")
return
return None
if not pkg_dir:
return
return None
manifest = self.load_manifest(pkg_dir)
if "dependencies" not in manifest:

View File

@ -384,7 +384,7 @@ class PkgInstallerMixin(object):
finally:
if isdir(tmp_dir):
util.rmtree_(tmp_dir)
return
return None
def _update_src_manifest(self, data, src_dir):
if not isdir(src_dir):
@ -603,18 +603,17 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin):
requirements=None,
silent=False,
trigger_event=True):
name, requirements, url = self.parse_pkg_uri(name, requirements)
package_dir = self.get_package_dir(name, requirements, url)
# avoid circle dependencies
if not self.INSTALL_HISTORY:
self.INSTALL_HISTORY = []
history_key = "%s-%s" % (name, requirements) if requirements else name
if history_key in self.INSTALL_HISTORY:
return
return package_dir
self.INSTALL_HISTORY.append(history_key)
name, requirements, url = self.parse_pkg_uri(name, requirements)
package_dir = self.get_package_dir(name, requirements, url)
if not package_dir or not silent:
msg = "Installing " + click.style(name, fg="cyan")
if requirements:
@ -714,7 +713,7 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin):
nl=False)
if not util.internet_on():
click.echo("[%s]" % (click.style("Off-line", fg="yellow")))
return
return None
latest = self.outdated(pkg_dir, requirements)
if latest:
@ -725,7 +724,7 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin):
click.echo("[%s]" % (click.style("Fixed", fg="yellow")))
if only_check or not latest:
return
return True
if "__src_url" in manifest:
vcs = VCSClientFactory.newClient(pkg_dir, manifest['__src_url'])

View File

@ -672,7 +672,7 @@ class PlatformBoardConfig(object):
def get_debug_data(self):
if not self._manifest.get("debug", {}).get("tools"):
return
return None
tools = {}
for name, options in self._manifest['debug']['tools'].items():
tools[name] = {}

View File

@ -407,3 +407,4 @@ def resend_backuped_reports():
# clean
tm['backup'] = []
app.set_state_item("telemetry", tm)
return True