This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PEP 292 implementation
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, brett.cannon, rhettinger
Priority: critical Keywords: patch

Created on 2004-08-23 03:24 by barry, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pep292.diff.txt barry, 2004-08-23 03:24
Messages (6)
msg46764 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2004-08-23 03:24
Here's a patch implementing PEP 292.  It does /not/
include the string module reorganization.
msg46765 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-08-23 08:21
Logged In: YES 
user_id=80475

1. Upon applying the patch, "import re" fails immediately:

Python 2.4a2 (#46, Aug 22 2004, 17:49:20) [MSC v.1200 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import re
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\PY24\lib\re.py", line 5, in ?
    from sre import *
  File "C:\PY24\lib\sre.py", line 98, in ?
    import sre_parse
  File "C:\PY24\lib\sre_parse.py", line 16, in ?
    import string, sys
  File "C:\PY24\lib\string.py", line 84, in ?
    class Template(unicode):
  File "C:\PY24\lib\string.py", line 89, in Template
    pattern = _re.compile(r"""
AttributeError: 'module' object has no attribute 'compile'

2. Needs thorough unittests before applying.

3. The little page breaks reappeared everywhere.

4. The "del _re" disappeared.

5. Consider adding examples to the docstrings and then
running them through doctest.

6. The mod operation returns a unicode object even if the
underlying template string and substitution variables are
normal strings.  Was this intended?

7.  Pattern legibility can be improved by indenting the
block and putting the comments on the same line as the
action or by putting the comments outside the pattern:

    pattern = _re.compile(r"""
      (?P<escaped>\${2})| # Match exactly two $'s
      \$(?P<named>[_a-z][_a-z0-9]*)| # identifer w/o braces
      \${(?P<braced>[_a-z][_a-z0-9]*)}| # identifier in braces
      (?P<bogus>\$)   # catchall for ill-formed $ expressions
    """
8.  Consider adding an auxiliary function to make a better
ValueError message that specifies line number rather than
character position:
   ValueError:  Invalid $ expression on line 206.

9. The retrieval of groupdict followed by a get is
unnecessary; the names can be retrieved directly with group():

    if mo.group('escaped') is not None:
        return '$'
    if mo.group('bogus') is not None:
        . . .

10.  The TeX markup passes texcheck.py and the wording
passes spell check.

11.  The reference to 292 should be moved down and made into
a \seealso reference.  As it reads now, it suggests that the
PEP is the primary documentation, but the lib ref needs to
be able to stand alone (the peps don't even go out as part
of the doc package).

12.  When referring to traditional % substitutions, add a
link to the relavant section in the docs.

13.  On the first reference to "Python identifier", add in
parentheses (alphanumeric strings starting with an alpha
character or underscore) or something similar.  Right now,
it presumes that knowledge without providing the ability to
find it.  Also, it is not clear that it is just the rules
that are the same -- that there doesn't have to be an
existing variable of that exact name.

14.  The style guide prohibits using "e.g.".  Replace it
with "such as" -- that will help international readers not
familiar with our abbreviation practices.

15.  How does Tim rate being in an example?  I can think of
another person who is much better looking and takes
excellent photographs ;-)

16.  At the end, add some examples of normal usage and an
example of overiding the pattern.

17.  Document the pattern attribute.
  
msg46766 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-08-23 15:09
Logged In: YES 
user_id=80475

Also, please take another look at whether these have to be
classes.  They are much easier to use as functions.

Instead of:
   t = Template(mytemp)
   print t % mymap
Write:
   print substitute(mytemp, mymap)

AFAICT, the only advantage of having a class is to provide a
namespace for the default pattern.  And, even that can be
handled with a pattern=_default_pattern argument.

When it comes to subclassing, no useful behaviors are
inherited, so a user is essentially starting from scratch
anyway.
msg46767 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-08-23 20:09
Logged In: YES 
user_id=80475

Also, the docs need a \versionadded tag.
msg46768 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-08-23 22:28
Logged In: YES 
user_id=357491

I don't have the import problem Raymond is having (nor do I have it if I 
use the CVS version by symlinking it to Lib/string).
msg46769 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2004-09-07 19:52
Logged In: YES 
user_id=12800

This can be closed now -- all the relevant discussion on
this is conducted elsewhere and there is code in Python 2.4
as of a3 now.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40806
2004-08-23 03:24:36barrycreate