3
0
Fork 0

fix: fix 'inconsistent-return-statements' for pylint

This commit is contained in:
Lance Edgar 2025-08-31 19:44:18 -05:00
parent 45a6c107b0
commit 4e9f7bf479
16 changed files with 67 additions and 23 deletions

6
.pylintrc Normal file
View file

@ -0,0 +1,6 @@
# -*- mode: conf; -*-
[MESSAGES CONTROL]
disable=all
enable=
inconsistent-return-statements,

View file

@ -52,7 +52,7 @@ dependencies = [
[project.optional-dependencies] [project.optional-dependencies]
continuum = ["Wutta-Continuum"] continuum = ["Wutta-Continuum"]
docs = ["Sphinx", "furo", "sphinxcontrib-programoutput"] docs = ["Sphinx", "furo", "sphinxcontrib-programoutput"]
tests = ["pytest-cov", "tox"] tests = ["pylint", "pytest", "pytest-cov", "tox"]
[project.entry-points."fanstatic.libraries"] [project.entry-points."fanstatic.libraries"]

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -115,12 +115,12 @@ class WuttaSecurityPolicy:
# fetch user uuid from current session # fetch user uuid from current session
uuid = self.session_helper.authenticated_userid(request) uuid = self.session_helper.authenticated_userid(request)
if not uuid: if not uuid:
return return None
# fetch user object from db # fetch user object from db
user = self.db_session.get(model.User, uuid) user = self.db_session.get(model.User, uuid)
if not user: if not user:
return return None
return user return user
@ -131,6 +131,7 @@ class WuttaSecurityPolicy:
user = self.identity(request) user = self.identity(request)
if user is not None: if user is not None:
return user.uuid return user.uuid
return None
def remember(self, request, userid, **kw): def remember(self, request, userid, **kw):
return self.session_helper.remember(request, userid, **kw) return self.session_helper.remember(request, userid, **kw)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -48,9 +48,11 @@ else:
request = get_current_request() request = get_current_request()
if request: if request:
return request.client_addr return request.client_addr
return None
def get_user_id(self, uow, session): def get_user_id(self, uow, session):
""" """ """ """
request = get_current_request() request = get_current_request()
if request and request.user: if request and request.user:
return request.user.uuid return request.user.uuid
return None

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -537,6 +537,8 @@ class Form:
if widget_type == "notes": if widget_type == "notes":
return widgets.NotesWidget(**kwargs) return widgets.NotesWidget(**kwargs)
return None
def set_default_widgets(self): def set_default_widgets(self):
""" """
Set default field widgets, where applicable. Set default field widgets, where applicable.
@ -1147,11 +1149,11 @@ class Form:
def get_vue_field_value(self, key): def get_vue_field_value(self, key):
""" """ """ """
if key not in self.fields: if key not in self.fields:
return return None
dform = self.get_deform() dform = self.get_deform()
if key not in dform: if key not in dform:
return return None
field = dform[key] field = dform[key]
return make_json_safe(field.cstruct) return make_json_safe(field.cstruct)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -49,7 +49,9 @@ class WuttaDateTime(colander.DateTime):
the Buefy datepicker + timepicker widgets. the Buefy datepicker + timepicker widgets.
""" """
def deserialize(self, node, cstruct): def deserialize( # pylint: disable=inconsistent-return-statements
self, node, cstruct
):
""" """ """ """
if not cstruct: if not cstruct:
return colander.null return colander.null
@ -376,7 +378,7 @@ class ObjectRef(colander.SchemaType):
``colander.Invalid``. ``colander.Invalid``.
""" """
if not value: if not value:
return return None
if isinstance(value, self.model_class): if isinstance(value, self.model_class):
return value return value

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -2280,6 +2280,8 @@ class Grid:
sorter = self.sort_defaults[0] sorter = self.sort_defaults[0]
return [sorter.sortkey, sorter.sortdir] return [sorter.sortkey, sorter.sortdir]
return None
def get_vue_filters(self): def get_vue_filters(self):
""" """
Returns a list of Vue-compatible filter definitions. Returns a list of Vue-compatible filter definitions.
@ -2422,6 +2424,7 @@ class Grid:
if callable(self.row_class): if callable(self.row_class):
return self.row_class(obj, data, i) return self.row_class(obj, data, i)
return self.row_class return self.row_class
return None
def get_vue_pager_stats(self): def get_vue_pager_stats(self):
""" """

View file

@ -516,6 +516,7 @@ class StringAlchemyFilter(AlchemyFilter):
value = str(value) value = str(value)
if value: if value:
return value return value
return None
def filter_contains(self, query, value): def filter_contains(self, query, value):
""" """
@ -583,6 +584,7 @@ class IntegerAlchemyFilter(NumericAlchemyFilter):
return int(value) return int(value)
except: except:
pass pass
return None
class BooleanAlchemyFilter(AlchemyFilter): class BooleanAlchemyFilter(AlchemyFilter):
@ -619,6 +621,7 @@ class BooleanAlchemyFilter(AlchemyFilter):
""" """ """ """
if value is not None: if value is not None:
return bool(value) return bool(value)
return None
def filter_is_true(self, query, value): def filter_is_true(self, query, value):
""" """
@ -686,6 +689,8 @@ class DateAlchemyFilter(AlchemyFilter):
else: else:
return dt.date() return dt.date()
return None
default_sqlalchemy_filters = { default_sqlalchemy_filters = {
None: AlchemyFilter, None: AlchemyFilter,

View file

@ -190,6 +190,7 @@ def default_user_getter(request, db_session=None):
model = app.model model = app.model
session = db_session or Session() session = db_session or Session()
return session.get(model.User, uuid) return session.get(model.User, uuid)
return None
def new_request_set_user( def new_request_set_user(

View file

@ -278,6 +278,8 @@ def get_libver(
if not configured_only: if not configured_only:
return "3.1.1" return "3.1.1"
return None
def get_liburl( def get_liburl(
request, request,
@ -370,7 +372,7 @@ def get_liburl(
return url return url
if configured_only: if configured_only:
return return None
version = get_libver( version = get_libver(
request, key, prefix=prefix, configured_only=False, default_only=default_only request, key, prefix=prefix, configured_only=False, default_only=default_only
@ -456,6 +458,8 @@ def get_liburl(
f"https://cdn.jsdelivr.net/npm/@fortawesome/vue-fontawesome@{version}/+esm" f"https://cdn.jsdelivr.net/npm/@fortawesome/vue-fontawesome@{version}/+esm"
) )
return None
def get_csrf_token(request): def get_csrf_token(request):
""" """
@ -523,7 +527,7 @@ def get_model_fields(config, model_class, include_fk=False):
try: try:
mapper = sa.inspect(model_class) mapper = sa.inspect(model_class)
except sa.exc.NoInspectionAvailable: except sa.exc.NoInspectionAvailable:
return return None
if include_fk: if include_fk:
fields = [prop.key for prop in mapper.iterate_properties] fields = [prop.key for prop in mapper.iterate_properties]

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -149,6 +149,7 @@ class BatchMasterView(MasterView):
if value: if value:
batch_id = int(value) batch_id = int(value)
return f"{batch_id:08d}" return f"{batch_id:08d}"
return None
def get_instance_title(self, batch): def get_instance_title(self, batch):
""" """ """ """

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -126,7 +126,7 @@ class EmailSettingView(MasterView):
""" """ """ """
recips = value recips = value
if not recips: if not recips:
return return None
if len(recips) < 3: if len(recips) < 3:
return ", ".join(recips) return ", ".join(recips)

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -1449,7 +1449,7 @@ class MasterView(View):
grid.set_renderer('my_bool_field', self.grid_render_bool) grid.set_renderer('my_bool_field', self.grid_render_bool)
""" """
if value is None: if value is None:
return return None
return "Yes" if value else "No" return "Yes" if value else "No"
@ -1476,7 +1476,7 @@ class MasterView(View):
value = record[key] value = record[key]
if value is None: if value is None:
return return None
if value < 0: if value < 0:
fmt = f"(${{:0,.{scale}f}})" fmt = f"(${{:0,.{scale}f}})"
@ -1506,7 +1506,7 @@ class MasterView(View):
value = record[key] value = record[key]
if value is None: if value is None:
return return None
return value.strftime(fmt or "%Y-%m-%d %I:%M:%S %p") return value.strftime(fmt or "%Y-%m-%d %I:%M:%S %p")
@ -1555,7 +1555,7 @@ class MasterView(View):
grid.set_renderer('my_notes_field', self.grid_render_notes, maxlen=50) grid.set_renderer('my_notes_field', self.grid_render_notes, maxlen=50)
""" """
if value is None: if value is None:
return return None
if len(value) < maxlen: if len(value) < maxlen:
return value return value
@ -1910,6 +1910,7 @@ class MasterView(View):
if self.listable: if self.listable:
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
return self.request.route_url(route_prefix, **kwargs) return self.request.route_url(route_prefix, **kwargs)
return None
def set_labels(self, obj): def set_labels(self, obj):
""" """
@ -2073,6 +2074,7 @@ class MasterView(View):
""" """
if hasattr(self, "grid_columns"): if hasattr(self, "grid_columns"):
return self.grid_columns return self.grid_columns
return None
def get_grid_data(self, columns=None, session=None): def get_grid_data(self, columns=None, session=None):
""" """
@ -2104,6 +2106,7 @@ class MasterView(View):
if model_class: if model_class:
session = session or self.Session() session = session or self.Session()
return session.query(model_class) return session.query(model_class)
return None
def configure_grid(self, grid): def configure_grid(self, grid):
""" """
@ -2289,6 +2292,7 @@ class MasterView(View):
""" """
if self.is_editable(obj): if self.is_editable(obj):
return self.get_action_url("edit", obj) return self.get_action_url("edit", obj)
return None
def get_action_url_delete(self, obj, i): def get_action_url_delete(self, obj, i):
""" """
@ -2305,6 +2309,7 @@ class MasterView(View):
""" """
if self.is_deletable(obj): if self.is_deletable(obj):
return self.get_action_url("delete", obj) return self.get_action_url("delete", obj)
return None
def is_editable(self, obj): def is_editable(self, obj):
""" """
@ -2386,6 +2391,7 @@ class MasterView(View):
""" """
if hasattr(self, "form_fields"): if hasattr(self, "form_fields"):
return self.form_fields return self.form_fields
return None
def configure_form(self, form): def configure_form(self, form):
""" """
@ -2480,6 +2486,7 @@ class MasterView(View):
""" """
if hasattr(self, "rows_title"): if hasattr(self, "rows_title"):
return self.rows_title return self.rows_title
return None
def make_row_model_grid(self, obj, **kwargs): def make_row_model_grid(self, obj, **kwargs):
""" """
@ -2586,6 +2593,7 @@ class MasterView(View):
""" """
if hasattr(self, "row_grid_columns"): if hasattr(self, "row_grid_columns"):
return self.row_grid_columns return self.row_grid_columns
return None
def get_row_grid_data(self, obj): def get_row_grid_data(self, obj):
""" """
@ -2685,6 +2693,7 @@ class MasterView(View):
""" """
if hasattr(cls, "model_class"): if hasattr(cls, "model_class"):
return cls.model_class return cls.model_class
return None
@classmethod @classmethod
def get_model_name(cls): def get_model_name(cls):
@ -2972,6 +2981,7 @@ class MasterView(View):
""" """
if hasattr(cls, "row_model_class"): if hasattr(cls, "row_model_class"):
return cls.row_model_class return cls.row_model_class
return None
############################## ##############################
# configuration # configuration

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# wuttaweb -- Web App for Wutta Framework # wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar # Copyright © 2024-2025 Lance Edgar
# #
# This file is part of Wutta Framework. # This file is part of Wutta Framework.
# #
@ -117,6 +117,7 @@ class UpgradeView(MasterView):
return "has-background-warning" return "has-background-warning"
if upgrade.status == enum.UpgradeStatus.FAILURE: if upgrade.status == enum.UpgradeStatus.FAILURE:
return "has-background-warning" return "has-background-warning"
return None
def configure_form(self, f): def configure_form(self, f):
""" """ """ """
@ -228,6 +229,7 @@ class UpgradeView(MasterView):
""" """ """ """
if filename: if filename:
return self.get_upgrade_filepath(upgrade, filename) return self.get_upgrade_filepath(upgrade, filename)
return None
def get_upgrade_filepath(self, upgrade, filename=None, create=True): def get_upgrade_filepath(self, upgrade, filename=None, create=True):
""" """ """ """

View file

@ -104,6 +104,7 @@ class UserView(MasterView):
""" """ """ """
if not user.active: if not user.active:
return "has-background-warning" return "has-background-warning"
return None
def is_editable(self, user): def is_editable(self, user):
""" """ """ """

View file

@ -9,6 +9,10 @@ commands = pytest {posargs}
[testenv:nox] [testenv:nox]
extras = tests extras = tests
[testenv:pylint]
basepython = python3.11
commands = pylint wuttaweb
[testenv:coverage] [testenv:coverage]
basepython = python3.11 basepython = python3.11
commands = pytest --cov=wuttaweb --cov-report=html --cov-fail-under=100 commands = pytest --cov=wuttaweb --cov-report=html --cov-fail-under=100