Sample

pyint-d0a9b1865b27-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines128

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.2460–1; higher is more readable
Mi0.0320–1; higher is more readable
LLOC79Logical lines; fewer is more readable
DeepSeek V4 Pro11.670–20; mean of three runs
GPT-6.1 Sol15.670–20; mean of three runs
BTTF0.5980–1; higher is more readable

Views

Source code

from django.core.exceptions import ImproperlyConfigured from django.core.paginator import InvalidPage, Paginator from django.db.models import QuerySet from django.http import Http404 from django.utils.translation import gettext as _ from django.views.generic.base import ContextMixin, TemplateResponseMixin, View class MultipleObjectMixin(ContextMixin): """A mixin for views manipulating multiple objects.""" allow_empty = True queryset = None model = None paginate_by = None paginate_orphans = 0 context_object_name = None paginator_class = Paginator page_kwarg = "page" ordering = None def get_queryset(self): """ Return the list of items for this view. The return value must be an iterable and may be an instance of `QuerySet` in which case `QuerySet` specific behavior will be enabled. """ if self.queryset is not None: queryset = self.queryset if isinstance(queryset, QuerySet): queryset = queryset.all() elif self.model is not None: queryset = self.model._default_manager.all() else: raise ImproperlyConfigured( "%(cls)s is missing a QuerySet. Define " "%(cls)s.model, %(cls)s.queryset, or override " "%(cls)s.get_queryset()." % {"cls": self.__class__.__name__} ) ordering = self.get_ordering() if ordering: if isinstance(ordering, str): ordering = (ordering,) queryset = queryset.order_by(*ordering) return queryset def get_ordering(self): """Return the field or fields to use for ordering the queryset.""" return self.ordering def paginate_queryset(self, queryset, page_size): """Paginate the queryset, if needed.""" paginator = self.get_paginator( queryset, page_size, orphans=self.get_paginate_orphans(), allow_empty_first_page=self.get_allow_empty(), ) page_kwarg = self.page_kwarg page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1 try: page_number = int(page) except ValueError: if page == "last": page_number = paginator.num_pages else: raise Http404( _("Page is not “last”, nor can it be converted to an int.") ) try: page = paginator.page(page_number) return (paginator, page, page.object_list, page.has_other_pages()) except InvalidPage as e: raise Http404( _("Invalid page (%(page_number)s): %(message)s") % {"page_number": page_number, "message": str(e)} ) def get_paginate_by(self, queryset): """ Get the number of items to paginate by, or ``None`` for no pagination. """ return self.paginate_by def get_paginator( self, queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs ): """Return an instance of the paginator for this view.""" return self.paginator_class( queryset, per_page, orphans=orphans, allow_empty_first_page=allow_empty_first_page, **kwargs, ) def get_paginate_orphans(self): """ Return the maximum number of orphans extend the last page by when paginating. """ return self.paginate_orphans def get_allow_empty(self): """ Return ``True`` if the view should display empty lists and ``False`` if a 404 should be raised instead. """ return self.allow_empty def get_context_object_name(self, object_list): """Get the name of the item to be used in the context.""" if self.context_object_name: return self.context_object_name elif hasattr(object_list, "model"): return "%s_list" % object_list.model._meta.model_name else: return None def get_context_data(self, *, object_list=None, **kwargs): """Get the context for this view.""" queryset = object_list if object_list is not None else self.object_list page_size = self.get_paginate_by(queryset) context_object_name = self.get_context_object_name(queryset) if page_size: paginator, page, queryset, is_paginated = self.paginate_queryset( queryset, page_size ) context = { "paginator": paginator, "page_obj": page, "is_paginated": is_paginated, "object_list": queryset, } else: context = { "paginator": None, "page_obj": None, "is_paginated": False, "object_list": queryset, } if context_object_name is not None: context[context_object_name] = queryset context.update(kwargs) return super().get_context_data(**context)

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.4290.036−141.571
Source linesThe number of non-empty source lines.128+51.2
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.305−6.458

