From 16dd28d1692e097a819d9d4bdf6f80c9744b460a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 11 Mar 2023 23:29:36 +0100 Subject: Add Python 3.8+ `asyncSetUp` to "defining-attr-methods" list (#8403) (#8438) (cherry picked from commit b312b9a66472e17d02461258d2156d670481a7f6) Co-authored-by: Samuel FORESTIER --- doc/user_guide/configuration/all-options.rst | 4 ++-- doc/whatsnew/fragments/8403.false_positive | 5 +++++ examples/pylintrc | 1 + examples/pyproject.toml | 2 +- pylint/checkers/classes/class_checker.py | 8 +++++++- tests/functional/a/attribute_defined_outside_init_py38.py | 9 +++++++++ tests/functional/a/attribute_defined_outside_init_py38.rc | 5 +++++ 7 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 doc/whatsnew/fragments/8403.false_positive create mode 100644 tests/functional/a/attribute_defined_outside_init_py38.py create mode 100644 tests/functional/a/attribute_defined_outside_init_py38.rc diff --git a/doc/user_guide/configuration/all-options.rst b/doc/user_guide/configuration/all-options.rst index 13d67c280..2cbc3f483 100644 --- a/doc/user_guide/configuration/all-options.rst +++ b/doc/user_guide/configuration/all-options.rst @@ -626,7 +626,7 @@ Standard Checkers """"""""""""""""""""""" *List of method names used to declare (i.e. assign) instance attributes.* -**Default:** ``('__init__', '__new__', 'setUp', '__post_init__')`` +**Default:** ``('__init__', '__new__', 'setUp', 'asyncSetUp', '__post_init__')`` --exclude-protected @@ -663,7 +663,7 @@ Standard Checkers [tool.pylint.classes] check-protected-access-in-special-methods = false - defining-attr-methods = ["__init__", "__new__", "setUp", "__post_init__"] + defining-attr-methods = ["__init__", "__new__", "setUp", "asyncSetUp", "__post_init__"] exclude-protected = ["_asdict", "_fields", "_replace", "_source", "_make", "os._exit"] diff --git a/doc/whatsnew/fragments/8403.false_positive b/doc/whatsnew/fragments/8403.false_positive new file mode 100644 index 000000000..bfa34d17d --- /dev/null +++ b/doc/whatsnew/fragments/8403.false_positive @@ -0,0 +1,5 @@ +Adds ``asyncSetUp`` to the default ``defining-attr-methods`` list to silence +``attribute-defined-outside-init`` warning when using +``unittest.IsolatedAsyncioTestCase``. + +Refs #8403 diff --git a/examples/pylintrc b/examples/pylintrc index 70c5ff87c..16284083e 100644 --- a/examples/pylintrc +++ b/examples/pylintrc @@ -260,6 +260,7 @@ check-protected-access-in-special-methods=no defining-attr-methods=__init__, __new__, setUp, + asyncSetUp, __post_init__ # List of member names, which should be excluded from the protected access diff --git a/examples/pyproject.toml b/examples/pyproject.toml index 1608d2cbb..f9a493c89 100644 --- a/examples/pyproject.toml +++ b/examples/pyproject.toml @@ -226,7 +226,7 @@ variable-naming-style = "snake_case" # check-protected-access-in-special-methods = # List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods = ["__init__", "__new__", "setUp", "__post_init__"] +defining-attr-methods = ["__init__", "__new__", "setUp", "asyncSetUp", "__post_init__"] # List of member names, which should be excluded from the protected access # warning. diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index bf0ab8ba6..e09df1706 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -778,7 +778,13 @@ class ClassChecker(BaseChecker): ( "defining-attr-methods", { - "default": ("__init__", "__new__", "setUp", "__post_init__"), + "default": ( + "__init__", + "__new__", + "setUp", + "asyncSetUp", + "__post_init__", + ), "type": "csv", "metavar": "", "help": "List of method names used to declare (i.e. assign) \ diff --git a/tests/functional/a/attribute_defined_outside_init_py38.py b/tests/functional/a/attribute_defined_outside_init_py38.py new file mode 100644 index 000000000..7e93d1d29 --- /dev/null +++ b/tests/functional/a/attribute_defined_outside_init_py38.py @@ -0,0 +1,9 @@ +# pylint: disable=missing-docstring + +import unittest + + +class AsyncioTestCase(unittest.IsolatedAsyncioTestCase): + + async def asyncSetUp(self): + self.i = 42 diff --git a/tests/functional/a/attribute_defined_outside_init_py38.rc b/tests/functional/a/attribute_defined_outside_init_py38.rc new file mode 100644 index 000000000..1bfb860e8 --- /dev/null +++ b/tests/functional/a/attribute_defined_outside_init_py38.rc @@ -0,0 +1,5 @@ +[main] +load-plugins=pylint.extensions.typing + +[testoptions] +min_pyver=3.8 -- cgit v1.2.1