Sample

pyint-f46b9b298fda-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines150

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4460–1; higher is more readable
Mi0.3480–1; higher is more readable
LLOC81Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.5410–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 not (ordering): pass else: 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 not (page == "last"): raise Http404( _("Page is not “last”, nor can it be converted to an int.") ) else: page_number = paginator.num_pages 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 not (page_size): context = { "paginator": None, "page_obj": None, "is_paginated": False, "object_list": queryset, } else: paginator, page, queryset, is_paginated = self.paginate_queryset( queryset, page_size ) context = { "paginator": paginator, "page_obj": page, "is_paginated": is_paginated, "object_list": queryset, } if not (context_object_name is not None): pass else: 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.4423.662−145.981
Source linesThe number of non-empty source lines.150+60
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.3−6.45

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.151−4.31
Indentation frequencyHow rapidly indentation changes from line to line.136+3.967
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.137−2.723
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.149.833+1.685
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.82.364+0.524
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.419
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.947+0.152

Intercept 0.07 + feature contributions = -0.216 (log-odds).
Score = sigmoid(-0.216) = 0.446.

Score0.348
Score81
Run 1

The code has solid docstrings and clear class attributes, but its readability is undermined by several issues. The structure is mostly logical, yet methods like get_queryset and paginate_queryset are convoluted. Nesting is problematic: the `if not (ordering): pass` and `if not (page_size):` patterns create unnecessary branches and inverted logic, making the flow harder to follow. Intent is generally clear but obscured by odd constructs such as `if not (page == "last")` and the awkward `if not (context_object_name is not None): pass`. Code length is reasonable, though some expressions could be more concise. Action granularity is mixed; most lines perform one action, but some conditionals pack too much logic. Reading flow suffers from these inverted conditions and pass statements, forcing readers to mentally invert the logic. Replacing these with early returns, positive conditionals, and direct else handling would significantly improve readability.

Run 2

The code is generally well-structured and readable, with clear docstrings and class attributes. However, it contains several stylistic inconsistencies that reduce readability. The `if not (ordering): pass else:` pattern in `get_queryset` is unnecessarily awkward compared to a simple `if ordering:` check. Similarly, `if not (page_size):` and `if not (context_object_name is not None): pass else:` patterns add cognitive overhead. The `paginate_queryset` method handles multiple concerns (parameter extraction, type conversion, error handling) with moderate nesting and exception flow that could be clearer. While the code is concise overall and actions are generally well-separated, the inconsistent conditional style and some convoluted boolean expressions make the intent harder to follow than necessary. The reading flow is mostly natural, but these unusual patterns interrupt it.

Run 3

The code is generally well-structured with clear method separation, docstrings, and consistent naming. The main readability issues are unnecessary 'if not (condition): pass else:' constructs in get_queryset, paginate_queryset, and get_context_data, which add noise and obscure intent. These could be simplified to flat 'if condition:' blocks. The paginate_queryset method has moderate nesting (two try/except blocks plus nested conditionals), but remains understandable. Action granularity is mostly one-per-line, though dictionary formatting in context creation is verbose. Import order and class-level attributes are clean. Overall the code is readable and follows Django conventions, but the awkward conditional patterns prevent a higher score.

Run 1

Code Structure: Well-organized mixin with focused methods separating queryset retrieval, pagination, configuration, and context construction. Nesting: Generally shallow, although unnecessary else branches and pass statements add avoidable complexity. Clarity of intent: Descriptive method names, meaningful variables, docstrings, and informative exceptions make responsibilities clear; negated conditions such as 'if not (context_object_name is not None)' are harder to parse. Code length: Mostly appropriate for an extensible Django mixin, but duplicated context dictionaries and redundant conditionals introduce verbosity. Action granularity: Statements generally perform one action each, with multiline calls and dictionaries formatted clearly. Reading flow: Methods follow a coherent progression and use consistent formatting, though inverted checks and no-op branches interrupt otherwise natural control flow.

Run 2

Code Structure: Well-organized mixin with focused methods separating queryset retrieval, pagination, configuration, and context construction. Nesting: Mostly shallow, although unnecessary pass/else branches introduce avoidable indentation. Clarity of intent: Descriptive method and variable names, docstrings, and informative exceptions make the purpose clear; inverted conditions such as 'if not (context_object_name is not None)' require extra mental effort. Code length: Generally appropriate for an extensible framework component, but redundant branches and repeated context dictionaries add verbosity. Action granularity: Statements generally perform one action per line, with readable formatting for longer calls and dictionaries. Reading flow: Methods follow natural processing sequences, but negative conditions, redundant parentheses, and reuse of 'page' for different types slightly disrupt comprehension.

Run 3

Code Structure: Well-organized mixin with focused methods separating queryset retrieval, pagination, configuration, and context construction. Nesting: Generally shallow, but unnecessary pass/else branches and negated conditions add avoidable nesting. Clarity of intent: Descriptive names, docstrings, and informative exceptions make the purpose clear; expressions such as 'if not (context_object_name is not None)' obscure simple checks. Code length: Mostly appropriate for extensible framework code, although repeated context dictionaries and redundant branches add verbosity. Action granularity: Statements generally perform one action each, with multiline calls formatted cleanly; tuple unpacking remains readable. Reading flow: Methods follow a coherent progression, and formatting is consistent. However, inverted conditions, redundant parentheses, and reusing 'page' for both an input value and a page object slightly interrupt comprehension.