Intercept 8.87 + feature contributions = -87.959 (log-odds).
Score = sigmoid(-87.959) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.129−3.531
Indentation frequencyHow rapidly indentation changes from line to line.115+3.241
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.116−2.241
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.126.969−1.713
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.127.883+1.378
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.126.992+1.245
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.431

Intercept 0.07 + feature contributions = -1.121 (log-odds).
Score = sigmoid(-1.121) = 0.246.

Score0.032
Score79
Run 1

The code is generally readable in terms of variable naming and docstrings, but suffers from inconsistent formatting: missing blank lines between methods, uneven indentation, and broken string literals (e.g., ImproperlyConfigured message and translated strings). Some method calls split arguments across lines awkwardly, reducing reading flow. Nesting is moderate; the pagination and queryset logic includes several nested conditionals and exception handlers, which are manageable but could be flatter. Action granularity is mixed—some lines contain multiple actions (e.g., page lookup in one line), while others are reasonably granular. Overall, structure is logical but visually cluttered, making the code harder to scan than necessary. With formatting fixes, it would rise to 16 or more.

Run 2

The code has clear intent and follows Django's mixin pattern, but readability suffers from inconsistent formatting and vertical alignment issues. Indentation is standard, but many function calls and multiline constructs have awkward spacing (e.g., spaced-out arguments, oddly aligned parentheses). Several methods lack blank lines between them, reducing visual separation. Some lines attempt multiple actions or have broken string literals that disrupt reading flow. The pagination logic is moderately complex and could be flatter. Overall structure is logical, and variable names are descriptive, but the inconsistent style and dense blocks make the code harder to scan than necessary.

Run 3

The code has clear intent and follows Django conventions, but readability suffers from inconsistent formatting and spacing. Several method definitions lack blank lines between them, and some function calls have excessive indentation or misplaced line breaks (e.g., in paginate_queryset and get_paginator). The get_queryset method has awkward string concatenation in the error message. Some lines contain multiple actions, reducing granularity. Nesting is moderate but acceptable. The overall structure is logical, but the formatting inconsistencies disrupt the natural reading flow. With proper PEP 8 formatting and consistent line breaks, readability would improve significantly.

Run 1

Code Structure: Well-organized mixin with focused methods separating queryset retrieval, pagination, and context construction. Nesting: Mostly shallow, with manageable nested conditionals and exception handling. Clarity of intent: Descriptive method names, variables, and docstrings make the purpose clear, although Django-specific conventions require framework knowledge. Code length: Reasonable for its responsibilities; small accessor methods support customization, while duplicated context dictionaries add minor verbosity. Action granularity: Most statements perform one action, but several arguments and dictionary entries are crowded onto single lines. Reading flow: Method order follows a logical progression, but inconsistent blank lines, excessive inline spacing, and awkwardly wrapped calls and error messages interrupt scanning. Overall, strong semantic organization is weakened primarily by formatting.

Run 2

Code Structure: Well organized into focused mixin methods, separating queryset selection, pagination, and context construction. Nesting: Mostly shallow, with manageable conditional branches and exception handling. Clarity of intent: Descriptive method names, configuration attributes, and docstrings make responsibilities clear, though Django-specific conventions require framework knowledge. Code length: Appropriate overall; small accessor methods support customization, although context dictionaries repeat several keys. Action granularity: Most statements perform one action, but several arguments and dictionary entries are crowded onto single lines. Reading flow: Methods follow a logical progression, but inconsistent spacing, missing blank lines between methods, and awkwardly formatted calls and error strings interrupt scanning. These formatting issues reduce readability without obscuring the underlying design.

Run 3

Code Structure: Well organized into focused methods for queryset retrieval, pagination, configuration, and context construction. Nesting: Mostly shallow, with manageable nested conditionals and exception handling. Clarity of intent: Descriptive method names, variables, and docstrings make the purpose clear, although some Django-specific conventions require framework knowledge. Code length: Generally appropriate, but repetitive configuration getters and duplicated context dictionaries add some verbosity. Action granularity: Most statements perform one action; several argument lists and dictionary entries are crowded onto single lines, reducing scanability. Reading flow: Methods follow a logical progression, but inconsistent spacing, missing blank lines between methods, and awkwardly formatted calls and string literals interrupt an otherwise natural flow.