Opened 18 years ago
Closed 18 years ago
#3753 closed (fixed)
Allow TEMPLATE_STRING_IF_INVALID to contain a placeholder for the missing variable's name
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Keywords: | Template, debug, TEMPLATE_STRING_IF_INVALID | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It'd be handy when debugging to see the name of the undefined variable in the TEMPLATE_STRING_IF_INVALID output. To do that, the patch allows TEMPLATE_STRING_IF_INVALID to contain a single '%s' which will be replaced with the invalid variable's name.
Attachments (4)
Change History (10)
by , 18 years ago
Attachment: | template-invalid-varname.diff added |
---|
by , 18 years ago
Attachment: | template-invalid-varname-doc.diff added |
---|
comment:1 by , 18 years ago
Keywords: | Template debug TEMPLATE_STRING_IF_INVALID added |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 18 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Design decision needed → Accepted |
comment:3 by , 18 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
As requested, tests added and suggested modifications made.
by , 18 years ago
Attachment: | 3753-1.diff added |
---|
comment:4 by , 18 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 18 years ago
For future reference: you should not access settings.*
in code that is executed at import time. Doing so means that you cannot import the module in question without haing already configured settings, which requires messy code design in the manually-configured settings case. We should allow people to follow PEP-8 formatted code practices: all imports first, then execute whataver is required (settings configuration, if needed).
I've altered the patch slightly so that settings are only accessed when required (inside Template methods).
comment:6 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Matt,
This sounds reasonable. A few changes to the existing patch(es) I'd like to see:
'%s' in TEMPLATE_STRING_IF_INVALID
, rather than doing the count() call. If there's more than one format string in that string, it's okay to error out, since that's a developer error that they can easily fix as part of the debugging cycle. So check if '%s' is in the string, then do the substitution if so. Python will raise an error anyway if you include more than one format marker ("not enough arguments for format string"), so you don't need to do anything extra there.If you could make one combined patch for everything when you update the patch, that would be cool. Also consider including a patch for AUTHORS so that I don't have to try and spell your name correctly.