Remove `str-bytes-safe` check
diff --git a/mypy/checkstrformat.py b/mypy/checkstrformat.py
index e7602f3..98a4bc1 100644
--- a/mypy/checkstrformat.py
+++ b/mypy/checkstrformat.py
@@ -430,17 +430,7 @@
if isinstance(c_typ, LiteralType) and isinstance(c_typ.value, str):
if len(c_typ.value) != 1:
self.msg.requires_int_or_char(call, format_call=True)
- if (not spec.conv_type or spec.conv_type == "s") and not spec.conversion:
- if has_type_component(actual_type, "builtins.bytes") and not custom_special_method(
- actual_type, "__str__"
- ):
- self.msg.fail(
- 'On Python 3 formatting "b\'abc\'" with "{}" '
- 'produces "b\'abc\'", not "abc"; '
- 'use "{!r}" if this is desired behavior',
- call,
- code=codes.STR_BYTES_PY3,
- )
+
if spec.flags:
numeric_types = UnionType(
[self.named_type("builtins.int"), self.named_type("builtins.float")]
@@ -942,17 +932,6 @@
def check_s_special_cases(self, expr: FormatStringExpr, typ: Type, context: Context) -> bool:
"""Additional special cases for %s in bytes vs string context."""
- if isinstance(expr, StrExpr):
- # Couple special cases for string formatting.
- if has_type_component(typ, "builtins.bytes"):
- self.msg.fail(
- 'On Python 3 formatting "b\'abc\'" with "%s" '
- 'produces "b\'abc\'", not "abc"; '
- 'use "%r" if this is desired behavior',
- context,
- code=codes.STR_BYTES_PY3,
- )
- return False
if isinstance(expr, BytesExpr):
# A special case for bytes formatting: b'%s' actually requires bytes on Python 3.
if has_type_component(typ, "builtins.str"):
diff --git a/mypy/errorcodes.py b/mypy/errorcodes.py
index 2eb2d5c..c177d93 100644
--- a/mypy/errorcodes.py
+++ b/mypy/errorcodes.py
@@ -112,9 +112,6 @@
STRING_FORMATTING: Final = ErrorCode(
"str-format", "Check that string formatting/interpolation is type-safe", "General"
)
-STR_BYTES_PY3: Final = ErrorCode(
- "str-bytes-safe", "Warn about dangerous coercions related to bytes and string types", "General"
-)
EXIT_RETURN: Final = ErrorCode(
"exit-return", "Warn about too general return type for '__exit__'", "General"
)
diff --git a/mypyc/test-data/run-strings.test b/mypyc/test-data/run-strings.test
index 4a20c13..d086116 100644
--- a/mypyc/test-data/run-strings.test
+++ b/mypyc/test-data/run-strings.test
@@ -231,9 +231,6 @@
assert f'bool: {bool_var1}, {bool_var2}' == 'bool: True, False'
x = bytes([1, 2, 3, 4])
- # assert f'bytes: {x}' == "bytes: b'\\x01\\x02\\x03\\x04'"
- # error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc";
- # use "{!r}" if this is desired behavior behavior
float_num = 123.4
assert f'{float_num}' == '123.4'
diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test
index 124d695..bc811df 100644
--- a/test-data/unit/check-errorcodes.test
+++ b/test-data/unit/check-errorcodes.test
@@ -637,9 +637,6 @@
'%d' % 'no' # E: Incompatible types in string interpolation (expression has type "str", placeholder has type "Union[int, float, SupportsInt]") [str-format]
'%d + %d' % (1, 2, 3) # E: Not all arguments converted during string formatting [str-format]
-
-'{}'.format(b'abc') # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior [str-bytes-safe]
-'%s' % b'abc' # E: On Python 3 formatting "b'abc'" with "%s" produces "b'abc'", not "abc"; use "%r" if this is desired behavior [str-bytes-safe]
[builtins fixtures/primitives.pyi]
[typing fixtures/typing-medium.pyi]
diff --git a/test-data/unit/check-formatting.test b/test-data/unit/check-formatting.test
index 5c0d0ed..41bae9b 100644
--- a/test-data/unit/check-formatting.test
+++ b/test-data/unit/check-formatting.test
@@ -30,8 +30,6 @@
xs: str
'%s' % xs # OK
-'%s' % xb # E: On Python 3 formatting "b'abc'" with "%s" produces "b'abc'", not "abc"; use "%r" if this is desired behavior
-'%(name)s' % {'name': b'value'} # E: On Python 3 formatting "b'abc'" with "%s" produces "b'abc'", not "abc"; use "%r" if this is desired behavior
[builtins fixtures/primitives.pyi]
[case testStringInterpolationCount]
@@ -435,21 +433,8 @@
n: N
'{}'.format(a)
-'{}'.format(b) # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
-'{}'.format(x) # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
-'{}'.format(n) # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
-
-f'{b}' # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
-f'{x}' # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
-f'{n}' # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
-
-class C(Generic[B]):
- x: B
- def meth(self) -> None:
- '{}'.format(self.x) # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
def func(x: A) -> A:
- '{}'.format(x) # E: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
return x
'{!r}'.format(a)