diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-08-06 10:00:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-06 10:00:32 +0200 |
commit | 865765ca78b43829d98c6c4424b6364c63925186 (patch) | |
tree | c8eaf3b30a0172cfc3b622350f4bcb7a066ef93b /tests | |
parent | 7d84a322afb129045b5c82790bad56b7d7f4fbc3 (diff) | |
download | pylint-git-865765ca78b43829d98c6c4424b6364c63925186.tar.gz |
Add ``redundant-u-string-prefix`` checker (#4804)
* Add ``redundant-u-string-prefix`` checker
This adds a checker for u-prefixes for strings, as used in Python 2. It only work in python 3.8 and above.
Closes #4102
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/a/anomalous_unicode_escape_py3.py | 2 | ||||
-rw-r--r-- | tests/functional/a/assign/assigning_non_slot.py | 2 | ||||
-rw-r--r-- | tests/functional/d/duplicate_dict_literal_key.py | 2 | ||||
-rw-r--r-- | tests/functional/e/excess_escapes.py | 1 | ||||
-rw-r--r-- | tests/functional/e/excess_escapes.txt | 18 | ||||
-rw-r--r-- | tests/functional/i/implicit/implicit_str_concat.py | 2 | ||||
-rw-r--r-- | tests/functional/i/iterable_context.py | 2 | ||||
-rw-r--r-- | tests/functional/m/member/membership_protocol.py | 2 | ||||
-rw-r--r-- | tests/functional/r/raise/raising_format_tuple.py | 1 | ||||
-rw-r--r-- | tests/functional/r/raise/raising_format_tuple.txt | 14 | ||||
-rw-r--r-- | tests/functional/r/redundant_u_string_prefix.py | 14 | ||||
-rw-r--r-- | tests/functional/r/redundant_u_string_prefix.rc | 2 | ||||
-rw-r--r-- | tests/functional/r/redundant_u_string_prefix.txt | 7 | ||||
-rw-r--r-- | tests/functional/s/suspicious_str_strip_call_py3.py | 1 | ||||
-rw-r--r-- | tests/functional/s/suspicious_str_strip_call_py3.txt | 6 | ||||
-rw-r--r-- | tests/functional/u/unsubscriptable_value.py | 2 |
16 files changed, 52 insertions, 26 deletions
diff --git a/tests/functional/a/anomalous_unicode_escape_py3.py b/tests/functional/a/anomalous_unicode_escape_py3.py index 18ebdf5f6..7c863097b 100644 --- a/tests/functional/a/anomalous_unicode_escape_py3.py +++ b/tests/functional/a/anomalous_unicode_escape_py3.py @@ -1,4 +1,4 @@ -# pylint:disable=pointless-string-statement +# pylint:disable=pointless-string-statement, redundant-u-string-prefix """Test for backslash escapes in byte vs unicode strings""" # Would be valid in Unicode, but probably not what you want otherwise diff --git a/tests/functional/a/assign/assigning_non_slot.py b/tests/functional/a/assign/assigning_non_slot.py index 600a2d5a2..4789014ff 100644 --- a/tests/functional/a/assign/assigning_non_slot.py +++ b/tests/functional/a/assign/assigning_non_slot.py @@ -1,7 +1,7 @@ """ Checks assigning attributes not found in class slots will trigger assigning-non-slot warning. """ -# pylint: disable=too-few-public-methods, no-init, missing-docstring, no-absolute-import, import-error, useless-object-inheritance +# pylint: disable=too-few-public-methods, no-init, missing-docstring, no-absolute-import, import-error, useless-object-inheritance, redundant-u-string-prefix from collections import deque from missing import Unknown diff --git a/tests/functional/d/duplicate_dict_literal_key.py b/tests/functional/d/duplicate_dict_literal_key.py index 67eab280f..6d359ff0a 100644 --- a/tests/functional/d/duplicate_dict_literal_key.py +++ b/tests/functional/d/duplicate_dict_literal_key.py @@ -1,5 +1,5 @@ """Check multiple key definition""" -# pylint: disable=pointless-statement +# pylint: disable=pointless-statement, redundant-u-string-prefix correct_dict = { 'tea': 'for two', diff --git a/tests/functional/e/excess_escapes.py b/tests/functional/e/excess_escapes.py index 04fa4db31..19fd5cb4d 100644 --- a/tests/functional/e/excess_escapes.py +++ b/tests/functional/e/excess_escapes.py @@ -1,5 +1,6 @@ # pylint:disable=pointless-string-statement, fixme, misplaced-comparison-constant, comparison-with-itself """Stray backslash escapes may be missing a raw-string prefix.""" +# pylint: disable=redundant-u-string-prefix __revision__ = '$Id$' diff --git a/tests/functional/e/excess_escapes.txt b/tests/functional/e/excess_escapes.txt index 20fa55243..4082e4709 100644 --- a/tests/functional/e/excess_escapes.txt +++ b/tests/functional/e/excess_escapes.txt @@ -1,9 +1,9 @@ -anomalous-backslash-in-string:7:5::"Anomalous backslash in string: '\['. String constant might be missing an r prefix." -anomalous-backslash-in-string:7:7::"Anomalous backslash in string: '\]'. String constant might be missing an r prefix." -anomalous-backslash-in-string:8:8::"Anomalous backslash in string: '\/'. String constant might be missing an r prefix." -anomalous-backslash-in-string:9:20::"Anomalous backslash in string: '\`'. String constant might be missing an r prefix." -anomalous-backslash-in-string:16:15::"Anomalous backslash in string: '\o'. String constant might be missing an r prefix." -anomalous-backslash-in-string:16:20::"Anomalous backslash in string: '\o'. String constant might be missing an r prefix." -anomalous-backslash-in-string:18:13::"Anomalous backslash in string: '\8'. String constant might be missing an r prefix." -anomalous-backslash-in-string:18:17::"Anomalous backslash in string: '\9'. String constant might be missing an r prefix." -anomalous-backslash-in-string:31:42::"Anomalous backslash in string: '\P'. String constant might be missing an r prefix." +anomalous-backslash-in-string:8:5::"Anomalous backslash in string: '\['. String constant might be missing an r prefix." +anomalous-backslash-in-string:8:7::"Anomalous backslash in string: '\]'. String constant might be missing an r prefix." +anomalous-backslash-in-string:9:8::"Anomalous backslash in string: '\/'. String constant might be missing an r prefix." +anomalous-backslash-in-string:10:20::"Anomalous backslash in string: '\`'. String constant might be missing an r prefix." +anomalous-backslash-in-string:17:15::"Anomalous backslash in string: '\o'. String constant might be missing an r prefix." +anomalous-backslash-in-string:17:20::"Anomalous backslash in string: '\o'. String constant might be missing an r prefix." +anomalous-backslash-in-string:19:13::"Anomalous backslash in string: '\8'. String constant might be missing an r prefix." +anomalous-backslash-in-string:19:17::"Anomalous backslash in string: '\9'. String constant might be missing an r prefix." +anomalous-backslash-in-string:32:42::"Anomalous backslash in string: '\P'. String constant might be missing an r prefix." diff --git a/tests/functional/i/implicit/implicit_str_concat.py b/tests/functional/i/implicit/implicit_str_concat.py index 707fa75bf..1ad9aed8c 100644 --- a/tests/functional/i/implicit/implicit_str_concat.py +++ b/tests/functional/i/implicit/implicit_str_concat.py @@ -1,4 +1,4 @@ -#pylint: disable=invalid-name,missing-docstring +#pylint: disable=invalid-name,missing-docstring,redundant-u-string-prefix # Basic test with a list TEST_LIST1 = ['a' 'b'] # [implicit-str-concat] diff --git a/tests/functional/i/iterable_context.py b/tests/functional/i/iterable_context.py index 6efefd550..2754d179f 100644 --- a/tests/functional/i/iterable_context.py +++ b/tests/functional/i/iterable_context.py @@ -2,7 +2,7 @@ Checks that primitive values are not used in an iterating/mapping context. """ -# pylint: disable=missing-docstring,invalid-name,too-few-public-methods,no-init,no-self-use,import-error,unused-argument,bad-mcs-method-argument,wrong-import-position,no-else-return, useless-object-inheritance, unnecessary-comprehension +# pylint: disable=missing-docstring,invalid-name,too-few-public-methods,no-init,no-self-use,import-error,unused-argument,bad-mcs-method-argument,wrong-import-position,no-else-return, useless-object-inheritance, unnecessary-comprehension,redundant-u-string-prefix from __future__ import print_function # primitives diff --git a/tests/functional/m/member/membership_protocol.py b/tests/functional/m/member/membership_protocol.py index 3401f4bb4..e5efc8916 100644 --- a/tests/functional/m/member/membership_protocol.py +++ b/tests/functional/m/member/membership_protocol.py @@ -1,4 +1,4 @@ -# pylint: disable=missing-docstring,pointless-statement,expression-not-assigned,too-few-public-methods,import-error,no-init,wrong-import-position,no-else-return, comparison-with-itself, useless-object-inheritance +# pylint: disable=missing-docstring,pointless-statement,expression-not-assigned,too-few-public-methods,import-error,no-init,wrong-import-position,no-else-return, comparison-with-itself, useless-object-inheritance, redundant-u-string-prefix # standard types 1 in [1, 2, 3] diff --git a/tests/functional/r/raise/raising_format_tuple.py b/tests/functional/r/raise/raising_format_tuple.py index 0f3a3349a..12e763d47 100644 --- a/tests/functional/r/raise/raising_format_tuple.py +++ b/tests/functional/r/raise/raising_format_tuple.py @@ -4,6 +4,7 @@ contains a percent sign, thus suggesting a % string formatting was intended instead. The same holds for a string containing {...} suggesting str.format() was intended. ''' +# pylint: disable=redundant-u-string-prefix def bad_percent(arg): '''Raising a percent-formatted string and an argument''' diff --git a/tests/functional/r/raise/raising_format_tuple.txt b/tests/functional/r/raise/raising_format_tuple.txt index 756fd1092..d663ca454 100644 --- a/tests/functional/r/raise/raising_format_tuple.txt +++ b/tests/functional/r/raise/raising_format_tuple.txt @@ -1,7 +1,7 @@ -raising-format-tuple:10:4:bad_percent:Exception arguments suggest string formatting might be intended -raising-format-tuple:18:4:bad_multiarg:Exception arguments suggest string formatting might be intended -raising-format-tuple:26:4:bad_braces:Exception arguments suggest string formatting might be intended -raising-format-tuple:34:4:bad_multistring:Exception arguments suggest string formatting might be intended -raising-format-tuple:40:4:bad_triplequote:Exception arguments suggest string formatting might be intended -raising-format-tuple:46:4:bad_unicode:Exception arguments suggest string formatting might be intended -raising-format-tuple:51:4:raise_something_without_name:Exception arguments suggest string formatting might be intended +raising-format-tuple:11:4:bad_percent:Exception arguments suggest string formatting might be intended +raising-format-tuple:19:4:bad_multiarg:Exception arguments suggest string formatting might be intended +raising-format-tuple:27:4:bad_braces:Exception arguments suggest string formatting might be intended +raising-format-tuple:35:4:bad_multistring:Exception arguments suggest string formatting might be intended +raising-format-tuple:41:4:bad_triplequote:Exception arguments suggest string formatting might be intended +raising-format-tuple:47:4:bad_unicode:Exception arguments suggest string formatting might be intended +raising-format-tuple:52:4:raise_something_without_name:Exception arguments suggest string formatting might be intended diff --git a/tests/functional/r/redundant_u_string_prefix.py b/tests/functional/r/redundant_u_string_prefix.py new file mode 100644 index 000000000..7ffbabd09 --- /dev/null +++ b/tests/functional/r/redundant_u_string_prefix.py @@ -0,0 +1,14 @@ +""""Checks for redundant u-prefixes for strings""" +# pylint: disable=missing-function-docstring + +def print_good(): + print("String") + print(f"String{1 + 1}") + + +def print_bad(): + print(u"String") # [redundant-u-string-prefix] + print(u'String') # [redundant-u-string-prefix] + print([u"String", u"String2"]) # [redundant-u-string-prefix, redundant-u-string-prefix] + print((u"String", u"String2")) # [redundant-u-string-prefix, redundant-u-string-prefix] + print({1: u"String"}) # [redundant-u-string-prefix] diff --git a/tests/functional/r/redundant_u_string_prefix.rc b/tests/functional/r/redundant_u_string_prefix.rc new file mode 100644 index 000000000..85fc502b3 --- /dev/null +++ b/tests/functional/r/redundant_u_string_prefix.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.8 diff --git a/tests/functional/r/redundant_u_string_prefix.txt b/tests/functional/r/redundant_u_string_prefix.txt new file mode 100644 index 000000000..f970ef8e8 --- /dev/null +++ b/tests/functional/r/redundant_u_string_prefix.txt @@ -0,0 +1,7 @@ +redundant-u-string-prefix:10:10::The u prefix for strings is no longer necessary in Python >=3.0:HIGH +redundant-u-string-prefix:11:10::The u prefix for strings is no longer necessary in Python >=3.0:HIGH +redundant-u-string-prefix:12:11::The u prefix for strings is no longer necessary in Python >=3.0:HIGH +redundant-u-string-prefix:12:22::The u prefix for strings is no longer necessary in Python >=3.0:HIGH +redundant-u-string-prefix:13:11::The u prefix for strings is no longer necessary in Python >=3.0:HIGH +redundant-u-string-prefix:13:22::The u prefix for strings is no longer necessary in Python >=3.0:HIGH +redundant-u-string-prefix:14:14::The u prefix for strings is no longer necessary in Python >=3.0:HIGH diff --git a/tests/functional/s/suspicious_str_strip_call_py3.py b/tests/functional/s/suspicious_str_strip_call_py3.py index e859f25f8..40684cc1d 100644 --- a/tests/functional/s/suspicious_str_strip_call_py3.py +++ b/tests/functional/s/suspicious_str_strip_call_py3.py @@ -1,4 +1,5 @@ """Suspicious str.strip calls.""" +# pylint: disable=redundant-u-string-prefix __revision__ = 1 ''.strip('yo') diff --git a/tests/functional/s/suspicious_str_strip_call_py3.txt b/tests/functional/s/suspicious_str_strip_call_py3.txt index dc50d46c1..7e338386c 100644 --- a/tests/functional/s/suspicious_str_strip_call_py3.txt +++ b/tests/functional/s/suspicious_str_strip_call_py3.txt @@ -1,3 +1,3 @@ -bad-str-strip-call:7:0::Suspicious argument in str.strip call -bad-str-strip-call:8:0::Suspicious argument in str.lstrip call -bad-str-strip-call:9:0::Suspicious argument in bytes.rstrip call +bad-str-strip-call:8:0::Suspicious argument in str.strip call +bad-str-strip-call:9:0::Suspicious argument in str.lstrip call +bad-str-strip-call:10:0::Suspicious argument in bytes.rstrip call diff --git a/tests/functional/u/unsubscriptable_value.py b/tests/functional/u/unsubscriptable_value.py index 73c3ac40e..6a97cc4c8 100644 --- a/tests/functional/u/unsubscriptable_value.py +++ b/tests/functional/u/unsubscriptable_value.py @@ -3,7 +3,7 @@ Checks that value used in a subscript supports subscription (i.e. defines __getitem__ method). """ # pylint: disable=missing-docstring,pointless-statement,expression-not-assigned,wrong-import-position, unnecessary-comprehension -# pylint: disable=too-few-public-methods,import-error,invalid-name,wrong-import-order, useless-object-inheritance +# pylint: disable=too-few-public-methods,import-error,invalid-name,wrong-import-order, useless-object-inheritance, redundant-u-string-prefix import six # primitives |