diff --git a/pygount/common.py b/pygount/common.py index cf4d95f..d12fef6 100644 --- a/pygount/common.py +++ b/pygount/common.py @@ -122,6 +122,8 @@ def deprecated(reason: Optional[str]): # pragma: no cover Decorator to mark functions as deprecated and log a warning in case it is called. Source: https://stackoverflow.com/questions/2536307/decorators-in-the-python-standard-lib-deprecated-specifically + + Updated replace .format() with f-string """ if isinstance(reason, str): @@ -134,16 +136,15 @@ def deprecated(reason: Optional[str]): # pragma: no cover # pass def decorator(func1): - if inspect.isclass(func1): - fmt1 = "Call to deprecated class {name} ({reason})." - else: - fmt1 = "Call to deprecated function {name} ({reason})." + class_or_func = "class" if inspect.isclass(func1) else "function" @functools.wraps(func1) def new_func1(*args, **kwargs): warnings.simplefilter("always", DeprecationWarning) warnings.warn( - fmt1.format(name=func1.__name__, reason=reason), category=DeprecationWarning, stacklevel=2 + f"Call to deprecated {class_or_func} {func1.__name__} ({reason}).", + category=DeprecationWarning, + stacklevel=2, ) warnings.simplefilter("default", DeprecationWarning) return func1(*args, **kwargs) @@ -151,6 +152,7 @@ def new_func1(*args, **kwargs): return new_func1 return decorator + if inspect.isclass(reason) or inspect.isfunction(reason): # The @deprecated is used without any 'reason'. # @@ -161,12 +163,16 @@ def new_func1(*args, **kwargs): # pass func2 = reason - fmt2 = "Call to deprecated class {name}." if inspect.isclass(func2) else "Call to deprecated function {name}." + class_or_func = "class" if inspect.isclass(func2) else "function" @functools.wraps(func2) def new_func2(*args, **kwargs): warnings.simplefilter("always", DeprecationWarning) - warnings.warn(fmt2.format(name=func2.__name__), category=DeprecationWarning, stacklevel=2) + warnings.warn( + f"Call to deprecated {class_or_func} {func2.__name__}.", + category=DeprecationWarning, + stacklevel=2, + ) warnings.simplefilter("default", DeprecationWarning) return func2(*args, **kwargs) diff --git a/pygount/write.py b/pygount/write.py index 5445fc7..64f8aee 100644 --- a/pygount/write.py +++ b/pygount/write.py @@ -74,11 +74,11 @@ class LineWriter(BaseWriter): def __init__(self, target_stream): super().__init__(target_stream) self.has_to_track_progress = False - self.template = "{0}\t{1}\t{2}\t{3}" def add(self, source_analysis): - line_to_write = self.template.format( - source_analysis.code_count, source_analysis.language, source_analysis.group, source_analysis.path + line_to_write = ( + f"{source_analysis.code_count}\t{source_analysis.language}\t" + f"{source_analysis.group}\t{source_analysis.path}" ) self._target_stream.write(line_to_write + os.linesep)