diff --git a/django_codemod/visitors/urls.py b/django_codemod/visitors/urls.py index bcb8cef0..8fbb2187 100644 --- a/django_codemod/visitors/urls.py +++ b/django_codemod/visitors/urls.py @@ -49,7 +49,6 @@ def update_call_to_path(self, updated_node: Call): self.check_not_simple_string(first_arg) # Extract the URL pattern from the first argument pattern = first_arg.value.evaluated_value - self.check_missing_start(pattern) # If we reach this point, we might be able to use `path()` call = self.build_path_call(pattern, other_args) AddImportsVisitor.add_needed_import( @@ -64,11 +63,6 @@ def check_not_simple_string(self, first_arg: Arg): if not m.matches(first_arg, m.Arg(value=m.SimpleString())): raise PatternNotSupported() - def check_missing_start(self, pattern): - """Patterns that do not match the start of the string with caret.""" - if not pattern.startswith("^"): - raise PatternNotSupported() - def build_path_call(self, pattern, other_args): """Build the `Call` node using Django 2.0's `path()` function.""" route = self.build_route(pattern) diff --git a/tests/visitors/test_urls.py b/tests/visitors/test_urls.py index 873766c2..77758899 100644 --- a/tests/visitors/test_urls.py +++ b/tests/visitors/test_urls.py @@ -52,8 +52,8 @@ def test_simple_substitution(self) -> None: """ self.assertCodemod(before, after) - def test_starting_caret(self) -> None: - """Patterns not starting with '^' are migrated to re_path.""" + def test_no_starting_caret(self) -> None: + """Patterns not starting with '^' are also migrated to path.""" before = """ from django.conf.urls import url @@ -62,10 +62,10 @@ def test_starting_caret(self) -> None: ] """ after = """ - from django.urls import re_path + from django.urls import path urlpatterns = [ - re_path(r'about/$', views.about, name='about'), + path('about/', views.about, name='about'), ] """ self.assertCodemod(before, after)