diff --git a/mypy/checkstrformat.py b/mypy/checkstrformat.py index c63210a96c44..dd42fe7755a0 100644 --- a/mypy/checkstrformat.py +++ b/mypy/checkstrformat.py @@ -393,8 +393,10 @@ def check_specs_in_format_call( # If the explicit conversion is given, then explicit conversion is called _first_. if spec.conversion[1] not in "rsa": self.msg.fail( - 'Invalid conversion type "{}",' - ' must be one of "r", "s" or "a"'.format(spec.conversion[1]), + ( + f'Invalid conversion type "{spec.conversion[1]}", ' + f'must be one of "r", "s" or "a"' + ), call, code=codes.STRING_FORMATTING, ) @@ -472,8 +474,7 @@ def find_replacements_in_call(self, call: CallExpr, keys: list[str]) -> list[Exp expr = self.get_expr_by_position(int(key), call) if not expr: self.msg.fail( - "Cannot find replacement for positional" - " format specifier {}".format(key), + f"Cannot find replacement for positional format specifier {key}", call, code=codes.STRING_FORMATTING, ) @@ -654,8 +655,9 @@ class User(TypedDict): assert spec.key, "Call this method only after auto-generating keys!" assert spec.field self.msg.fail( - "Invalid index expression in format field" - ' accessor "{}"'.format(spec.field[len(spec.key) :]), + 'Invalid index expression in format field accessor "{}"'.format( + spec.field[len(spec.key) :] + ), ctx, code=codes.STRING_FORMATTING, ) diff --git a/mypy/inspections.py b/mypy/inspections.py index 3e660a0bd7a6..0baf0896f7e5 100644 --- a/mypy/inspections.py +++ b/mypy/inspections.py @@ -469,8 +469,7 @@ def missing_type(self, expression: Expression) -> str: def missing_node(self, expression: Expression) -> str: return ( - f'Cannot find definition for "{type(expression).__name__}"' - f" at {expr_span(expression)}" + f'Cannot find definition for "{type(expression).__name__}" at {expr_span(expression)}' ) def add_prefixes(self, result: str, expression: Expression) -> str: diff --git a/mypy/main.py b/mypy/main.py index 5991ddd9e62f..c3ab8bc9b008 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -552,15 +552,16 @@ def add_invertible_flag( ) config_group.add_argument( "--config-file", - help="Configuration file, must have a [mypy] section " - "(defaults to {})".format(", ".join(defaults.CONFIG_FILES)), + help=( + f"Configuration file, must have a [mypy] section " + f"(defaults to {', '.join(defaults.CONFIG_FILES)})" + ), ) add_invertible_flag( "--warn-unused-configs", default=False, strict_flag=True, - help="Warn about unused '[mypy-]' or '[[tool.mypy.overrides]]' " - "config sections", + help="Warn about unused '[mypy-]' or '[[tool.mypy.overrides]]' config sections", group=config_group, ) @@ -589,8 +590,7 @@ def add_invertible_flag( "--python-executable", action="store", metavar="EXECUTABLE", - help="Python executable used for finding PEP 561 compliant installed" - " packages and stubs", + help="Python executable used for finding PEP 561 compliant installed packages and stubs", dest="special-opts:python_executable", ) imports_group.add_argument( @@ -623,8 +623,7 @@ def add_invertible_flag( "--platform", action="store", metavar="PLATFORM", - help="Type check special-cased code for the given OS platform " - "(defaults to sys.platform)", + help="Type check special-cased code for the given OS platform (defaults to sys.platform)", ) platform_group.add_argument( "--always-true", @@ -661,8 +660,7 @@ def add_invertible_flag( "--disallow-any-decorated", default=False, action="store_true", - help="Disallow functions that have Any in their signature " - "after decorator transformation", + help="Disallow functions that have Any in their signature after decorator transformation", ) disallow_any_group.add_argument( "--disallow-any-explicit", diff --git a/mypy/message_registry.py b/mypy/message_registry.py index 29d539faaed6..c0b422d4a35d 100644 --- a/mypy/message_registry.py +++ b/mypy/message_registry.py @@ -196,8 +196,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage: TYPEVAR_ARG_MUST_BE_TYPE: Final = '{} "{}" must be a type' TYPEVAR_UNEXPECTED_ARGUMENT: Final = 'Unexpected argument to "TypeVar()"' UNBOUND_TYPEVAR: Final = ( - "A function returning TypeVar should receive at least " - "one argument containing the same TypeVar" + "A function returning TypeVar should receive at least one argument containing the same TypeVar" ) TYPE_PARAMETERS_SHOULD_BE_DECLARED: Final = ( "All type parameters should be declared ({} not declared)" diff --git a/mypy/messages.py b/mypy/messages.py index adf150eab50a..d63df92c80a7 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -675,8 +675,7 @@ def incompatible_argument( arg_type, callee.arg_types[n - 1], options=self.options ) info = ( - f" (expression has type {arg_type_str}, " - f"target has type {callee_type_str})" + f" (expression has type {arg_type_str}, target has type {callee_type_str})" ) error_msg = ( message_registry.INCOMPATIBLE_TYPES_IN_ASSIGNMENT.with_additional_msg(info) @@ -1433,8 +1432,7 @@ def first_argument_for_super_must_be_type(self, actual: Type, context: Context) def unsafe_super(self, method: str, cls: str, ctx: Context) -> None: self.fail( - 'Call to abstract method "{}" of "{}" with trivial body' - " via super() is unsafe".format(method, cls), + f'Call to abstract method "{method}" of "{cls}" with trivial body via super() is unsafe', ctx, code=codes.SAFE_SUPER, ) @@ -1588,8 +1586,10 @@ def final_cant_override_writable(self, name: str, ctx: Context) -> None: def cant_override_final(self, name: str, base_name: str, ctx: Context) -> None: self.fail( - 'Cannot override final attribute "{}"' - ' (previously declared in base class "{}")'.format(name, base_name), + ( + f'Cannot override final attribute "{name}" ' + f'(previously declared in base class "{base_name}")' + ), ctx, ) @@ -1676,15 +1676,16 @@ def overloaded_signatures_typevar_specific(self, index: int, context: Context) - def overloaded_signatures_arg_specific(self, index: int, context: Context) -> None: self.fail( - "Overloaded function implementation does not accept all possible arguments " - "of signature {}".format(index), + ( + f"Overloaded function implementation does not accept all possible arguments " + f"of signature {index}" + ), context, ) def overloaded_signatures_ret_specific(self, index: int, context: Context) -> None: self.fail( - "Overloaded function implementation cannot produce return type " - "of signature {}".format(index), + f"Overloaded function implementation cannot produce return type of signature {index}", context, ) @@ -1707,8 +1708,7 @@ def operator_method_signatures_overlap( context: Context, ) -> None: self.fail( - 'Signatures of "{}" of "{}" and "{}" of {} ' - "are unsafely overlapping".format( + 'Signatures of "{}" of "{}" and "{}" of {} are unsafely overlapping'.format( reverse_method, reverse_class.name, forward_method, @@ -1997,8 +1997,7 @@ def bad_proto_variance( self, actual: int, tvar_name: str, expected: int, context: Context ) -> None: msg = capitalize( - '{} type variable "{}" used in protocol where' - " {} one is expected".format( + '{} type variable "{}" used in protocol where {} one is expected'.format( variance_string(actual), tvar_name, variance_string(expected) ) ) @@ -2246,15 +2245,17 @@ def report_protocol_problems( for name, subflags, superflags in conflict_flags[:MAX_ITEMS]: if not class_obj and IS_CLASSVAR in subflags and IS_CLASSVAR not in superflags: self.note( - "Protocol member {}.{} expected instance variable," - " got class variable".format(supertype.type.name, name), + "Protocol member {}.{} expected instance variable, got class variable".format( + supertype.type.name, name + ), context, code=code, ) if not class_obj and IS_CLASSVAR in superflags and IS_CLASSVAR not in subflags: self.note( - "Protocol member {}.{} expected class variable," - " got instance variable".format(supertype.type.name, name), + "Protocol member {}.{} expected class variable, got instance variable".format( + supertype.type.name, name + ), context, code=code, ) diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index 49c39a9ce91c..958abebc84d1 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -73,8 +73,7 @@ def error_message_templates(self, daemon: bool) -> tuple[str, list[str]]: elif self is ModuleNotFoundReason.WRONG_WORKING_DIRECTORY: msg = 'Cannot find implementation or library stub for module named "{module}"' notes = [ - "You may be running mypy in a subpackage, " - "mypy should be run on the package root" + "You may be running mypy in a subpackage, mypy should be run on the package root" ] elif self is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS: msg = ( diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py index edfc6840fc37..81a5e70e6b3a 100644 --- a/mypy/plugins/dataclasses.py +++ b/mypy/plugins/dataclasses.py @@ -444,8 +444,7 @@ def add_slots( # This means that version is lower than `3.10`, # it is just a non-existent argument for `dataclass` function. self._api.fail( - 'Keyword argument "slots" for "dataclass" ' - "is only valid in Python 3.10 and higher", + 'Keyword argument "slots" for "dataclass" is only valid in Python 3.10 and higher', self._reason, ) return diff --git a/mypy/semanal.py b/mypy/semanal.py index e182322cfbe6..23310e0974cd 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -2636,8 +2636,7 @@ def calculate_class_mro( calculate_mro(defn.info, obj_type) except MroError: self.fail( - "Cannot determine consistent method resolution " - 'order (MRO) for "%s"' % defn.name, + f'Cannot determine consistent method resolution order (MRO) for "{defn.name}"', defn, ) self.set_dummy_mro(defn.info) diff --git a/mypy/semanal_namedtuple.py b/mypy/semanal_namedtuple.py index 768dd265b338..7c6da7721e8f 100644 --- a/mypy/semanal_namedtuple.py +++ b/mypy/semanal_namedtuple.py @@ -380,8 +380,7 @@ def parse_namedtuple_args( rename = arg.name == "True" else: self.fail( - 'Boolean literal expected as the "rename" argument to ' - f"{type_name}()", + f'Boolean literal expected as the "rename" argument to {type_name}()', arg, code=ARG_TYPE, ) diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 0a6b7689136e..d3ed3ff2bae6 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -968,14 +968,12 @@ def analyze_unbound_type_without_type_info( message = 'Type variable "{}" is unbound' short = name.split(".")[-1] notes.append( - ( - '(Hint: Use "Generic[{}]" or "Protocol[{}]" base class' - ' to bind "{}" inside a class)' - ).format(short, short, short) + f'(Hint: Use "Generic[{short}]" or "Protocol[{short}]" base class' + f' to bind "{short}" inside a class)' ) notes.append( - '(Hint: Use "{}" in function signature to bind "{}"' - " inside a function)".format(short, short) + f'(Hint: Use "{short}" in function signature ' + f'to bind "{short}" inside a function)' ) else: message = 'Cannot interpret reference "{}" as a type'