From 46a96978eb3be5d7cd7689a9614c9a8a25dc6d2a Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 16 Aug 2021 18:45:14 +0200 Subject: Merge abstract_class_instantiated in the same file --- .../a/abstract/abstract_class_instantiated.py | 143 +++++++++++++++++++++ .../a/abstract/abstract_class_instantiated.txt | 6 + .../a/abstract/abstract_class_instantiated_py3.py | 128 ------------------ .../a/abstract/abstract_class_instantiated_py3.rc | 2 - .../a/abstract/abstract_class_instantiated_py3.txt | 5 - .../a/abstract/abstract_class_instantiated_py34.py | 19 --- .../a/abstract/abstract_class_instantiated_py34.rc | 2 - .../abstract/abstract_class_instantiated_py34.txt | 1 - 8 files changed, 149 insertions(+), 157 deletions(-) create mode 100644 tests/functional/a/abstract/abstract_class_instantiated.py create mode 100644 tests/functional/a/abstract/abstract_class_instantiated.txt delete mode 100644 tests/functional/a/abstract/abstract_class_instantiated_py3.py delete mode 100644 tests/functional/a/abstract/abstract_class_instantiated_py3.rc delete mode 100644 tests/functional/a/abstract/abstract_class_instantiated_py3.txt delete mode 100644 tests/functional/a/abstract/abstract_class_instantiated_py34.py delete mode 100644 tests/functional/a/abstract/abstract_class_instantiated_py34.rc delete mode 100644 tests/functional/a/abstract/abstract_class_instantiated_py34.txt diff --git a/tests/functional/a/abstract/abstract_class_instantiated.py b/tests/functional/a/abstract/abstract_class_instantiated.py new file mode 100644 index 000000000..85facb540 --- /dev/null +++ b/tests/functional/a/abstract/abstract_class_instantiated.py @@ -0,0 +1,143 @@ +"""Check that instantiating a class with +`abc.ABCMeta` as metaclass fails if it defines +abstract methods. +""" + +# pylint: disable=too-few-public-methods, missing-docstring +# pylint: disable=abstract-method, import-error, useless-object-inheritance + +import abc +import weakref +from lala import Bala + + +class GoodClass(object, metaclass=abc.ABCMeta): + pass + +class SecondGoodClass(object, metaclass=abc.ABCMeta): + def test(self): + """ do nothing. """ + +class ThirdGoodClass(object, metaclass=abc.ABCMeta): + """ This should not raise the warning. """ + def test(self): + raise NotImplementedError() + +class BadClass(object, metaclass=abc.ABCMeta): + @abc.abstractmethod + def test(self): + """ do nothing. """ + +class SecondBadClass(object, metaclass=abc.ABCMeta): + @property + @abc.abstractmethod + def test(self): + """ do nothing. """ + +class ThirdBadClass(SecondBadClass): + pass + + +class Structure(object, metaclass=abc.ABCMeta): + @abc.abstractmethod + def __iter__(self): + pass + @abc.abstractmethod + def __len__(self): + pass + @abc.abstractmethod + def __contains__(self, _): + pass + @abc.abstractmethod + def __hash__(self): + pass + +class Container(Structure): + def __contains__(self, _): + pass + +class Sizable(Structure): + def __len__(self): + return 42 + +class Hashable(Structure): + __hash__ = 42 + + +class Iterator(Structure): + def keys(self): # pylint: disable=no-self-use + return iter([1, 2, 3]) + + __iter__ = keys + +class AbstractSizable(Structure): + @abc.abstractmethod + def length(self): + pass + __len__ = length + +class NoMroAbstractMethods(Container, Iterator, Sizable, Hashable): + pass + +class BadMroAbstractMethods(Container, Iterator, AbstractSizable): + pass + +class SomeMetaclass(metaclass=abc.ABCMeta): + + @abc.abstractmethod + def prop(self): + pass + +class FourthGoodClass(SomeMetaclass): + """Don't consider this abstract if some attributes are + there, but can't be inferred. + """ + prop = Bala # missing + + +def main(): + """ do nothing """ + GoodClass() + SecondGoodClass() + ThirdGoodClass() + FourthGoodClass() + weakref.WeakKeyDictionary() + weakref.WeakValueDictionary() + NoMroAbstractMethods() + + BadMroAbstractMethods() # [abstract-class-instantiated] + BadClass() # [abstract-class-instantiated] + SecondBadClass() # [abstract-class-instantiated] + ThirdBadClass() # [abstract-class-instantiated] + + +if 1: # pylint: disable=using-constant-test + class FourthBadClass(object, metaclass=abc.ABCMeta): + + def test(self): + pass +else: + class FourthBadClass(object, metaclass=abc.ABCMeta): + + @abc.abstractmethod + def test(self): + pass + + +def main2(): + FourthBadClass() # [abstract-class-instantiated] + + +class BadClassTwo(abc.ABC): + """ + Check that instantiating a class with `abc.ABCMeta` as ancestor fails if it + defines abstract methods. + """ + @abc.abstractmethod + def test(self): + pass + + +def main_two(): + """ do nothing """ + BadClassTwo() # [abstract-class-instantiated] diff --git a/tests/functional/a/abstract/abstract_class_instantiated.txt b/tests/functional/a/abstract/abstract_class_instantiated.txt new file mode 100644 index 000000000..757528d01 --- /dev/null +++ b/tests/functional/a/abstract/abstract_class_instantiated.txt @@ -0,0 +1,6 @@ +abstract-class-instantiated:108:4:main:Abstract class 'BadMroAbstractMethods' with abstract methods instantiated:HIGH +abstract-class-instantiated:109:4:main:Abstract class 'BadClass' with abstract methods instantiated:HIGH +abstract-class-instantiated:110:4:main:Abstract class 'SecondBadClass' with abstract methods instantiated:HIGH +abstract-class-instantiated:111:4:main:Abstract class 'ThirdBadClass' with abstract methods instantiated:HIGH +abstract-class-instantiated:128:4:main2:Abstract class 'FourthBadClass' with abstract methods instantiated:HIGH +abstract-class-instantiated:143:4:main_two:Abstract class 'BadClassTwo' with abstract methods instantiated:HIGH diff --git a/tests/functional/a/abstract/abstract_class_instantiated_py3.py b/tests/functional/a/abstract/abstract_class_instantiated_py3.py deleted file mode 100644 index bf2ef2e03..000000000 --- a/tests/functional/a/abstract/abstract_class_instantiated_py3.py +++ /dev/null @@ -1,128 +0,0 @@ -"""Check that instantiating a class with -`abc.ABCMeta` as metaclass fails if it defines -abstract methods. -""" - -# pylint: disable=too-few-public-methods, missing-docstring -# pylint: disable=abstract-method, import-error, useless-object-inheritance - -import abc -import weakref -from lala import Bala - - -class GoodClass(object, metaclass=abc.ABCMeta): - pass - -class SecondGoodClass(object, metaclass=abc.ABCMeta): - def test(self): - """ do nothing. """ - -class ThirdGoodClass(object, metaclass=abc.ABCMeta): - """ This should not raise the warning. """ - def test(self): - raise NotImplementedError() - -class BadClass(object, metaclass=abc.ABCMeta): - @abc.abstractmethod - def test(self): - """ do nothing. """ - -class SecondBadClass(object, metaclass=abc.ABCMeta): - @property - @abc.abstractmethod - def test(self): - """ do nothing. """ - -class ThirdBadClass(SecondBadClass): - pass - - -class Structure(object, metaclass=abc.ABCMeta): - @abc.abstractmethod - def __iter__(self): - pass - @abc.abstractmethod - def __len__(self): - pass - @abc.abstractmethod - def __contains__(self, _): - pass - @abc.abstractmethod - def __hash__(self): - pass - -class Container(Structure): - def __contains__(self, _): - pass - -class Sizable(Structure): - def __len__(self): - return 42 - -class Hashable(Structure): - __hash__ = 42 - - -class Iterator(Structure): - def keys(self): # pylint: disable=no-self-use - return iter([1, 2, 3]) - - __iter__ = keys - -class AbstractSizable(Structure): - @abc.abstractmethod - def length(self): - pass - __len__ = length - -class NoMroAbstractMethods(Container, Iterator, Sizable, Hashable): - pass - -class BadMroAbstractMethods(Container, Iterator, AbstractSizable): - pass - -class SomeMetaclass(metaclass=abc.ABCMeta): - - @abc.abstractmethod - def prop(self): - pass - -class FourthGoodClass(SomeMetaclass): - """Don't consider this abstract if some attributes are - there, but can't be inferred. - """ - prop = Bala # missing - - -def main(): - """ do nothing """ - GoodClass() - SecondGoodClass() - ThirdGoodClass() - FourthGoodClass() - weakref.WeakKeyDictionary() - weakref.WeakValueDictionary() - NoMroAbstractMethods() - - BadMroAbstractMethods() # [abstract-class-instantiated] - BadClass() # [abstract-class-instantiated] - SecondBadClass() # [abstract-class-instantiated] - ThirdBadClass() # [abstract-class-instantiated] - - -if 1: # pylint: disable=using-constant-test - class FourthBadClass(object, metaclass=abc.ABCMeta): - - def test(self): - pass -else: - class FourthBadClass(object, metaclass=abc.ABCMeta): - - @abc.abstractmethod - def test(self): - pass - - -def main2(): - FourthBadClass() # [abstract-class-instantiated] diff --git a/tests/functional/a/abstract/abstract_class_instantiated_py3.rc b/tests/functional/a/abstract/abstract_class_instantiated_py3.rc deleted file mode 100644 index c093be204..000000000 --- a/tests/functional/a/abstract/abstract_class_instantiated_py3.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -min_pyver=3.0 diff --git a/tests/functional/a/abstract/abstract_class_instantiated_py3.txt b/tests/functional/a/abstract/abstract_class_instantiated_py3.txt deleted file mode 100644 index f08baf86f..000000000 --- a/tests/functional/a/abstract/abstract_class_instantiated_py3.txt +++ /dev/null @@ -1,5 +0,0 @@ -abstract-class-instantiated:108:4:main:Abstract class 'BadMroAbstractMethods' with abstract methods instantiated -abstract-class-instantiated:109:4:main:Abstract class 'BadClass' with abstract methods instantiated -abstract-class-instantiated:110:4:main:Abstract class 'SecondBadClass' with abstract methods instantiated -abstract-class-instantiated:111:4:main:Abstract class 'ThirdBadClass' with abstract methods instantiated -abstract-class-instantiated:128:4:main2:Abstract class 'FourthBadClass' with abstract methods instantiated diff --git a/tests/functional/a/abstract/abstract_class_instantiated_py34.py b/tests/functional/a/abstract/abstract_class_instantiated_py34.py deleted file mode 100644 index e24ad28f1..000000000 --- a/tests/functional/a/abstract/abstract_class_instantiated_py34.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -Check that instantiating a class with `abc.ABCMeta` as ancestor fails if it -defines abstract methods. -""" - -# pylint: disable=too-few-public-methods, missing-docstring, no-init - -import abc - - - -class BadClass(abc.ABC): - @abc.abstractmethod - def test(self): - pass - -def main(): - """ do nothing """ - BadClass() # [abstract-class-instantiated] diff --git a/tests/functional/a/abstract/abstract_class_instantiated_py34.rc b/tests/functional/a/abstract/abstract_class_instantiated_py34.rc deleted file mode 100644 index f400a86e6..000000000 --- a/tests/functional/a/abstract/abstract_class_instantiated_py34.rc +++ /dev/null @@ -1,2 +0,0 @@ -[testoptions] -min_pyver=3.4 diff --git a/tests/functional/a/abstract/abstract_class_instantiated_py34.txt b/tests/functional/a/abstract/abstract_class_instantiated_py34.txt deleted file mode 100644 index 88d0ef32c..000000000 --- a/tests/functional/a/abstract/abstract_class_instantiated_py34.txt +++ /dev/null @@ -1 +0,0 @@ -abstract-class-instantiated:19:4:main:Abstract class 'BadClass' with abstract methods instantiated -- cgit v1.2.1