From aff649a3bd0c4fd8f7d859464f0eb907e877443f Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 22 May 2022 08:23:10 +0200 Subject: [PATCH] Normalized imports of functools.wraps. @wraps is 10 times more common than @functools.wraps. Standardize to the most common version. --- django/template/library.py | 6 +++--- django/utils/autoreload.py | 10 +++++----- django/views/decorators/debug.py | 6 +++--- tests/template_tests/utils.py | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/django/template/library.py b/django/template/library.py index fbec9484a16..16db79e4cd8 100644 --- a/django/template/library.py +++ b/django/template/library.py @@ -1,4 +1,4 @@ -import functools +from functools import wraps from importlib import import_module from inspect import getfullargspec, unwrap @@ -120,7 +120,7 @@ class Library: ) = getfullargspec(unwrap(func)) function_name = name or func.__name__ - @functools.wraps(func) + @wraps(func) def compile_func(parser, token): bits = token.split_contents()[1:] target_var = None @@ -175,7 +175,7 @@ class Library: ) = getfullargspec(unwrap(func)) function_name = name or func.__name__ - @functools.wraps(func) + @wraps(func) def compile_func(parser, token): bits = token.split_contents()[1:] args, kwargs = parse_bits( diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index 1b3652b41d9..f4076d6d31d 100644 --- a/django/utils/autoreload.py +++ b/django/utils/autoreload.py @@ -1,4 +1,3 @@ -import functools import itertools import logging import os @@ -10,6 +9,7 @@ import time import traceback import weakref from collections import defaultdict +from functools import lru_cache, wraps from pathlib import Path from types import ModuleType from zipimport import zipimporter @@ -57,7 +57,7 @@ def is_django_path(path): def check_errors(fn): - @functools.wraps(fn) + @wraps(fn) def wrapper(*args, **kwargs): global _exception try: @@ -120,7 +120,7 @@ def iter_all_python_module_files(): return iter_modules_and_files(modules, frozenset(_error_files)) -@functools.lru_cache(maxsize=1) +@lru_cache(maxsize=1) def iter_modules_and_files(modules, extra_files): """Iterate through all modules needed to be watched.""" sys_file_paths = [] @@ -170,7 +170,7 @@ def iter_modules_and_files(modules, extra_files): return frozenset(results) -@functools.lru_cache(maxsize=1) +@lru_cache(maxsize=1) def common_roots(paths): """ Return a tuple of common roots that are shared between the given paths. @@ -463,7 +463,7 @@ class WatchmanReloader(BaseReloader): logger.debug("Watchman watch-project result: %s", result) return result["watch"], result.get("relative_path") - @functools.lru_cache + @lru_cache def _get_clock(self, root): return self.client.query("clock", root)["clock"] diff --git a/django/views/decorators/debug.py b/django/views/decorators/debug.py index 5cf8db891f5..5578a4995f9 100644 --- a/django/views/decorators/debug.py +++ b/django/views/decorators/debug.py @@ -1,4 +1,4 @@ -import functools +from functools import wraps from django.http import HttpRequest @@ -33,7 +33,7 @@ def sensitive_variables(*variables): ) def decorator(func): - @functools.wraps(func) + @wraps(func) def sensitive_variables_wrapper(*func_args, **func_kwargs): if variables: sensitive_variables_wrapper.sensitive_variables = variables @@ -77,7 +77,7 @@ def sensitive_post_parameters(*parameters): ) def decorator(view): - @functools.wraps(view) + @wraps(view) def sensitive_post_parameters_wrapper(request, *args, **kwargs): if not isinstance(request, HttpRequest): raise TypeError( diff --git a/tests/template_tests/utils.py b/tests/template_tests/utils.py index 2e78ec98948..9bab583e794 100644 --- a/tests/template_tests/utils.py +++ b/tests/template_tests/utils.py @@ -1,5 +1,5 @@ -import functools import os +from functools import wraps from django.template.engine import Engine from django.test.utils import override_settings @@ -46,7 +46,7 @@ def setup(templates, *args, test_once=False): # Make Engine.get_default() raise an exception to ensure that tests # are properly isolated from Django's global settings. @override_settings(TEMPLATES=None) - @functools.wraps(func) + @wraps(func) def inner(self): # Set up custom template tag libraries if specified libraries = getattr(self, "libraries", {})