TypeError: __new__() missing 2 required positional arguments: 'bases' and 'namespace

I am getting error in python console after ran python use.py // how bypass it???
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license()” for more information.

============= RESTART: C:\Users\LS\Desktop\use.py =============
Traceback (most recent call last):
  File "C:\Users\LS\Desktop\use.py", line 10, in <module>
    main()
  File "C:\Users\LS\Desktop\use.py", line 6, in main
    print( Polygon.EquilateralTriangle(6).area() )
**TypeError: __new__() missing 2 required positional arguments: 'bases' and 'namespace'**

# . use.py

import Polygon

def main():
    print( Polygon.EquilateralTriangle(6).area() )

main()

# Polygon.py

'''
Projects
P-2.39 Develop an inheritance hierarchy based upon a Polygon class that has
abstract methods area( ) and perimeter( ). Implement classes Triangle,
Quadrilateral, Pentagon, Hexagon, and Octagon that extend this base
class, with the obvious meanings for the area( ) and perimeter( ) methods.
Also implement classes, IsoscelesTriangle, EquilateralTriangle, Rectangle,
and Square, that have the appropriate inheritance relationships. Finally,
write a simple program that allows users to create polygons of the
various types and input their geometric dimensions, and the program then
outputs their area and perimeter. For extra effort, allow users to input
polygons by specifying their vertex coordinates and be able to test if two
such polygons are similar.

https://github.com/theJollySin/python_for_scientists/blob/master/classes/07_object_oriented_programming_2/lecture_07.md


https://github.com/theJollySin/python_for_scientists/blob/master/README.md



'''

from abc import ABCMeta, abstractmethod # need these definitions

class Polygon(ABCMeta):

    def __init__(self, lengths_of_sides):
        self.number_of_sides = len(lengths_of_sides)
        self.lengths_of_sides = [0] * [self.number_of_sides]
        assign_values_to_sides(self, lengths_of_sides)
    
    def print_num_sides(self):
        '''a quick, informational print statement'''
        print('There are ' + str(self.number_of_sides) + 'sides.')
        
    def assign_values_to_sides(self, lengths_of_sides):
        index = 0
        while index < len(lengths_of_sides):
            self.lengths_of_sides[index] = lengths_of_sides[index]
            index += 1

    @abstractmethod
    def area(self):
        '''Return the area of the polygon.'''
        
    @abstractmethod
    def perimeter(self):
        '''Return the perimeter of the polygon.'''


class Triangle(Polygon):

    def __init__(self, lengths_of_sides):
        Polygon.__init__(self, 3, lengths_of_sides)
    
    def area(self):
        '''return the area of the triangle using the semi-perimeter method'''
        a, b, c = self.lengths_of_sides
        # calculate the semi-perimeter
        s = (a + b + c) / 2
        return (s*(s-a)*(s-b)*(s-c)) ** 0.5
    
    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        # calculate the perimeter
        s = (lengths_of_sides[0] + lengths_of_sides[1] + lengths_of_sides[2])
        return s



class IsoscelesTriangle(Triangle):

    def __init__(self, side, base):  # [side, base]
        Polygon.__init__(self, 3, [side, side, base])
    
    def area(self):
        '''return the area of the triangle using the semi-perimeter method'''
        super().area();
    
    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        super().perimeter();


class EquilateralTriangle(Triangle):

    def __init__(self, side): # side
        Polygon.__init__(self, 3, [side, side, side])
    
    def area(self):
        '''return the area of the triangle using the semi-perimeter method'''
        super().area();
    
    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        super().perimeter();


        
class Pentagon(Polygon):

    def __init__(self, lengths_of_sides):
        Polygon.__init__(self, 5, lengths_of_sides)
    
    def area(self):
        x, y = self.lenghts_of_sides[0], self.lenghts_of_sides[1]
        return x * y

    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        # calculate the perimeter
        x, y = self.lenghts_of_sides
        return (x+y)*2


        
class Hexagon(Polygon):

    def __init__(self, lengths_of_sides):
        Polygon.__init__(self, 6, lengths_of_sides)
    
    def area(self):
        x, y = self.lenghts_of_sides[0], self.lenghts_of_sides[1]
        return x * y

    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        # calculate the perimeter
        x, y = self.lenghts_of_sides
        return (x+y)*2


        
class Octagon(Polygon):

    def __init__(self, lengths_of_sides):
        Polygon.__init__(self, 4, lengths_of_sides)
    
    def area(self):
        x, y = self.lenghts_of_sides[0], self.lenghts_of_sides[1]
        return x * y

    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        # calculate the perimeter
        x, y = self.lenghts_of_sides
        return (x+y)*2



        
class Quadrilateral(Polygon):

    def __init__(self, lengths_of_sides):  # [side1, side2]
        Polygon.__init__(self, 4, [lengths_of_sides[0],lengths_of_sides[1],lengths_of_sides[0],lengths_of_sides[1]])
    
    def area(self):
        x, y = self.lenghts_of_sides[0], self.lenghts_of_sides[1]
        return x * y

    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        # calculate the perimeter
        x, y = self.lenghts_of_sides
        return (x + y) * 2
    
        
class Rectangle(Quadrilateral):

    def __init__(self, lengths_of_sides):  # [side1, side2]
        Quadrilateral.__init__(self, lengths_of_sides)
    
    def area(self):
        x, y = self.lenghts_of_sides[0], self.lenghts_of_sides[1]
        return x * y

    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        # calculate the perimeter
        x, y = self.lenghts_of_sides
        return (x + y) * 2

    
class Square(Rectangle):

    def __init__(self, side):  
        Rectangle.__init__(self, [side, side])
    
    def area(self):
        x = self.lenghts_of_sides[0]
        return x * x

    def perimeter(self):
        '''Return the perimeter of the polygon.'''        
        # calculate the perimeter
        x = self.lenghts_of_sides[0]
        return x * 4

A couple of fixes:

  • from abc import ABC, abstractmethod. # not ABCMeta, which is where your error arises

  • assign_values_to_sides() in __init__ looks like it needs a “self.” prefix.

  • remove “self” as first argument when calling a method (several places)

  • defining a method which simply calls super() and the same method in its superclass is redundant

  • don’t use semicolons at the end of python statements (unless you’re stringing multiple of them on the same line - but don’t do that, it is a special case: command line one-lines for example)

  • use super().__init__ not class names directly

  • numerous typos: lenghts -> lengths

  • definitely needs a unit test, i think there are some logic errors in there as well. Better yet, write the unit test first and build your code against that (i.e. TDD)

  • I’ve inserted some asserts in places where it is logical to do so

  • for passing variable length arrays, consider using *args instead of passing arrays around. This should improve readability as well.

from abc import ABC, abstractmethod  # need these definitions


class Polygon(ABC):

    def __init__(self, lengths_of_sides):
        self.number_of_sides = len(lengths_of_sides)
        self.lengths_of_sides = [0] * self.number_of_sides
        self.assign_values_to_sides(lengths_of_sides)
    
    def print_num_sides(self):
        """a quick, informational print statement"""
        print('There are ' + str(self.number_of_sides) + 'sides.')
        
    def assign_values_to_sides(self, lengths_of_sides):
        index = 0
        while index < len(lengths_of_sides):
            self.lengths_of_sides[index] = lengths_of_sides[index]
            index += 1

    @abstractmethod
    def area(self):
        """Return the area of the polygon."""
        pass
        
    @abstractmethod
    def perimeter(self):
        """Return the perimeter of the polygon."""
        pass


class Triangle(Polygon):

    def __init__(self, lengths_of_sides):
        super().__init__(lengths_of_sides)
        assert 3, self.number_of_sides

    def area(self):
        """return the area of the triangle using the semi-perimeter method"""
        a, b, c = self.lengths_of_sides
        # calculate the semi-perimeter
        s = (a + b + c) / 2
        return (s*(s-a)*(s-b)*(s-c)) ** 0.5
    
    def perimeter(self):
        """Return the perimeter of the polygon."""        
        # calculate the perimeter
        s = (self.lengths_of_sides[0] + self.lengths_of_sides[1] + self.lengths_of_sides[2])
        return s


class IsoscelesTriangle(Triangle):

    def __init__(self, side, base):  # [side, base]
        super().__init__([side, side, base])


class EquilateralTriangle(Triangle):

    def __init__(self, side):  # side
        super().__init__([side, side, side])

        
class Pentagon(Polygon):

    def __init__(self, lengths_of_sides):
        super().__init__(lengths_of_sides)
        assert 5, self.number_of_sides
    
    def area(self):
        x, y = self.lengths_of_sides[0], self.lengths_of_sides[1]
        return x * y

    def perimeter(self):
        """Return the perimeter of the polygon."""        
        # calculate the perimeter
        x, y = self.lengths_of_sides
        return (x+y)*2

        
class Hexagon(Polygon):

    def __init__(self, lengths_of_sides):
        super().__init__(lengths_of_sides)
        assert 6, self.number_of_sides

    def area(self):
        x, y = self.lengths_of_sides[0], self.lengths_of_sides[1]
        return x * y

    def perimeter(self):
        """Return the perimeter of the polygon."""        
        # calculate the perimeter
        x, y = self.lengths_of_sides
        return (x+y)*2


class Octagon(Polygon):

    def __init__(self, lengths_of_sides):
        super().__init__(lengths_of_sides)
        assert 8, self.number_of_sides

    def area(self):
        x, y = self.lengths_of_sides[0], self.lengths_of_sides[1]
        return x * y

    def perimeter(self):
        """Return the perimeter of the polygon."""        
        # calculate the perimeter
        x, y = self.lengths_of_sides
        return (x+y)*2


class Quadrilateral(Polygon):

    def __init__(self, lengths_of_sides):  # [side1, side2]
        super().__init__([lengths_of_sides[0], lengths_of_sides[1], lengths_of_sides[0], lengths_of_sides[1]])
        assert 4, self.number_of_sides

    def area(self):
        x, y = self.lengths_of_sides[0], self.lengths_of_sides[1]
        return x * y

    def perimeter(self):
        """Return the perimeter of the polygon."""        
        # calculate the perimeter
        x, y = self.lengths_of_sides
        return (x + y) * 2
    
        
class Rectangle(Quadrilateral):

    def __init__(self, lengths_of_sides):  # [side1, side2]
        super().__init__(lengths_of_sides)
    
    def area(self):
        x, y = self.lengths_of_sides[0], self.lengths_of_sides[1]
        return x * y

    def perimeter(self):
        """Return the perimeter of the polygon."""        
        # calculate the perimeter
        x, y = self.lengths_of_sides
        return (x + y) * 2

    
class Square(Rectangle):

    def __init__(self, side):  
        super().__init__([side, side])
    
    def area(self):
        x = self.lengths_of_sides[0]
        return x * x

    def perimeter(self):
        """Return the perimeter of the polygon."""        
        # calculate the perimeter
        x = self.lengths_of_sides[0]
        return x * 4