Misleading Python error message

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Kelley

    Misleading Python error message

    I accidentally derived a class from a module (types instead of
    types.Dicttype)
    [color=blue][color=green][color=darkred]
    >>> import types
    >>> class f(types): pass[/color][/color][/color]
    ....
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: function takes at most 2 arguments (3 given)

    Shouldn't this report something like (TypeError: can't subclass from a
    module) It goes to the right line, but I coudn't see where the function
    was being called :)

    Brian


  • Dennis Lee Bieber

    #2
    Re: Misleading Python error message

    Brian Kelley fed this fish to the penguins on Wednesday 19 November
    2003 12:02 pm:

    [color=blue]
    > Shouldn't this report something like (TypeError: can't subclass from a
    > module) It goes to the right line, but I coudn't see where the
    > function was being called :)
    >[/color]
    Which version?

    Python 2.2 (#1, Nov 5 2002, 15:43:24)
    [GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386
    Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
    >>> import types
    >>> class f(types):[/color][/color][/color]
    .... pass
    ....[color=blue][color=green][color=darkred]
    >>> class f(types): pass[/color][/color][/color]
    ....[color=blue][color=green][color=darkred]
    >>>
    >>> dir(f)[/color][/color][/color]
    [][color=blue][color=green][color=darkred]
    >>> t = f()[/color][/color][/color]
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: 'module' object is not callable[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    --[color=blue]
    > =============== =============== =============== =============== == <
    > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
    > wulfraed@dm.net | Bestiaria Support Staff <
    > =============== =============== =============== =============== == <
    > Bestiaria Home Page: http://www.beastie.dm.net/ <
    > Home Page: http://www.dm.net/~wulfraed/ <[/color]

    Comment

    • Andrew Dalke

      #3
      Re: Misleading Python error message

      Brian Kelley:[color=blue]
      > I accidentally derived a class from a module (types instead of
      > types.Dicttype)[/color]
      ...[color=blue]
      > TypeError: function takes at most 2 arguments (3 given)
      >
      > Shouldn't this report something like (TypeError: can't subclass from a
      > module) It goes to the right line, but I coudn't see where the function
      > was being called :)[/color]

      Strangely enough, I asked this question last week, titled "class with
      invalid base class". (Strange because Brian and I used to work
      together but there's no causation for this correlation in questions.)

      Merging answers from Thomas Heller and Michael Hudson

      If the type(base class) is callable, which is true for all type objects
      since 2.2, then it's called with three arguments: The name of
      the new class, a tuple of the bases, and a dictionary.

      However, ModuleType only takes two parameters, not three,
      hence the TypeError.

      I completely agree that the error message is inexplicable to all
      but those whose heads have exploded.

      Andrew
      dalke@dalkescie ntific.com


      Comment

      • Peter Hansen

        #4
        Re: Misleading Python error message

        Dennis Lee Bieber wrote:[color=blue]
        >
        > Brian Kelley fed this fish to the penguins on Wednesday 19 November
        > 2003 12:02 pm:
        >[color=green]
        > > Shouldn't this report something like (TypeError: can't subclass from a
        > > module) It goes to the right line, but I coudn't see where the
        > > function was being called :)
        > >[/color]
        > Which version?[/color]

        Python 2.3, of course, as a result of the new types stuff.

        -Peter

        Comment

        Working...