Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc_inherit doesn't work with two levels of sub-classing #20

Open
rmjarvis opened this issue Oct 16, 2017 · 0 comments
Open

doc_inherit doesn't work with two levels of sub-classing #20

rmjarvis opened this issue Oct 16, 2017 · 0 comments

Comments

@rmjarvis
Copy link

rmjarvis commented Oct 16, 2017

I'm trying to get the doc_inherit recipe (576862) to work with my classes, and the problem is that sometimes I have classes that go 2 levels down from the base class, rather than just one. This leads to an infinite recursion when the middle layer uses doc_inherit for a method.

Here is a minimal case that reproduces my problem:

from recipe_576862 import doc_inherit

class Base(object):

    def foo(self):
        "Base class foo"
        pass

class Mid(Base):

    @doc_inherit
    def foo(self):
        # Should inherit doc string from Base
        pass

class Final(Mid):

    def __init__(self): pass

obj = Final()
obj.foo()

The output is:

python doc-inherit-bug.py 
Traceback (most recent call last):
  File "doc-inherit-bug.py", line 22, in <module>
    obj.foo()
  File "/Users/Mike/Downloads/recipe_576862.py", line 34, in __get__
    return self.get_with_inst(obj, cls)
  File "/Users/Mike/Downloads/recipe_576862.py", line 40, in get_with_inst
    overridden = getattr(super(cls, obj), self.name, None)
[snip]
  File "/Users/Mike/Downloads/recipe_576862.py", line 34, in __get__
    return self.get_with_inst(obj, cls)
  File "/Users/Mike/Downloads/recipe_576862.py", line 40, in get_with_inst
    overridden = getattr(super(cls, obj), self.name, None)
RuntimeError: maximum recursion depth exceeded while calling a Python object

Unfortunately, I don't understand python's super well enough to figure out how to fix it. Anyone have an idea how the recipe could be tweaked to allow this use case?

Thanks so much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant