Is it bad style to override the built-in function `type`?

Cameron Simpson cs at
Sun Nov 25 07:33:58 CET 2012

On 25Nov2012 04:06, Steven D'Aprano <steve+comp.lang.python at> wrote:
| On Sat, 24 Nov 2012 14:32:19 -0800, Michael Herrmann wrote:
| > how about "write" instead of "type"? Just came to me in a flash of
| > inspiration. I know it's also pretty general but at least it's not a
| > built-in!
| "write" is an extremely common operation with a signature very similar to 
| that of your function you want. The typical use of your function:
| automata.write("Hello world")  # or whatever your module is called
| looks exactly like writing to the file referred to by the name "automata".

Which is actually an argument _for_ his suggestion.

| If I inspect the way that the functions are used, the difference is 
| clear: write is nearly always used as a procedure, while type is used as 
| a function. [...]
| Your "simulate typing" function does not look like this. It doesn't 
| return anything. It usually gets used as a procedure, not a function, 
| just like the write method:

Again, an argument _for_ his suggestion.

| There is far more opportunity for confusion with the name "write" than 
| "type":
| * but a call to your proposed function "write(string)" does look
|   very similar, if not identical, to a typical call to write.

Again, an argument _for_ his suggestion.

Why do I find these reasons to be plusses while you find them minuses?
Because you're conveniently glossing over the fact that almost all
uses of "write" in the library and common code have an object for

And I find his suggestion good because for us old UNIX heads, the way you
present typed text to a terminal is usually to write it to the master
side of a pseudotty, thus:

  pty.write("typed text here!")

The usage is _exactly_ analogous to the conventional uses of write(),
because "everything is a file" (one of the UNIX mantras). Writing typed
text is the natural way to express this stuff.

Your argument seems to be that because his write looks and acts like
other write()s it is cause for confusion. My argument is that using the
name "write" is a good thing, _because_ his usage looks and acts like
the other common uses of write.

So I maintain it should cause less confusion.

Cameron Simpson <cs at>

It is a tale told by an idiot, full of sound and fury, signifying nothing.
        - William Shakespeare

More information about the Python-list mailing list