mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
Fixed #36252 -- Handled duplicate automatic imports in the shell command.
This commit is contained in:
parent
1823a80113
commit
e804a07d76
@ -185,8 +185,8 @@ class Command(BaseCommand):
|
|||||||
else:
|
else:
|
||||||
module = None
|
module = None
|
||||||
name = path
|
name = path
|
||||||
|
if (name, obj) not in auto_imports[module]:
|
||||||
auto_imports[module].append((name, obj))
|
auto_imports[module].append((name, obj))
|
||||||
|
|
||||||
namespace = {
|
namespace = {
|
||||||
name: obj for items in auto_imports.values() for name, obj in items
|
name: obj for items in auto_imports.values() for name, obj in items
|
||||||
|
@ -55,7 +55,8 @@ Running this customized ``shell`` command with ``verbosity=2`` would show:
|
|||||||
from django.urls import resolve, reverse
|
from django.urls import resolve, reverse
|
||||||
|
|
||||||
If an overridden ``shell`` command includes paths that cannot be imported,
|
If an overridden ``shell`` command includes paths that cannot be imported,
|
||||||
these errors are shown when ``verbosity`` is set to ``1`` or higher.
|
these errors are shown when ``verbosity`` is set to ``1`` or higher. Duplicate
|
||||||
|
imports are automatically handled.
|
||||||
|
|
||||||
Note that automatic imports can be disabled for a specific ``shell`` session
|
Note that automatic imports can be disabled for a specific ``shell`` session
|
||||||
using the :option:`--no-imports <shell --no-imports>` flag. To permanently
|
using the :option:`--no-imports <shell --no-imports>` flag. To permanently
|
||||||
|
@ -303,11 +303,16 @@ class ShellCommandAutoImportsTestCase(SimpleTestCase):
|
|||||||
def test_message_with_stdout_listing_objects_with_isort_not_installed(self):
|
def test_message_with_stdout_listing_objects_with_isort_not_installed(self):
|
||||||
class TestCommand(shell.Command):
|
class TestCommand(shell.Command):
|
||||||
def get_auto_imports(self):
|
def get_auto_imports(self):
|
||||||
|
# Include duplicate import strings to ensure proper handling,
|
||||||
|
# independent of isort's deduplication (#36252).
|
||||||
return super().get_auto_imports() + [
|
return super().get_auto_imports() + [
|
||||||
"django.urls.reverse",
|
"django.urls.reverse",
|
||||||
"django.urls.resolve",
|
"django.urls.resolve",
|
||||||
"shell",
|
"shell",
|
||||||
"django",
|
"django",
|
||||||
|
"django.urls.reverse",
|
||||||
|
"shell",
|
||||||
|
"django",
|
||||||
]
|
]
|
||||||
|
|
||||||
with captured_stdout() as stdout:
|
with captured_stdout() as stdout:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user