mkorpela / overrides

A decorator to automatically detect mismatch when overriding a method
Apache License 2.0
261 stars 32 forks source link

EnforceOverrides fails on nested classes #86

Open ashwin153 opened 3 years ago

ashwin153 commented 3 years ago

If you run this in a REPL it fails (Python 3.8). I've stared at this for an hour and I have no idea why it fails. Do you guys have any ideas?

import overrides

class Foo:
    class Bar(overrides.EnforceOverrides):
        def to_dict(self): 
            pass
    class Car(Bar):
        @overrides.overrides
        def to_dict(self):
            pass

To be clear, this works fine.

class Foo:
    class Bar:
        def to_dict(self): 
            pass
    class Car(Bar):
        def to_dict(self):
            pass
hubertqtf commented 2 years ago

I have same issue

class Outer(object):
    class Inner(object):
             pass

class ChildOuter(Outer):
     class Inner(Outer.Inner):
            pass

this doesn't work as well

mkorpela commented 2 years ago

This currently works

from overrides import overrides

class Outer(object):
    class Inner(object):
        pass

class ChildOuter(Outer):
    @overrides
    class Inner(Outer.Inner):
        pass
hubertqtf commented 2 years ago

This currently works

from overrides import overrides

class Outer(object):
    class Inner(object):
        pass

class ChildOuter(Outer):
    @overrides
    class Inner(Outer.Inner):
        pass

Awesome! This may look like narrow case, but in case of web automation, where code resembles page layout - i use it quite a lot! My worst case was to get data from a graph, that has inner dots to hover, that opened a tooltip, that had those data, so 3 times nested classes just for that graph... and all svg elements! It was a nightmare, but currently i can fetch those data and even self-recover in case of mis-hover or any other interruption... Nevertheless, as always, thank you for support and I am glad that code continues to improve! Have a nice day! Hubert