Re: Extending built-in function unicode
"Sergey Schetinin" <[email protected]>
| Newsgroups | gmane.comp.python.peak |
|---|---|
| Message-ID | <[email protected]> |
PEAK-Rules only works on functions with code objects. <unicode> isn't a function at all, it's a type. Also, it's a builtin, implemented in C, so you can't extend it. Also if types is the types module, then types.ClassType isn't some Django specific type, it's a builtin type for old-style classes. It also seems that you don't know about __repr__ / __str__ / __unicode__ methods. I'd suggest to try Python manual first. http://docs.python.org/library/index.html Anyway, to override __unicode__ for a class, you'd need to change its metaclass which I'm not sure even possible for existing classes. On Mon, Oct 6, 2008 at 14:56, Rajeev J Sebastian <[email protected]> wrote: > Hi, > > I'm using PEAK_Rules-0.5a1.dev_r2576-py2.4 > > I get an exception when trying to "extend" the unicode function: > > @when(unicode, (types.ClassType,)) > def unicode_model(m): > return m._meta.app_label+'.'+m._meta.object_name > > > ( this is to print a good string when the object 'm' is a django model class) > > However, I get something like: > > AttributeError: type object 'unicode' has no attribute 'func_code' > > when this code loads. > > It seems this is because 'unicode' is not a python function (?). Could > someone suggest a better way to achieve this ? > > Regards > Rajeev J Sebastian > > > Partial Traceback: > File "build\bdist.win32\egg\peak\util\decorators.py", line 600, in do_decorate > File "/usr/lib/python2.4/site-packages/PEAK_Rules-0.5a1.dev_r2576-py2.4.egg/peak/rules/core.py", > line 185, in callback > File "/usr/lib/python2.4/site-packages/PEAK_Rules-0.5a1.dev_r2576-py2.4.egg/peak/rules/core.py", > line 309, in rules_for > File "/usr/lib/python2.4/site-packages/PEAK_Rules-0.5a1.dev_r2576-py2.4.egg/peak/rules/core.py", > line 547, in callback > File "/usr/lib/python2.4/site-packages/PEAK_Rules-0.5a1.dev_r2576-py2.4.egg/peak/rules/core.py", > line 153, in __call__ > File "/usr/lib/python2.4/site-packages/PEAK_Rules-0.5a1.dev_r2576-py2.4.egg/peak/rules/core.py", > line 312, in rules_for > File "build\bdist.win32\egg\peak\util\addons.py", line 55, in __call__ > File "/usr/lib/python2.4/site-packages/PEAK_Rules-0.5a1.dev_r2576-py2.4.egg/peak/rules/core.py", > line 334, in __init__ > File "/usr/lib/python2.4/site-packages/PEAK_Rules-0.5a1.dev_r2576-py2.4.egg/peak/rules/core.py", > line 358, in _regen_code > File "build\bdist.win32\egg\peak\util\assembler.py", line 858, in > from_function > AttributeError: type object 'unicode' has no attribute 'func_code' > _______________________________________________ > PEAK mailing list > [email protected] > http://www.eby-sarna.com/mailman/listinfo/peak > -- Best Regards, Sergey Schetinin http://s3bk.com/ -- S3 Backup http://word-to-html.com/ -- Word to HTML Converter