Path 1: 3 calls (0.23)

AsyncWith (3)

AttributeInferenceError (3)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 2: 2 calls (0.15)

AsyncWith (2)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 3: 1 calls (0.08)

AsyncWith (1)

AttributeInferenceError (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 4: 1 calls (0.08)

AsyncWith (1)

AttributeInferenceError (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 5: 1 calls (0.08)

AsyncWith (1)

AttributeInferenceError (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 6: 1 calls (0.08)

AsyncWith (1)

AttributeInferenceError (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 7: 1 calls (0.08)

AsyncWith (1)

AttributeInferenceError (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 8: 1 calls (0.08)

AsyncWith (1)

AttributeInferenceError (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 9: 1 calls (0.08)

AsyncWith (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )
            

Path 10: 1 calls (0.08)

AsyncWith (1)

1@checker_utils.only_required_for_messages("not-async-context-manager")
2    def visit_asyncwith(self, node: nodes.AsyncWith) -> None:
3        for ctx_mgr, _ in node.items:
4            inferred = checker_utils.safe_infer(ctx_mgr)
5            if inferred is None or inferred is astroid.Uninferable:
6                continue
7
8            if isinstance(inferred, nodes.AsyncFunctionDef):
9                # Check if we are dealing with a function decorated
10                # with contextlib.asynccontextmanager.
11                if decorated_with(inferred, self._async_generators):
12                    continue
13            elif isinstance(inferred, astroid.bases.AsyncGenerator):
14                # Check if we are dealing with a function decorated
15                # with contextlib.asynccontextmanager.
16                if decorated_with(inferred.parent, self._async_generators):
17                    continue
18            else:
19                try:
20                    inferred.getattr("__aenter__")
21                    inferred.getattr("__aexit__")
22                except astroid.exceptions.NotFoundError:
23                    if isinstance(inferred, astroid.Instance):
24                        # If we do not know the bases of this class,
25                        # just skip it.
26                        if not checker_utils.has_known_bases(inferred):
27                            continue
28                        # Ignore mixin classes if they match the rgx option.
29                        if (
30                            "not-async-context-manager"
31                            in self.linter.config.ignored_checks_for_mixins
32                            and self._mixin_class_rgx.match(inferred.name)
33                        ):
34                            continue
35                else:
36                    continue
37            self.add_message(
38                "not-async-context-manager", node=node, args=(inferred.name,)
39            )