diff options
author | Levi Gruspe <mail.levig@gmail.com> | 2022-09-04 19:10:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-04 13:10:41 +0200 |
commit | 2f766a1dcde49c76de1c826eb8df8cbbeb2e7c71 (patch) | |
tree | 415a9cf3114b51f6cf832f40b7a31224c90b386b /tests/checkers/unittest_utils.py | |
parent | 89737663f6a8891f5f5ae3e9a7d689cfec569ee8 (diff) | |
download | pylint-git-2f766a1dcde49c76de1c826eb8df8cbbeb2e7c71.tar.gz |
Fix #3299 false positives with names in string literal type annotations (#7400)
Don't emit 'unused-variable' or 'unused-import' on names in string literal type annotations (#3299)
Don't treat strings inside typing.Literal as names
Diffstat (limited to 'tests/checkers/unittest_utils.py')
-rw-r--r-- | tests/checkers/unittest_utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/checkers/unittest_utils.py b/tests/checkers/unittest_utils.py index 8b9189892..f68a48dbb 100644 --- a/tests/checkers/unittest_utils.py +++ b/tests/checkers/unittest_utils.py @@ -489,3 +489,29 @@ def test_deprecation_check_messages() -> None: records[0].message.args[0] == "utils.check_messages will be removed in favour of calling utils.only_required_for_messages in pylint 3.0" ) + + +def test_is_typing_literal() -> None: + code = astroid.extract_node( + """ + from typing import Literal as Lit, Set as Literal + import typing as t + + Literal #@ + Lit #@ + t.Literal #@ + """ + ) + + assert not utils.is_typing_literal(code[0]) + assert utils.is_typing_literal(code[1]) + assert utils.is_typing_literal(code[2]) + + code = astroid.extract_node( + """ + Literal #@ + typing.Literal #@ + """ + ) + assert not utils.is_typing_literal(code[0]) + assert not utils.is_typing_literal(code[1]) |