Bug or feature?

John Roth johnroth at ameritech.net
Sat Sep 1 15:21:36 EDT 2001


"Gerson Kurz" <gerson.kurz at t-online.de> wrote in message
news:3b912589.12116843 at news.t-online.de...
> Consider:
>
> class a:
>     def b(self,x):
>         print "call #1"
>
>     def b(self,x):
>         print "call #2"
>
> v = a()
> v.b(42)
>
> This code raises no warning, and can be executed ('call #2' will be
> printed), on Python 2.1.1 (ActivePython Build 212). Bug or feature?
>
>

Neither one, I'd say. That's just the way Python's object model works.
"def b ..." binds the code object to the variable "b". Since variables
aren't
typed, there's no way of telling in advance whether you really wanted it to
be done once, or not.

On the other hand, I've been bitten a couple of times by that one myself,
and I'd like to see at least a warning while loading a module. Or maybe not,
I can think of several fairly complicated modules that check what's
available in the environment, and then select one of several routines to
present to the user under that name.

John Roth





More information about the Python-list mailing list