[New-bugs-announce] [issue14545] html module should not be available in Python 3.1

Chris Jerdonek report at bugs.python.org
Wed Apr 11 07:26:11 CEST 2012

New submission from Chris Jerdonek <chris.jerdonek at gmail.com>:

The Python documentation says that the html module (defining html.escape()) is new in Python 3.2:


However, it's importable in Python 3.1, but without the escape() function.   See below for evidence.

This prevents the usual EAFP code from not working:

    # Python 3.2 deprecates cgi.escape() and adds the html module as a replacement.
    import html
except ImportError:
    import cgi as html

> python
Python 3.1.4 (default, Apr 10 2012, 21:58:25) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import html
>>> html.escape
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'escape'
>>> dir(html)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
>>> html.__file__

components: None
messages: 158008
nosy: cjerdonek
priority: normal
severity: normal
status: open
title: html module should not be available in Python 3.1
type: behavior
versions: Python 3.1

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list