Sample

pyint-bea7fb27e0bf-I12

Inline all eligible single-use intermediate local variables

Matched original source

Lines146

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4610–1; higher is more readable
Mi0.3570–1; higher is more readable
LLOC79Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.6580–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.146+58.4
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.314−6.472

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.147−4.168
Indentation frequencyHow rapidly indentation changes from line to line.132+3.829
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.133−2.631
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.145.845+1.629
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.82.912+0.533
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.43
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.82.946+0.152

Intercept 0.07 + feature contributions = -0.157 (log-odds).
Score = sigmoid(-0.157) = 0.461.

Score0.357
Score79
Run 1

The code is generally well-structured and readable, benefiting from clear method separation and descriptive docstrings. However, it has a few areas that reduce clarity. The get_queryset method contains nested conditionals and multiple responsibilities (querying and ordering), which makes it slightly harder to follow. The paginate_queryset method has a try-except with a nested conditional, and the loop-free flow is mostly linear but occasionally dense. Variable naming is clear, and each line tends to represent one action, but some lines combine multiple operations. Overall, it's clear and maintainable, though not as flat or concise as it could be.

Run 2

The code is well-structured and follows Django's established mixin pattern, making it familiar and logical. It is largely flat, with only mild nesting in pagination and queryset checks. Intent is clear through descriptive method names, docstrings, and standard Django conventions. Length is reasonable, though `get_context_data` has some repetition. Action granularity is mostly one action per line, though the pagination page retrieval line is overly dense and reduces readability. Reading flow is natural and organized. Minor deductions: the complex ternary-like page retrieval, repeated context dictionaries, and overloaded `page` variable slightly reduce clarity. Overall, it is highly readable for developers familiar with Django class-based views.

Run 3

The code is highly readable with clear structure, logical organization, and good use of class-based mixin pattern. Each method has a single responsibility and is well-documented with docstrings explaining intent. Nesting is mostly flat, with only 2-3 levels in methods like get_queryset and paginate_queryset, which is acceptable. Intent is clear throughout—method names like get_paginate_orphans and get_allow_empty are self-documenting. Code length is appropriate, though some methods could be slightly more concise. Action granularity is generally one action per line, especially in paginate_queryset where each step (fetching page number, parsing, error handling) occupies its own line. Reading flow is natural—methods are ordered from data access (get_queryset) to pagination to context construction, following a logical progression. Minor deductions: the nested try/except in paginate_queryset adds slight cognitive overhead, and the error message strings are long, but these are Django conventions and not readability issues.

Run 1

Code Structure: Well-organized mixin with focused methods separating queryset selection, ordering, pagination, and context construction. Nesting: Mostly shallow, with modest nested conditionals and straightforward exception handling. Clarity of intent: Descriptive method names, configuration attributes, and docstrings make responsibilities clear; Django-specific conventions and the positional pagination return tuple require some familiarity. Code length: Reasonably concise for its functionality, although context dictionaries repeat several keys and simple accessor methods add length while supporting customization. Action granularity: Statements generally perform one action each, with readable multiline calls and dictionaries; tuple unpacking remains manageable. Reading flow: Methods follow a coherent progression from data retrieval through pagination to context assembly. Minor distractions include unused imports, reuse of 'page' for different types, and an awkwardly worded orphan-pagination docstring.

Run 2

Code Structure: Well-organized mixin with focused methods separating queryset retrieval, pagination, and context construction. Nesting: Generally shallow, with modest nesting for configuration and page validation. Clarity of intent: Descriptive method names, configuration attributes, docstrings, and informative exceptions make behavior clear; Django-specific conventions require framework knowledge. Code length: Mostly concise, though numerous simple accessor methods and duplicated context dictionaries add some verbosity. Action granularity: Statements generally perform one action each; tuple unpacking and chained page-source selection remain understandable. Reading flow: Methods follow a logical progression, and consistent formatting supports scanning. Minor drawbacks include unused imports, reuse of the page variable for different types, and an awkwardly worded pagination docstring.

Run 3

Code Structure: Responsibilities are logically separated into focused methods, with configuration attributes grouped clearly. Nesting: Generally shallow; queryset selection and pagination error handling introduce only moderate nesting. Clarity of intent: Descriptive method names, docstrings, and explicit error messages make the purpose clear, although Django-specific conventions and the pagination tuple require some familiarity. Code length: Mostly concise, but trivial accessor methods and repeated context dictionary keys add verbosity. Action granularity: Statements generally perform one action each; tuple unpacking and chained page-source selection remain manageable. Reading flow: Consistent formatting and a natural progression from queryset retrieval through pagination to context construction support easy reading. Minor distractions include unused imports, a grammatically awkward docstring, and reassignment of variables such as page and queryset to different representations.