3
0
Fork 0

fix: fix 'attribute-defined-outside-init' for pylint

This commit is contained in:
Lance Edgar 2025-09-01 11:53:50 -05:00
parent 92754a64c4
commit dd25d98e7d
8 changed files with 29 additions and 24 deletions

View file

@ -2,6 +2,5 @@
[MESSAGES CONTROL]
disable=fixme,
attribute-defined-outside-init,
duplicate-code,
no-member,

View file

@ -65,13 +65,13 @@ class WebAppProvider(AppProvider):
:returns: Instance of :class:`~wuttaweb.handler.WebHandler`.
"""
if "web_handler" not in self.__dict__:
if "web" not in self.app.handlers:
spec = self.config.get(
f"{self.appname}.web.handler_spec",
default="wuttaweb.handler:WebHandler",
)
self.web_handler = self.app.load_object(spec)(self.config)
return self.web_handler
self.app.handlers["web"] = self.app.load_object(spec)(self.config)
return self.app.handlers["web"]
def make_wutta_config(settings, config_maker=None, **kwargs):

View file

@ -264,10 +264,11 @@ class Form: # pylint: disable=too-many-instance-attributes,too-many-public-meth
If the :meth:`validate()` method was called, and it succeeded,
this will be set to the validated data dict.
Note that in all other cases, this attribute may not exist.
"""
deform_form = None
validated = None
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-locals
self,
request,
@ -874,7 +875,7 @@ class Form: # pylint: disable=too-many-instance-attributes,too-many-public-meth
Return the :class:`deform:deform.Form` instance for the form,
generating it automatically if necessary.
"""
if not hasattr(self, "deform_form"):
if not self.deform_form:
schema = self.get_schema()
kwargs = {}
@ -1174,9 +1175,9 @@ class Form: # pylint: disable=too-many-instance-attributes,too-many-public-meth
:attr:`validated` attribute.
However if the data is not valid, ``False`` is returned, and
there will be no :attr:`validated` attribute. In that case
you should inspect the form errors to learn/display what went
wrong for the user's sake. See also
the :attr:`validated` attribute will be ``None``. In that
case you should inspect the form errors to learn/display what
went wrong for the user's sake. See also
:meth:`get_field_errors()`.
This uses :meth:`deform:deform.Field.validate()` under the
@ -1192,8 +1193,7 @@ class Form: # pylint: disable=too-many-instance-attributes,too-many-public-meth
:returns: Data dict, or ``False``.
"""
if hasattr(self, "validated"):
del self.validated
self.validated = None
if self.request.method != "POST":
return False

View file

@ -264,7 +264,7 @@ class Grid: # pylint: disable=too-many-instance-attributes,too-many-public-meth
``active_sorters`` defines the "current/effective" sorters.
This attribute is set by :meth:`load_settings()`; until that is
called it will not exist.
called its value will be ``None``.
This is conceptually a "subset" of :attr:`sorters` although a
different format is used here::
@ -372,6 +372,10 @@ class Grid: # pylint: disable=too-many-instance-attributes,too-many-public-meth
See also :meth:`add_tool()` and :meth:`set_tools()`.
"""
active_sorters = None
joined = None
pager = None
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-locals
self,
request,
@ -2293,12 +2297,11 @@ class Grid: # pylint: disable=too-many-instance-attributes,too-many-public-meth
:returns: The first sorter in format ``[sortkey, sortdir]``,
or ``None``.
"""
if hasattr(self, "active_sorters"):
if self.active_sorters:
sorter = self.active_sorters[0]
return [sorter["key"], sorter["dir"]]
elif self.sort_defaults:
if self.sort_defaults:
sorter = self.sort_defaults[0]
return [sorter.sortkey, sorter.sortdir]

View file

@ -439,6 +439,7 @@ class MasterView(View): # pylint: disable=too-many-public-methods
viewing = False
editing = False
deleting = False
executing = False
configuring = False
# default DB session

View file

@ -58,6 +58,8 @@ class RoleView(MasterView): # pylint: disable=abstract-method
}
sort_defaults = "name"
wutta_permissions = None
# TODO: master should handle this, possibly via configure_form()
def get_query(self, session=None): # pylint: disable=empty-docstring
""" """

View file

@ -363,7 +363,7 @@ class TestForm(TestCase):
# basic
form = self.make_form(schema=schema)
self.assertFalse(hasattr(form, "deform_form"))
self.assertIsNone(form.deform_form)
dform = form.get_deform()
self.assertIsInstance(dform, deform.Form)
self.assertIs(form.deform_form, dform)
@ -684,7 +684,7 @@ class TestForm(TestCase):
def test_validate(self):
schema = self.make_schema()
form = self.make_form(schema=schema)
self.assertFalse(hasattr(form, "validated"))
self.assertIsNone(form.validated)
# will not validate unless request is POST
self.request.POST = {"foo": "blarg", "bar": "baz"}

View file

@ -497,7 +497,7 @@ class TestGrid(WebTestCase):
# settings are loaded, applied, saved
self.assertEqual(grid.sort_defaults, [])
self.assertFalse(hasattr(grid, "active_sorters"))
self.assertIsNone(grid.active_sorters)
self.request.GET = {"sort1key": "name", "sort1dir": "desc"}
grid.load_settings()
self.assertEqual(grid.active_sorters, [{"key": "name", "dir": "desc"}])
@ -525,7 +525,7 @@ class TestGrid(WebTestCase):
sort_on_backend=True,
sort_defaults="name",
)
self.assertFalse(hasattr(grid, "active_sorters"))
self.assertIsNone(grid.active_sorters)
grid.load_settings()
self.assertEqual(grid.active_sorters, [{"key": "name", "dir": "asc"}])
@ -537,7 +537,7 @@ class TestGrid(WebTestCase):
mod.SortInfo("name", "asc"),
mod.SortInfo("value", "desc"),
]
self.assertFalse(hasattr(grid, "active_sorters"))
self.assertIsNone(grid.active_sorters)
grid.load_settings()
self.assertEqual(grid.active_sorters, [{"key": "name", "dir": "asc"}])
@ -556,7 +556,7 @@ class TestGrid(WebTestCase):
paginated=True,
paginate_on_backend=True,
)
self.assertFalse(hasattr(grid, "active_sorters"))
self.assertIsNone(grid.active_sorters)
grid.load_settings()
self.assertEqual(grid.active_sorters, [{"key": "name", "dir": "desc"}])