You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A ListAttribute that defines its default as a list of something other than str (in my case, ints) breaks sopel-plugins configure if the user simply enters two blank lines to accept the default.
Reproduction steps
Step 1: In ~/.sopel/plugins, create a dummy.py plugin containing this minimal reproducer:
fromsopel.configimporttypesclassDummySection(types.StaticSection):
broken=types.ListAttribute('broken', default=[1, 2, 3])
defconfigure(config):
config.define_section('dummy', DummySection)
config.dummy.configure_setting(
'broken',
'Specify the list to use:',
)
Step 1.5: Enable the plugin if needed (sopel-plugins enable dummy, edit the .cfg file, etc.)
Step 2: Run sopel-plugins configure dummy
Step 3: Press Enter twice to accept the default list, which appears to be ["1","2","3"] (strings) as rendered by the configure_setting() wizard logic.
The command line will error out; see full traceback below.
Expected behavior
Ideally, the default value should Just Work™ if the list members can be cast to str.
While we could consider this to be a plugin developer's problem (as ListAttribute expects str values and the developer isn't providing strs), I do think it would be nice to support this use case—maybe even allow a custom parse type like the basic ValidatedAttribute type does so the plugin can declare its ListAttribute to be a list of e.g. ints instead of strs.
Relevant logs
$ sopel-plugins configure dummy
Configure dummy plugin
Specify the list to use: ["1","2","3"]
??
Traceback (most recent call last):
File "/workspace/.pyenv_mirror/user/3.12.6/bin/sopel-plugins", line 8, in<module>sys.exit(main())
^^^^^^
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/cli/plugins.py", line 559, in main
return handle_configure(options)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/cli/plugins.py", line 332, in handle_configure
plugin.configure(settings)
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/plugins/handlers.py", line 414, in configure
self.module.configure(settings)
File "/workspace/.sopel/plugins/dummy.py", line 10, in configure
config.dummy.configure_setting(
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/config/types.py", line 114, in configure_setting
value = attribute.configure(
^^^^^^^^^^^^^^^^^^^^
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/config/types.py", line 622, in configure
values = self._serialize(values, parent, section)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/config/types.py", line 254, in _serialize
return self.serialize(value)
^^^^^^^^^^^^^^^^^^^^^
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/config/types.py", line 582, in serialize
return'\n' + '\n'.join(self.serialize_item(item) foritemin value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/config/types.py", line 582, in<genexpr>return'\n' + '\n'.join(self.serialize_item(item) foritemin value)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/sopel/config/types.py", line 593, in serialize_item
if item.startswith('#'):
^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'startswith'
Notes
No response
Sopel version
8.0.0
Installation method
pip install
Python version
3.12.6
Operating system
Ubuntu 22.04.4 LTS
IRCd
No response
Relevant plugins
No response
The text was updated successfully, but these errors were encountered:
dgw
added
the
Bug
Things to squish; generally used for issues
label
Sep 25, 2024
Description
A
ListAttribute
that defines itsdefault
as a list of something other thanstr
(in my case,int
s) breakssopel-plugins configure
if the user simply enters two blank lines to accept thedefault
.Reproduction steps
Step 1: In
~/.sopel/plugins
, create adummy.py
plugin containing this minimal reproducer:Step 1.5: Enable the plugin if needed (
sopel-plugins enable dummy
, edit the.cfg
file, etc.)Step 2: Run
sopel-plugins configure dummy
Step 3: Press Enter twice to accept the default list, which appears to be
["1","2","3"]
(strings) as rendered by theconfigure_setting()
wizard logic.The command line will error out; see full traceback below.
Expected behavior
Ideally, the default value should Just Work™ if the list members can be cast to
str
.While we could consider this to be a plugin developer's problem (as
ListAttribute
expectsstr
values and the developer isn't providingstr
s), I do think it would be nice to support this use case—maybe even allow a custom parse type like the basicValidatedAttribute
type does so the plugin can declare itsListAttribute
to be a list of e.g.int
s instead ofstr
s.Relevant logs
Notes
No response
Sopel version
8.0.0
Installation method
pip install
Python version
3.12.6
Operating system
Ubuntu 22.04.4 LTS
IRCd
No response
Relevant plugins
No response
The text was updated successfully, but these errors were encountered: