LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python: inheritance not working as expected. Problem with my code? (https://www.linuxquestions.org/questions/programming-9/python-inheritance-not-working-as-expected-problem-with-my-code-931617/)

BrianK 02-27-2012 04:45 PM

python: inheritance not working as expected. Problem with my code?
 
I'm writing a layer that goes on top of a 3rd party module. My class inherits from a class in the 3rd party module. That moule [eventually] inherits from dict. The layout looks like:

Code:

class 3rdPartyParent(dict):
 ...

class 3rdPartyObject(3rdPartyParent):
...

class MyClass(3rdPartyObject):
    ...
    @property
    def frames(self):
        if not self.__frames:
            self.__updateFrames()
        return self.__frames
    ...

However, when I try to use my defined "frames" property (by my_instance = MyClass(); my_instance.frames), I'm getting a result from the 3rdPartyParent's __getattr__ (which happens to raise an error that the requested attribute doesn't exist). Not quite sure why that would be. I expect that it would execute my code, but it doesn't. Any ideas?

ta0kira 03-04-2012 12:21 PM

Is it frames that isn't found, or is it __frames or __updateFrames?
Kevin Barry

BrianK 03-05-2012 07:53 PM

Oops... forgot to update this thread.

It was "frames" that wasn't found - the property, not "__frames" the variable. The problem had something to do with a coding error that wasn't caught by the interpreter. Unfortunately, I can't say exactly what it was, but I was in the middle of a rather large edit when this started coming up. After checking over the property time & time again, I pushed through to finish the edit, checked again & it was working as expected.

dugan 03-06-2012 09:21 AM

Does it work without the property decorator? Python's property inheritance is one of the things that works funny.


All times are GMT -5. The time now is 09:29 PM.