1

I have just discovered a strange behaviour of arguments of init while subclkassing in python. Having a simple code :

class my_frset (frozenset):

def __init__(self, st, inst):

    super().__init__(st)
    self.inst = inst

As i try to init an instance like :

a = my_frset({1,2,3} , 4)

i got an exception:

    a = my_frset({1,2,3} , 4)
TypeError: my_frset expected at most 1 arguments, got 2

So my_frset wants to have 1 argument, But if i do like :

    a = my_frset({1,2,3})
TypeError: __init__() missing 1 required positional argument: 'inst'

So it does not want to have either 1 not 2 argument, what is going on there ?

user8426627
  • 903
  • 1
  • 9
  • 19
  • related: https://stackoverflow.com/questions/4850370/inheriting-behaviours-for-set-and-frozenset-seem-to-differ. `frozenset` defines `__new__` that intercept construction. You have to redefine `__new__` too – Jean-François Fabre May 26 '19 at 15:02
  • ohh i ll just have then incapsulation self.fset = frozenset(fset) cause that is a pile of crap there with strange construction – user8426627 May 26 '19 at 17:59

0 Answers0