Skip to content

Commit 16dd28d

Browse files
Add Python 3.8+ asyncSetUp to "defining-attr-methods" list (#8403) (#8438)
(cherry picked from commit b312b9a) Co-authored-by: Samuel FORESTIER <[email protected]>
1 parent 575319b commit 16dd28d

File tree

7 files changed

+30
-4
lines changed

7 files changed

+30
-4
lines changed

doc/user_guide/configuration/all-options.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ Standard Checkers
626626
"""""""""""""""""""""""
627627
*List of method names used to declare (i.e. assign) instance attributes.*
628628

629-
**Default:** ``('__init__', '__new__', 'setUp', '__post_init__')``
629+
**Default:** ``('__init__', '__new__', 'setUp', 'asyncSetUp', '__post_init__')``
630630

631631

632632
--exclude-protected
@@ -663,7 +663,7 @@ Standard Checkers
663663
[tool.pylint.classes]
664664
check-protected-access-in-special-methods = false
665665
666-
defining-attr-methods = ["__init__", "__new__", "setUp", "__post_init__"]
666+
defining-attr-methods = ["__init__", "__new__", "setUp", "asyncSetUp", "__post_init__"]
667667
668668
exclude-protected = ["_asdict", "_fields", "_replace", "_source", "_make", "os._exit"]
669669
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Adds ``asyncSetUp`` to the default ``defining-attr-methods`` list to silence
2+
``attribute-defined-outside-init`` warning when using
3+
``unittest.IsolatedAsyncioTestCase``.
4+
5+
Refs #8403

examples/pylintrc

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ check-protected-access-in-special-methods=no
260260
defining-attr-methods=__init__,
261261
__new__,
262262
setUp,
263+
asyncSetUp,
263264
__post_init__
264265

265266
# List of member names, which should be excluded from the protected access

examples/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ variable-naming-style = "snake_case"
226226
# check-protected-access-in-special-methods =
227227

228228
# List of method names used to declare (i.e. assign) instance attributes.
229-
defining-attr-methods = ["__init__", "__new__", "setUp", "__post_init__"]
229+
defining-attr-methods = ["__init__", "__new__", "setUp", "asyncSetUp", "__post_init__"]
230230

231231
# List of member names, which should be excluded from the protected access
232232
# warning.

pylint/checkers/classes/class_checker.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,13 @@ class ClassChecker(BaseChecker):
778778
(
779779
"defining-attr-methods",
780780
{
781-
"default": ("__init__", "__new__", "setUp", "__post_init__"),
781+
"default": (
782+
"__init__",
783+
"__new__",
784+
"setUp",
785+
"asyncSetUp",
786+
"__post_init__",
787+
),
782788
"type": "csv",
783789
"metavar": "<method names>",
784790
"help": "List of method names used to declare (i.e. assign) \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# pylint: disable=missing-docstring
2+
3+
import unittest
4+
5+
6+
class AsyncioTestCase(unittest.IsolatedAsyncioTestCase):
7+
8+
async def asyncSetUp(self):
9+
self.i = 42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[main]
2+
load-plugins=pylint.extensions.typing
3+
4+
[testoptions]
5+
min_pyver=3.8

0 commit comments

Comments
 (0)