diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2020-03-07 17:22:47 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2020-03-07 17:22:47 +0100 |
commit | 00bcf7b817ed459ee617b8af8843aca18d72fe04 (patch) | |
tree | 5dcb7740a4edd1515840f2f6a3d73e28457bf255 /tests/testdata/python3 | |
parent | 04f5853b42f3c886fc7a3b553e32f1d1bf21419b (diff) | |
download | astroid-git-00bcf7b817ed459ee617b8af8843aca18d72fe04.tar.gz |
Prevent a recursion error to happen when inferring the declared metaclass of a class
Close #749
Diffstat (limited to 'tests/testdata/python3')
3 files changed, 20 insertions, 0 deletions
diff --git a/tests/testdata/python3/data/metaclass_recursion/__init__.py b/tests/testdata/python3/data/metaclass_recursion/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/testdata/python3/data/metaclass_recursion/__init__.py diff --git a/tests/testdata/python3/data/metaclass_recursion/monkeypatch.py b/tests/testdata/python3/data/metaclass_recursion/monkeypatch.py new file mode 100644 index 00000000..757bb3f8 --- /dev/null +++ b/tests/testdata/python3/data/metaclass_recursion/monkeypatch.py @@ -0,0 +1,17 @@ +# https://github.com/PyCQA/astroid/issues/749 +# Not an actual module but allows us to reproduce the issue +from tests.testdata.python3.data.metaclass_recursion import parent + +class MonkeyPatchClass(parent.OriginalClass): + _original_class = parent.OriginalClass + + @classmethod + def patch(cls): + if parent.OriginalClass != MonkeyPatchClass: + cls._original_class = parent.OriginalClass + parent.OriginalClass = MonkeyPatchClass + + @classmethod + def unpatch(cls): + if parent.OriginalClass == MonkeyPatchClass: + parent.OriginalClass = cls._original_class diff --git a/tests/testdata/python3/data/metaclass_recursion/parent.py b/tests/testdata/python3/data/metaclass_recursion/parent.py new file mode 100644 index 00000000..5cff73e0 --- /dev/null +++ b/tests/testdata/python3/data/metaclass_recursion/parent.py @@ -0,0 +1,3 @@ +# https://github.com/PyCQA/astroid/issues/749 +class OriginalClass: + pass |