1 Replies - 2548 Views - Last Post: 28 February 2013 - 03:09 AM Rate Topic: -----

#1 Static Hazard   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 25-November 09

Should return None, not 'list'

Posted 28 February 2013 - 02:11 AM

I am designing a constructor that takes in one parameter, which is the size of the container (to be used later). It creates a container (empty list will suffice), and returns the generated container (to be used by other methods, for adding and such). The container isn't populated by the constructor, just generated.

I am getting a strange error that I haven't seen, which is:

__init__() should return None, not 'list'

Surely this has something to do with my case with "None" (that I had problems with earlier). I want to set the capacity to 50 if no capacity is entered (so for example, if container.Container() was called, the size would be 50, but if container.Container(25) was called, it would be 25).

Either way, an empty list should be returned, but it won't let me!

    def __init__(self, capacity = None):
        self.values = []
        if capacity is None:
            self.theCapacity = 50
            self.theCapacity = capacity
        if(self.theCapacity < 1 or isinstance(self.theCapacity, int) == False):
            raise ValueError("Container.__init__: invalid capacity")
        return self.values

Unit test:
def test1ShouldCreateInstance(self):
        self.assertIsInstance(container.Container(25), container.Container)

Can anyone lend a fresh pair of eyes?

Is This A Good Question/Topic? 0
  • +

Replies To: Should return None, not 'list'

#2 Mekire   User is offline

  • D.I.C Head

Reputation: 118
  • View blog
  • Posts: 216
  • Joined: 11-January 13

Re: Should return None, not 'list'

Posted 28 February 2013 - 03:09 AM

Um... so... the __init__() should return None, not 'list'

Now do what the nice error message says and let it return none.
You don't return things with init.
Just delete that line.

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1