Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string.Template custom pattern not working #50879

Closed
jcollado mannequin opened this issue Aug 3, 2009 · 5 comments
Closed

string.Template custom pattern not working #50879

jcollado mannequin opened this issue Aug 3, 2009 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jcollado
Copy link
Mannequin

jcollado mannequin commented Aug 3, 2009

BPO 6630
Nosy @warsaw, @birkenfeld, @rhettinger, @ericvsmith

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/warsaw'
closed_at = <Date 2010-07-29.17:16:25.438>
created_at = <Date 2009-08-03.06:47:40.505>
labels = ['type-feature', 'library']
title = 'string.Template custom pattern not working'
updated_at = <Date 2010-07-29.17:16:25.436>
user = 'https://bugs.python.org/jcollado'

bugs.python.org fields:

activity = <Date 2010-07-29.17:16:25.436>
actor = 'georg.brandl'
assignee = 'barry'
closed = True
closed_date = <Date 2010-07-29.17:16:25.438>
closer = 'georg.brandl'
components = ['Library (Lib)']
creation = <Date 2009-08-03.06:47:40.505>
creator = 'jcollado'
dependencies = []
files = []
hgrepos = []
issue_num = 6630
keywords = []
message_count = 5.0
messages = ['91217', '91224', '91230', '91238', '111974']
nosy_count = 5.0
nosy_names = ['barry', 'georg.brandl', 'rhettinger', 'eric.smith', 'jcollado']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue6630'
versions = ['Python 2.7', 'Python 3.2']

@jcollado
Copy link
Mannequin Author

jcollado mannequin commented Aug 3, 2009

In the string.Template documentation
(http://docs.python.org/library/string.html) it's explained that if a
custom regular expression for pattern substitution is needed, it's
possible to override idpattern class attribute (whose default value is
[_a-z][_a-z0-9]*).

However, if the custom pattern that is needed is just uppercase
letters, something like [A-Z]+ won't work because of the following line
in the _TemplateMetaclass class __init__ method:
cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE)

I would say that this is an error (IGNORECASE just shouldn't be there)
and that the line above should be:
cls.pattern = _re.compile(pattern, _re.VERBOSE)
and the default value for idpattern:
[_a-zA-Z][_a-zA-Z0-9]*

Do you agree on this? Is there any reason for the IGNORECASE option to
be passed to re.compile?

@jcollado jcollado mannequin added type-bug An unexpected behavior, bug, or error topic-regex topic-IO labels Aug 3, 2009
@rhettinger
Copy link
Contributor

Better to add a flags argument and leave the default flag as-is.

@rhettinger rhettinger added stdlib Python modules in the Lib dir and removed topic-regex topic-IO labels Aug 3, 2009
@rhettinger rhettinger added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Aug 3, 2009
@ericvsmith
Copy link
Member

I agree with Raymond. I think it should either take a string and flags,
or a compiled regex object.

@warsaw
Copy link
Member

warsaw commented Aug 3, 2009

I agree w/Raymond. string + flags

@birkenfeld
Copy link
Member

Added in r83236.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants