Skip to main content

Docstring Recipe generates git diff

I used the “Generate Docstrings” option on a class. The Sourcery pane took some time to load, but when it finally did, it generated this diff instead of just the docstring:

```
<<<<<<< SEARCH

class CreateGuide(PermissionRequiredMixin, CreateView):

model = models.Guide

template_name = "guides/create_guide.html"

form_class = forms.GuideForm

permission_required = "clients.add_guide"

raise_exception = True

def form_valid(self, form):

self.object = form.save()

return HttpResponseRedirect(reverse_lazy("guides_manage", kwargs=self.kwargs)+"?system_id="+str(self.object.system.id))

def get_context_data(self, **kwargs):

context = super().get_context_data(**kwargs)

context["guides_url"] = reverse_lazy("guides_manage", kwargs=self.kwargs)

return context

=======

class CreateGuide(PermissionRequiredMixin, CreateView):

"""Create a new guide.

This view handles the creation of new guides,

allowing users to add guides to the system.

"""

model = models.Guide

template_name = "guides/create_guide.html"

form_class = forms.GuideForm

permission_required = "clients.add_guide"

raise_exception = True

def form_valid(self, form):

self.object = form.save()

return HttpResponseRedirect(reverse_lazy("guides_manage", kwargs=self.kwargs)+"?system_id="+str(self.object.system.id))

def get_context_data(self, **kwargs):

context = super().get_context_data(**kwargs)

context["guides_url"] = reverse_lazy("guides_manage", kwargs=self.kwargs)

return context

>>>>>>> REPLACE
```

Usually, it just generates the class with the added docstring, and I can use the ‘insert at cursor’ option to just replace the code.

This would appear to be a bug to me. Does anyone else get this?

I’m on Windows 11, VS Code 1.99.3, Sourcery 1.35.0. Let me know if there’s any other diagnostic info I can provide.

5 comments

Log in to comment and vote

Comments5

  • Nick Thapen

    •

    Apr 23, 2025

    Hi James - we reworked it to return this format so that you can click the ‘Apply Changes’ button in the code block and get the docstring directly applied to your code.

    We’re keen for more feedback - is this not working, or not clear enough that it’s how to do it?