Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Commonmark migration
Source Link

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent() ###Solution(thanks to @Paul McGuire's answer):

Solution(thanks to @Paul McGuire's answer):

class Child(object):
 def __init__(self):
 self.obj = generateParent()
 def __getattr__(self, attr):
 return getattr(self.obj, attr)

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent() ###Solution(thanks to @Paul McGuire's answer):

class Child(object):
 def __init__(self):
 self.obj = generateParent()
 def __getattr__(self, attr):
 return getattr(self.obj, attr)

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent()

Solution(thanks to @Paul McGuire's answer):

class Child(object):
 def __init__(self):
 self.obj = generateParent()
 def __getattr__(self, attr):
 return getattr(self.obj, attr)
added solution
Source Link
elyase
  • 41.2k
  • 12
  • 121
  • 123

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent() ###Solution(thanks to @Paul McGuire's answer):

class Child(object):
 def __init__(self):
 self.obj = generateParent()
 def __getattr__(self, attr):
 return getattr(self.obj, attr)

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent()

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent() ###Solution(thanks to @Paul McGuire's answer):

class Child(object):
 def __init__(self):
 self.obj = generateParent()
 def __getattr__(self, attr):
 return getattr(self.obj, attr)
added 3 characters in body
Source Link
elyase
  • 41.2k
  • 12
  • 121
  • 123

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent()

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither Parent nor generateParent()

I have a function which return instances of the class Parent:

def generateParent():
 do_stuff
 return Parent(some_parameters)

Now I want to init a subclass of Parent with the results of a call to generateParent():

class Child(Parent):
 def __new__():
 return generateParent(some_other_parameters) 

The problem is, when I override some methods from Parent in Child and then call them in instances of Child in my program, the original Parent method gets called instead of the new one from Child. Am I doing something wrong here? Am I using the correct design here for my task?

EDIT: I don't have access neither to Parent nor generateParent()

edited title
Link
elyase
  • 41.2k
  • 12
  • 121
  • 123
Loading
added 65 characters in body
Source Link
elyase
  • 41.2k
  • 12
  • 121
  • 123
Loading
Source Link
elyase
  • 41.2k
  • 12
  • 121
  • 123
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /