Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Should return None, not 'list'

$
0
0
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
        else:
            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?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>