Sample

pyint-b7f42149a866-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines148

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4150–1; higher is more readable
Mi0.3570–1; higher is more readable
LLOC81Logical lines; fewer is more readable
DeepSeek V4 Pro15.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.4820–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 a = 2 b = -1 page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or (a + b) 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.4400.78−145.226
Source linesThe number of non-empty source lines.148+59.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.312−6.468

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.149−4.239
Indentation frequencyHow rapidly indentation changes from line to line.134+3.898
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.135−2.677
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.147.867+1.657
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.88.946+0.631
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.422
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.88.953−0.102

Intercept 0.07 + feature contributions = -0.342 (log-odds).
Score = sigmoid(-0.342) = 0.415.

Score0.357
Score81
Run 1

The code follows Django view mixin conventions with a clear class structure and well-defined methods, making logical organization good. Most methods are flat with minimal nesting, though paginate_queryset has some nested try/except blocks. Intent is generally clear, with descriptive method names and docstrings. However, the variables 'a = 2' and 'b = -1' in paginate_queryset are cryptic and unnecessary—this significantly hurts clarity. The page calculation line is overly long, combining multiple operations and reducing action granularity. Elsewhere, the code is concise and avoids redundant verbosity. Reading flow is natural, with methods ordered logically: queryset retrieval, ordering, pagination, then context construction. Overall, the code is quite readable but loses points for the intentional obfuscation and the lengthy pagination line that combines several actions.

Run 2

The code is generally well-structured with clear method separation and good docstrings. It follows Django conventions and has readable naming. However, there are notable issues: the variables 'a' and 'b' in paginate_queryset are poorly named and make the page calculation confusing; the list of imports at the top is unused; and some methods are overly verbose. The nesting is mostly flat, but the conditionals in get_queryset could be simplified. The reading flow is natural overall, but magic numbers and unclear variable names break the flow in the pagination method. The code would benefit from removing unused imports and using more descriptive variables.

Run 3

Overall the code is well-structured, with clear separation of methods and sensible naming that conveys intent. Docstrings and comments explain non-obvious behavior, aiding readability. Nesting is generally moderate but becomes slightly deep in paginate_queryset due to exception handling and conditionals. The odd lines `a = 2` and `b = -1` used as a fallback for the page number are confusing and hurt clarity. The code is concise for a real-world mixin, though `get_context_data` has some repetition. Action granularity is mostly one action per line, but the page variable assignment packs several operations into one line, reducing clarity. Reading flow is natural, following a logical sequence from queryset retrieval to pagination to context building.

Run 1

Code Structure: Well-organized mixin with focused methods separating queryset selection, pagination, and context construction. Nesting: Mostly shallow, with manageable nested conditionals and clear exception handling. Clarity of intent: Descriptive method names, configuration attributes, and docstrings explain behavior well; however, unexplained variables a and b obscure the default page value, and reusing page for both input and a page object adds ambiguity. Code length: Generally proportionate to functionality, though duplicated context dictionaries and the unnecessary arithmetic introduce verbosity. Action granularity: Statements generally perform one action each, with readable multiline calls; the chained page fallback packs several decisions into one line. Reading flow: Methods follow a natural progression, and consistent formatting supports scanning, although helper-method indirection requires some navigation.

Run 2

Code Structure: Well-organized mixin with focused methods separating queryset retrieval, pagination, and context construction. Nesting: Mostly shallow, with manageable nested conditionals and straightforward exception handling. Clarity of intent: Descriptive method names, configuration attributes, and docstrings make the purpose clear; however, unexplained variables a and b and the computed default (a + b) obscure the simple default page number. Code length: Generally appropriate, though duplicated context dictionaries and trivial accessor methods add verbosity; the accessors also provide clear extension points. Action granularity: Statements generally perform one action per line, with readable multiline calls and dictionaries. Reading flow: Methods follow a coherent progression and use consistent formatting, but Django-specific conventions require framework knowledge, and the artificial page-default calculation interrupts otherwise natural flow.

Run 3

Code Structure: Well organized into focused methods, with configuration attributes grouped at the top. Nesting: Mostly shallow, with manageable conditional branches and exception handling. Clarity of intent: Descriptive method names and docstrings explain queryset retrieval, pagination, and context creation; however, a = 2 and b = -1 obscure the default page value of 1, and page changes from an input value to a page object. Code length: Generally appropriate for the functionality, though duplicated context dictionaries and unnecessary arithmetic add verbosity. Action granularity: Statements generally perform one action per line; tuple unpacking and chained fallback expressions remain understandable. Reading flow: Methods follow a coherent progression from queryset handling through pagination to context construction, although framework inheritance and hook methods require some Django familiarity.