Template variable reference fails

Tom Ekberg <[email protected]>
Newsgroups gmane.comp.bug-tracking.roundup.user
Message-ID <DM6PR08MB4778871D2A463FE3A889D40ACA710@DM6PR08MB4778.namprd08.prod.outlook.com>
This is the case where a TAL variable reference using near-tip roundup and python3.5 fails.


I think I have discovered why this happens. In cgi/PageTemplates/PythonExpr.py there is a slight difference between determining variable references in Python 2.7 and Python 3.5. In Python 2.7, assuming function f, evaluating f.func_code.co_names is used to determine variable references. In Python 3.5 the corresponding expression is f.__code__.co_names. On the surface this looks correct. If the function f looks like this:


def f(): return [x for x in context.assignedto_multi if x.realname not in user_realnames]

Note that the variables referenced are context and user_realnames.

The f.func_code.co_names in Python 2.7 evalutates to this:

>>> f.func_code.co_names
('context', 'assignedto_multi', 'realname', 'user_realnames')

The extra names assignedto_multi and realnames aren't really variable but that is OK. The variables context and user_realnames are present. Now, for Python 3.5 the f.__code__.co_names expression evaluates to this:

>>> f.__code__.co_names
('context', 'assignedto_multi')

Note that the required variable user_realnames is not present! This is why I get the following templating error when function f is evaluated:

<class 'NameError'>: name 'user_realnames' is not defined

I looked at all of the other attributes of f.__code__ for Python 3.5 None of them looked like replacements for co_names. The same was the case for the attributes of f.

So, this is a roundup bug due a difference between Python 3.5 and 2.7. Other than filing a bug report I don't know how to proceeded. Any ideas?

Tom Ekberg
Senior Computer Specialist, Lab Medicine
4th Floor, Pat Steel Building
Department of Laboratory Medicine
Work: (206) 520-4856
Email: [email protected]

_______________________________________________
Roundup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/roundup-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.