Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Class methods in standard library that (c|sh)ould be staticmethods

0 views
Skip to first unread message

Christos TZOTZIOY

unread,
Jan 1, 2003, 2:05:38 PM1/1/03
to
As I understand it, based on the description of a staticmethod, there
are some methods that qualify as static methods this way:
* They are irrelevant to the instance data
* They are meaningful if called on their own (through the class of
course) without any need for creating a class instance.

A staticmethod has also a minor advantage of lower overhead and slightly
faster calls (as verified in 2.2.2 and 2.3 by me) than methods (UIAM
static methods stop being methods and turn into simple functions).

Since static methods are there, anyway, and keeping in mind that many
(at least, *I* did and still do occasionally :) newbies browse the
standard library to learn Python, I suggest we change some of the
library class methods into static methods. I'm willing do that (ie
provide a patch), if there is some consensus; after all, I already did
that and verified that nothing changed in the standard test suite
results.

At the end of my post I provide a list of the methods that can be turned
into static methods, along with a little reasoning why. I picked
methods that can be of wider use (for some of which I have written
versions of my own when I shouldn't, since they were in the library...).

Opinions, please.

** List of staticmethod candidates:

- File 'cgi.py', class FieldStorage, method make_file:
# Returns a read-write temporary binary file. (perhaps a
tempfile.TemporaryFile would be more appropriate, though)

- File 'CGIHTTPServer.py', class CGIHTTPRequestHandler, method
is_executable:
# Checks whether argument is an executable.
- File 'CGIHTTPServer.py', class CGIHTTPRequestHandler, method
is_python:
# Checks whether path argument is a python script.

- File 'cmd.py', class Cmd, method columnize:
# Displays a list of strings as a compact set of columns.

- File 'ConfigParser.py', class ConfigParser, method _interpolate:
# Substitutes %(name) values "recursively" (tries again after
substituting)
I would drop the underscore in this case, though.

- File 'formatter.py', class AbstractFormatter, method format_roman:
# Returns a number as a Roman numeral.

- File 'HTMLParser.py', class HTMLParser, method unescape:
# Returns its arg unescaping some common HTML "&name;" entities

- File 'pydoc.py', class HTMLRepr, method escape:
# Returns its arg escaping '&', '<' and '>'

- File 'pydoc.py', class TextDoc, method indent:
# Indents each line in its text arg with its prefix arg

- All encode, decode methods of the Codec classes in the
encodings/<codec>.py files (although str.decode and unicode.encode feel
more appropriate)
--
TZOTZIOY, I speak England very best,
Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64')

0 new messages