Skip to content

Commit

Permalink
Add Python 3.8+ asyncSetUp to "defining-attr-methods" list (#8403) (#…
Browse files Browse the repository at this point in the history
…8438)

(cherry picked from commit b312b9a)

Co-authored-by: Samuel FORESTIER <HorlogeSkynet@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and HorlogeSkynet authored Mar 11, 2023
1 parent 575319b commit 16dd28d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions doc/user_guide/configuration/all-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
5 changes: 5 additions & 0 deletions doc/whatsnew/fragments/8403.false_positive
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions examples/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/a/attribute_defined_outside_init_py38.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# pylint: disable=missing-docstring

import unittest


class AsyncioTestCase(unittest.IsolatedAsyncioTestCase):

async def asyncSetUp(self):
self.i = 42
5 changes: 5 additions & 0 deletions tests/functional/a/attribute_defined_outside_init_py38.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[main]
load-plugins=pylint.extensions.typing

[testoptions]
min_pyver=3.8

0 comments on commit 16dd28d

Please sign in to comment.