[Patches] [ python-Patches-1022173 ] Improve Template error detection and reporting

SourceForge.net noreply at sourceforge.net
Sun Sep 5 21:19:21 CEST 2004


Patches item #1022173, was opened at 2004-09-03 19:54
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1022173&group_id=5470

Category: Library (Lib)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 6
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Barry A. Warsaw (bwarsaw)
Summary: Improve Template error detection and reporting

Initial Comment:
Report line number and token rather than just character
position.

Detect and report situations where non-ASCII alphabet
characters are used in a placeholder number. 
Currently, this situation results in a silent error for
SafeTemplates and either a KeyError or mis-substitution
for Templates.

Does not change the API or existing tests.


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-09-05 14:19

Message:
Logged In: YES 
user_id=80475

Sure, it is documented that way.  That doesn't mean that we
can't give a useful error message when a potentially common
end-user mistake is made.

The locale has no affect on valid python identifiers;
however, it is a strong indicator of what the user expects
to be valid alphabetical characters.  The idea is to avoid a
silent failure for non-programmer end users who may
understandably not know that some of their everyday
characters will be viewed as delimiters by the template
logic.  As it stands, it is a usability bug (documented, but
a problem never-the-less).

MvL concurred when I discussed with him two weeks ago.



----------------------------------------------------------------------

Comment By: Barry A. Warsaw (bwarsaw)
Date: 2004-09-05 10:34

Message:
Logged In: YES 
user_id=12800

Why would the locale have any effect on what Python defines
an identifier as?  The PEP and documentation clearly state
that the substitution variables are Python identifiers and
that's a well-defined, locale-neutral concept.

The resolution of your hypothetical bug report is:

Won't Fix -- "mañana" is not a Python identifier.  You can't
use it as a variable in regular Python code, and you can't
use it as a placeholder in a Template string.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-09-04 14:44

Message:
Logged In: YES 
user_id=80475

When a user has their locale set so that a different alphabet 
is enabled, then they see $mañana as a single token.  To 
them, the third character is not out of place with the rest -- 
anymore than we think of the letter "d" as not being special.  
In such case, SafeTemplate will pass the error silently.

Bug Report:
"""SafeTemplate broke.  I see placeholder in dictionary but it 
no substitute.  Please fix.

>>>   SafeTemplate("vamanos $mañana o esté dia") % 
{'mañana':'ahora'}
u'vamanos $mañana o esté dia' 

"""

The templates are likely to be exposed to end users (non-
programmers).  The above is not an unlikely scenario.  We 
should give the users as much help as possible.  

Yes, tests and docs will be updated if accepted.  It's a waste 
of time to do so now if you think that $ma was the intended 
placeholder and want the silent error to pass.

Also, the line number / token is an important part of the 
error message.  In a long template, it is useless to say that 
there is an error at position 23019 for example.


----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-09-04 14:43

Message:
Logged In: YES 
user_id=80475

When a user has their locale set so that a different alphabet 
is enabled, then they see $mañana as a single token.  To 
them, the third character is not out of place with the rest -- 
anymore than we think of the letter "d" as not being special.  
In such case, SafeTemplate will pass the error silently.

Bug Report:
"""SafeTemplate broke.  I see placeholder in dictionary but it 
no substitute.  Please fix.

>>>   SafeTemplate("vamanos $mañana o esté dia") % 
{'mañana':'ahora'}
u'vamanos $mañana o esté dia' 

"""

The templates are likely to be exposed to end users (non-
programmers).  The above is not an unlikely scenario.  We 
should give the users as much help as possible.  

Yes, tests and docs will be updated if accepted.  It's a waste 
of time to do so now if you think that $ma was the intended 
placeholder and want the silent error to pass.

Also, the line number / token is an important part of the 
error message.  In a long template, it is useless to say that 
there is an error at position 23019 for example.


----------------------------------------------------------------------

Comment By: Barry A. Warsaw (bwarsaw)
Date: 2004-09-04 12:15

Message:
Logged In: YES 
user_id=12800

I wonder about this patch.  PEP 292 clearly says that the
first non-identifier character terminates the placeholder. 
So why would you expect that the eñe would cause an
exception to be raised instead of a valid substitution for $ma?

Will discuss on python-dev, but in any event, if we accept
this patch we would need a unittest update, as well as
documentation and PEP 292 updates.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1022173&group_id=5470


More information about the Patches mailing list