Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module members with attributes named interval, rule, etc. confused for decorated functions #859

Closed
Zokormazo opened this issue Aug 11, 2015 · 5 comments · Fixed by #1936
Closed
Assignees
Labels
Bug Things to squish; generally used for issues
Milestone

Comments

@Zokormazo
Copy link

Modules with 'interval' config option don't work, they throw this error:

TypeError: 'ValidatedAttribute' object is not iterable (file "/home/julen/projects/sopel/sopel/bot.py", line 177, in register)

If i change the config option name to something else they work properle

Tryed with this to discard any other problem:

interval.py
import sopel
from sopel.config.types import ValidatedAttribute, StaticSection

class IntervalSection(StaticSection):
interval = ValidatedAttribute('interval', default='5')

def configure(config):
config.define_section('test', IntervalSection)
config.test.configure_setting(
'interval',
'interval to work'
)

def setup(bot=None):
if not bot:
return
bot.config.define_section('test', IntervalSection)

@embolalia embolalia added the Bug Things to squish; generally used for issues label Aug 22, 2015
@embolalia
Copy link
Contributor

Having an interval attribute on anything callable in your module makes Sopel think it's a function it should call periodically; @interval basically just adds an interval attribute to a function. For now, you'll have to rename the attribute to something else (the actual setting in the config file can be the same, but the name of the attribute on the class has to be different).

Fixing this well is a bit difficult. I don't want to just add and not isattribute(StaticSection) to the logic that finds those things, because obviously this can still also happen to anything else in your module. (Honestly, I'm kind of surprised that this is the first time I've heard of it happening). It'll probably have to be reworking the decorators to use mangled attribute names, which would once and for all break backwards compatibility with the ancient versions, so there probably won't be a complete solution until at least 7.0.

@embolalia embolalia changed the title ValidatedAttribute called 'interval' Module members with attributes named interval, rule, etc. confused for decorated functions Aug 22, 2015
@Exirel
Copy link
Contributor

Exirel commented Jan 12, 2019

Just a quick note here: this kind of issues arise in part because there is no way to tell Sopel that "this is a module", and that "this isn't a module": no meta-data, no "ModuleConfig" object, etc. nothing!

As said by @embolia, as it is, it's not easy to fix, and I'm not sure it's something doable for 7.x release.
But that's something I wish to work on if I've the time.

@Exirel Exirel added Low Priority Long-term Planning Things that need to happen at some point in the future, but need to NOT happen soon. and removed Low Priority labels Mar 21, 2019
@dgw dgw added this to the 8.0.0 milestone Nov 21, 2019
@dgw
Copy link
Member

dgw commented Nov 21, 2019

Milestone assigned so we don't lose track of this.

@dgw
Copy link
Member

dgw commented Aug 29, 2020

As noted in my writeup for #1931, even an innocent-looking global variable containing an innocent-looking stdlib object can trigger this.

@Exirel
Copy link
Contributor

Exirel commented Sep 11, 2020

When I wrote this in the doc for Sopel 7:

Sopel identifies a callable as a rule when it has been decorated with any of
these decorators from :mod:`sopel.plugin`

I didn't realize that I basically got the solution for this issue.

As a result, these decorators will add an attribute and set it to True to the decorated callable. Sopel won't collect objects without this attribute, and it has to be set to True.

So yeah, it'll be done for Sopel 7.1!

@Exirel Exirel modified the milestones: 8.0.0, 7.1.0 Sep 11, 2020
@Exirel Exirel removed the Long-term Planning Things that need to happen at some point in the future, but need to NOT happen soon. label Sep 11, 2020
@Exirel Exirel self-assigned this Sep 11, 2020
@dgw dgw closed this as completed in #1936 Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Things to squish; generally used for issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants