From ac65ec891b8169d07fc26fd6908e0e12dbd4a27f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 30 Aug 2025 15:46:42 -0500 Subject: [PATCH] add initial pylint config, just one checker will clean these up one by one so we can use fail-under=10 for buildbot pylint --- .pylintrc | 5 +++++ src/wuttjamaican/conf.py | 16 +++++++++------- src/wuttjamaican/email.py | 16 ++++++++++------ tox.ini | 6 ++++++ 4 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..e634a21 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,5 @@ +# -*- mode: conf; -*- + +[MESSAGES CONTROL] +disable=all +enable=dangerous-default-value diff --git a/src/wuttjamaican/conf.py b/src/wuttjamaican/conf.py index daad029..3eff415 100644 --- a/src/wuttjamaican/conf.py +++ b/src/wuttjamaican/conf.py @@ -61,10 +61,12 @@ class WuttaConfig: * one or more INI files * "defaults" provided by app logic - :param files: List of file paths from which to read config values. + :param files: Optional list of file paths from which to read + config values. - :param defaults: Initial values to use as defaults. This gets - converted to :attr:`defaults` during construction. + :param defaults: Optional dict of initial values to use as + defaults. This gets converted to :attr:`defaults` during + construction. :param appname: Value to assign for :attr:`appname`. @@ -187,8 +189,8 @@ class WuttaConfig: def __init__( self, - files=[], - defaults={}, + files=None, + defaults=None, appname='wutta', usedb=None, preferdb=None, @@ -199,11 +201,11 @@ class WuttaConfig: # read all files requested self.files_read = [] - for path in files: + for path in files or []: self._load_ini_configs(path, configs, require=True) # add config for use w/ setdefault() - self.defaults = configuration.Configuration(defaults) + self.defaults = configuration.Configuration(defaults or {}) configs.append(self.defaults) # master config set diff --git a/src/wuttjamaican/email.py b/src/wuttjamaican/email.py index ab89081..af039d6 100644 --- a/src/wuttjamaican/email.py +++ b/src/wuttjamaican/email.py @@ -370,7 +370,7 @@ class EmailHandler(GenericHandler): """ return Message(**kwargs) - def make_auto_message(self, key, context={}, default_subject=None, **kwargs): + def make_auto_message(self, key, context=None, default_subject=None, **kwargs): """ Make a new email message using config to determine its properties, and auto-generating body from a template. @@ -407,6 +407,7 @@ class EmailHandler(GenericHandler): * :meth:`get_auto_txt_body()` * :meth:`get_auto_html_body()` """ + context = context or {} kwargs['key'] = key if 'sender' not in kwargs: kwargs['sender'] = self.get_auto_sender(key) @@ -452,7 +453,7 @@ class EmailHandler(GenericHandler): # fall back to global default, if present return self.config.get(f'{self.config.appname}.email.default.replyto') - def get_auto_subject(self, key, context={}, rendered=True, setting=None, default=None): + def get_auto_subject(self, key, context=None, rendered=True, setting=None, default=None): """ Returns automatic :attr:`~wuttjamaican.email.Message.subject` line for a message, as determined by config. @@ -481,6 +482,7 @@ class EmailHandler(GenericHandler): if not rendered: return template + context = context or {} return Template(template).render(**context) def get_auto_subject_template(self, key, setting=None, default=None): @@ -561,7 +563,7 @@ class EmailHandler(GenericHandler): return self.config.get_list(f'{self.config.appname}.email.default.{typ}', default=[]) - def get_auto_txt_body(self, key, context={}): + def get_auto_txt_body(self, key, context=None): """ Returns automatic :attr:`~wuttjamaican.email.Message.txt_body` content for a message, as determined by config. This renders @@ -569,9 +571,10 @@ class EmailHandler(GenericHandler): """ template = self.get_auto_body_template(key, 'txt') if template: + context = context or {} return template.render(**context) - def get_auto_html_body(self, key, context={}): + def get_auto_html_body(self, key, context=None): """ Returns automatic :attr:`~wuttjamaican.email.Message.html_body` content for a @@ -580,6 +583,7 @@ class EmailHandler(GenericHandler): """ template = self.get_auto_body_template(key, 'html') if template: + context = context or {} return template.render(**context) def get_auto_body_template(self, key, mode): @@ -740,7 +744,7 @@ class EmailHandler(GenericHandler): return self.config.get_bool(f'{self.config.appname}.mail.send_emails', default=False) - def send_email(self, key=None, context={}, message=None, sender=None, recips=None, **kwargs): + def send_email(self, key=None, context=None, message=None, sender=None, recips=None, **kwargs): """ Send an email message. @@ -810,7 +814,7 @@ class EmailHandler(GenericHandler): # auto-create message from key + context if sender: kwargs['sender'] = sender - message = self.make_auto_message(key, context, **kwargs) + message = self.make_auto_message(key, context or {}, **kwargs) if not (message.txt_body or message.html_body): raise RuntimeError(f"message (type: {key}) has no body - " "perhaps template file not found?") diff --git a/tox.ini b/tox.ini index 4c184e5..2d8728a 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,12 @@ commands = pytest {posargs} [testenv:nox] extras = tests +[testenv:pylint] +basepython = python3.11 +extras = +deps = pylint +commands = pylint wuttjamaican + [testenv:coverage] basepython = python3.11 extras = db,tests