Skip to content

[Backport maintenance/2.17.x] Add Python 3.8+ asyncSetUp to "defining-attr-methods" list #8438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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