Modify

Ticket #29 (closed defect: fixed)

Opened 3 months ago

Last modified 3 months ago

Validator subclasses can't access superclass messages method

Reported by: jcmcken@… Owned by:
Priority: minor Milestone: 0.5
Keywords: Cc:

Description (last modified by fs) (diff)

Your superclass magic may be too magical for me. Or maybe I'm not doin' it right

from pycerberus.api import Validator
>>> class FooValidator(Validator):
...     def messages(self):
...             super_msg = Validator.messages(self).copy()
...             return super_msg.update({'foo':u'bar'})
... 
>>> FooValidator()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/pycerberus-0.4.2-py2.6.egg/pycerberus/api.py", line 165, in __init__
    self._implementations, self._implementation_by_class = self._freeze_implementations_for_class()
  File "/usr/lib/python2.6/site-packages/pycerberus-0.4.2-py2.6.egg/pycerberus/api.py", line 187, in _freeze_implementations_for_class
    for key in cls.keys(self):
TypeError: 'NoneType' object is not iterable

Attachments

Change History

comment:2 Changed 3 months ago by fs

  • Description modified (diff)

comment:3 Changed 3 months ago by fs

Just return the new/updated keys, that should work. The "magic" will collect all the other messages from your super classes:

class FooValidator(Validator):
    def messages(self):
        return {'foo': u'bar'}

I tried to express that in the docs:

Return all messages which are defined by this validator as a key/message dictionary.

Please point me to places where I should improve the documentation.

Did that help?

comment:4 Changed 3 months ago by jcmcken@…

Ah. To me that means all messages defined in the current class, not including any that may have existed in the superclass(es).

I also noticed the class-level definition of messages, which I think I like better than the method.

Thanks for your response

comment:5 Changed 3 months ago by fs

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone set to 0.5
View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.