summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2023-03-11 23:29:36 +0100
committerGitHub <noreply@github.com>2023-03-11 23:29:36 +0100
commit16dd28d1692e097a819d9d4bdf6f80c9744b460a (patch)
tree785a99200615ad771c2d39fb81d60cb01f33394b
parent575319bb87de73114203c5a49edd3ae18aace8c7 (diff)
downloadpylint-git-16dd28d1692e097a819d9d4bdf6f80c9744b460a.tar.gz
Add Python 3.8+ `asyncSetUp` to "defining-attr-methods" list (#8403) (#8438)
(cherry picked from commit b312b9a66472e17d02461258d2156d670481a7f6) Co-authored-by: Samuel FORESTIER <HorlogeSkynet@users.noreply.github.com>
-rw-r--r--doc/user_guide/configuration/all-options.rst4
-rw-r--r--doc/whatsnew/fragments/8403.false_positive5
-rw-r--r--examples/pylintrc1
-rw-r--r--examples/pyproject.toml2
-rw-r--r--pylint/checkers/classes/class_checker.py8
-rw-r--r--tests/functional/a/attribute_defined_outside_init_py38.py9
-rw-r--r--tests/functional/a/attribute_defined_outside_init_py38.rc5
7 files changed, 30 insertions, 4 deletions
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": "<method names>",
"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