pychecker - sets.Set need to be overridden

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Istvan Albert

    pychecker - sets.Set need to be overridden

    Hello all,

    if I have this code:

    import sets

    class Foo:
    x = sets.Set()

    then pychecker says:

    test.py:4: Methods (__cmp__, __hash__) in sets.Set need to be overridden in a subclass

    I don't get this message. What is it trying to say, and why?

    Istvan.
  • wittempj@hotmail.com

    #2
    Re: pychecker - sets.Set need to be overridden

    mport sets

    class Foo:
    def __init__(self):
    self.x = sets.Set()

    x = Foo()
    print x, getattr(x, 'x')

    gives for me:
    <__main__.Foo instance at 0x00C578A0> Set([])
    on 2.4. on WinXP. What environment do you run in?

    Comment

    • Istvan Albert

      #3
      Re: pychecker - sets.Set need to be overridden

      wittempj@hotmai l.com wrote:
      [color=blue]
      > <__main__.Foo instance at 0x00C578A0> Set([])
      > on 2.4. on WinXP. What environment do you run in?[/color]

      I'm running it on cygwin,

      but still don't get it, why the warning?

      Istvan.


      Comment

      • Peter Otten

        #4
        Re: pychecker - sets.Set need to be overridden

        Istvan Albert wrote:
        [color=blue]
        > if I have this code:
        >
        > import sets
        >
        > class Foo:
        > x = sets.Set()
        >
        > then pychecker says:
        >
        > test.py:4: Methods (__cmp__, __hash__) in sets.Set need to be overridden
        > in a subclass
        >
        > I don't get this message. What is it trying to say, and why?[/color]

        The minimal example is actually

        import sets
        sets.Set()

        The Set class has implementations for __cmp__() and __hash__() that
        unconditionally raise an exception. pychecker assumes that these methods
        are "abstract", i. e. meant to be overriden by a subclass, and warns that
        you are instantiating an abstract base class, while the intention of the
        Set class author was to make Sets "uncomparab le" and unhashable by
        overriding the corresponding superclass methods.

        Peter

        Comment

        • wittempj@hotmail.com

          #5
          Re: pychecker - sets.Set need to be overridden

          I don't know pychecker, maybe there's something wrong with it as your
          code seems valid to me.

          Comment

          • Istvan Albert

            #6
            Re: pychecker - sets.Set need to be overridden

            Peter Otten wrote:
            [color=blue]
            > The Set class has implementations for __cmp__() and __hash__() that
            > unconditionally raise an exception. pychecker assumes that these methods
            > are "abstract", i. e. meant to be overriden by a subclass, and warns that
            > you are instantiating an abstract base class, while the intention of the[/color]

            I see. Thanks!

            Istvan.

            Comment

            Working...