Language question

Brian Kelley kelley at bioreason.com
Wed Oct 20 11:45:19 EDT 1999


Tim Peters wrote:

> [Brian Kelley]
> > This question actually comes up due to accident (bug?)  Here is
> > the scenario
> >
> > class foo:
> >       """insert foo here"""
> >
> > def bar(foo):
> >       """this should really be class bar(foo):  Insert bar
> >       here"""
> >
> > As far as python is concerned, this is prefectly legal except
> > that the user of bar will probably get None for their troubles.
> > That is foobar = bar() is the same thing as foobar = None.
> >
> > My question is, is there any real reason to allow this? ...
>
> [Gordon McMillan]
> > What's to disallow? ...
>
> After several readings, I believe Brian objects to Python allowing him to
> reuse the name of a class as a formal argument name, in a context where
> "class" in place of "def" would have been legal.  That is, he would like
> Python to ignore what he typed and infer his intent <wink>.
>
> wouldn't-we-all-ly y'rs  - tim

Pretty much... there are many times when I want compilers to do what I want,
not what I say.   When I wrote this example I obviously forgot the symantics
between functions and classes.  What I was suprised by was that all of the
class symantics were accepted by the function.  In this contrived example:

class bar:
    def __init__(self):
        self.a = 1

def foo(bar):
    def __init__(self):
        self.b = 1

    def __len__(self):
        return len(self.b)

I believe this example makes it clearer.  I have no problem with allowing by
the way as it shows the power of python. I guess my current question is
would-py-lint-catch-this-cause-it-took-me-an-hour?

--
Brian Kelley          w 505 995-8188
Bioreason, Inc        f 505 995-8186
309 Johnson Av
Santa Fe, NM 87501    kelley at bioreason.com







More information about the Python-list mailing list