From 8148b0a92c3e8c7f4e6334de94be49e6783daca5 Mon Sep 17 00:00:00 2001 From: hemant-iitkgp Date: Thu, 26 Sep 2024 19:56:03 +0530 Subject: [PATCH 1/3] issue 17036 solved --- mypy/messages.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mypy/messages.py b/mypy/messages.py index 62846c536f3d..ddd6c981a6ec 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -534,6 +534,11 @@ def has_no_attr( context, code=codes.UNION_ATTR, ) + self.note( + 'You can use "if is not None" check to guard against a None value', + context, + code=codes.UNION_ATTR, + ) return codes.UNION_ATTR elif isinstance(original_type, TypeVarType): bound = get_proper_type(original_type.upper_bound) From cf0c564f96262ea830675b663d16344cf559be9e Mon Sep 17 00:00:00 2001 From: hemant-iitkgp Date: Thu, 26 Sep 2024 21:46:28 +0530 Subject: [PATCH 2/3] issue 17036 solved --- mypy/messages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index ddd6c981a6ec..5db8b0036674 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -534,7 +534,8 @@ def has_no_attr( context, code=codes.UNION_ATTR, ) - self.note( + if(typ_format == '"None"'): + self.note( 'You can use "if is not None" check to guard against a None value', context, code=codes.UNION_ATTR, From 682e45663bb14db453bf2f9d329107c8801a403d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:17:27 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/messages.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 5db8b0036674..30a8401070c8 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -534,12 +534,12 @@ def has_no_attr( context, code=codes.UNION_ATTR, ) - if(typ_format == '"None"'): + if typ_format == '"None"': self.note( - 'You can use "if is not None" check to guard against a None value', - context, - code=codes.UNION_ATTR, - ) + 'You can use "if is not None" check to guard against a None value', + context, + code=codes.UNION_ATTR, + ) return codes.UNION_ATTR elif isinstance(original_type, TypeVarType): bound = get_proper_type(original_type.upper_bound)