Sample

pyint-a0efaa60fb1f-I13

Lower every eligible synchronous for loop to a while loop

Matched original source

Lines62

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6730–1; higher is more readable
Mi0.5130–1; higher is more readable
LLOC25Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol17.670–20; mean of three runs
BTTF0.6330–1; higher is more readable

Views

Source code

import datetime from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db import models from django.http import Http404 from django.utils import timezone from django.utils.functional import cached_property from django.utils.translation import gettext as _ from django.views.generic.base import View from django.views.generic.detail import ( BaseDetailView, SingleObjectTemplateResponseMixin, ) from django.views.generic.list import ( MultipleObjectMixin, MultipleObjectTemplateResponseMixin, ) class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailView): """ Base detail view for a single object on a single date; this differs from the standard DetailView by accepting a year/month/day in the URL. This requires subclassing to provide a response mixin. """ def get_object(self, queryset=None): """Get the object this request displays.""" year = self.get_year() month = self.get_month() day = self.get_day() date = _date_from_string( year, self.get_year_format(), month, self.get_month_format(), day, self.get_day_format(), ) # Use a custom queryset if provided qs = self.get_queryset() if queryset is None else queryset if not self.get_allow_future() and date > datetime.date.today(): raise Http404( _( "Future %(verbose_name_plural)s not available because " "%(class_name)s.allow_future is False." ) % { "verbose_name_plural": qs.model._meta.verbose_name_plural, "class_name": self.__class__.__name__, } ) # Filter down a queryset from self.queryset using the date from the # URL. This'll get passed as the queryset to DetailView.get_object, # which'll handle the 404 lookup_kwargs = self._make_single_date_lookup(date) qs = qs.filter(**lookup_kwargs) return super().get_object(queryset=qs)

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.1668.406−55.057
Source linesThe number of non-empty source lines.62+24.8
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.509−6.764

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.62−1.159
Indentation frequencyHow rapidly indentation changes from line to line.53+1.096
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.53−0.795
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.84.873+0.565
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.61.942+0.456
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.053+0.424
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.84.968+0.066

Intercept 0.07 + feature contributions = 0.723 (log-odds).
Score = sigmoid(0.723) = 0.673.

Score0.513
Score25
Run 1

The code is generally readable with clear imports, logical structure, and good variable naming. The main method is well-organized and focused, using meaningful intermediate variables like `year`, `month`, `day`, and `lookup_kwargs`. Comments explain non-obvious behavior, and action granularity is appropriate. However, the error-raising block contains dense string formatting that interrupts flow, and the `_date_from_string` call breaks from class methods to use a standalone function, which could confuse intent. The mixin inheritance with multiple base classes may require added cognitive load, though this is a common Django pattern. Overall, the code is concise but could benefit from extracting error handling or simplifying formatting logic.

Run 2

The code is highly readable with clear logical structure: imports grouped by source, a focused view class, and a single well-defined method. Nesting is minimal, with only one conditional and no deep indentation. Intent is explicit through descriptive method/variable names and helpful comments explaining non-obvious steps. Code length is concise and avoids unnecessary repetition. Action granularity is mostly one action per line, improving debuggability. Reading flow is natural, progressing from extracting URL date components, to future-date validation, to queryset filtering and delegation to the parent class. Minor deductions: the long format string with placeholders slightly reduces readability, and the conditional queryset assignment could be simplified. Overall, the code follows Django conventions and is easy to follow.

Run 3

The code is highly readable with clear structure and organization. It follows Django conventions, has logical grouping of imports and a well-structured class with a single focused method. The nesting is minimal—only one conditional block—and the reading flow is natural, moving from argument extraction to date parsing, validation, query filtering, and delegation. Variable names like 'year', 'month', 'day', and 'qs' are clear, and comments explain non-obvious steps. The docstring provides useful context about the class purpose. The only minor issues are the slightly long error-raising block with string formatting, and the method could arguably be split into smaller helpers, but overall it is concise and readable.

Run 1

Code Structure: The class and method are logically organized, separating date extraction, queryset selection, validation, filtering, and retrieval. Nesting: Control flow is shallow, with a single conditional and no nested branches. Clarity of intent: Descriptive method names, a useful class docstring, and explanatory comments make the purpose clear; however, qs is abbreviated and several mixins and helpers are not defined in the snippet. Code length: The implementation is reasonably concise, though some comments repeat obvious operations and several imports are unused here. Action granularity: Most statements perform one clear action, and multiline calls improve legibility. Reading flow: Execution follows a natural sequence from URL date parsing to validation and object retrieval, although the verbose exception construction briefly interrupts that flow.

Run 2

Code Structure: The method is logically organized into date extraction, queryset selection, future-date validation, filtering, and object retrieval. Nesting: A single conditional keeps control flow shallow; multiline error formatting adds visual depth without complex branching. Clarity of intent: Descriptive method names, a useful class docstring, and contextual comments make the purpose clear, although 'qs' is abbreviated and several mixins and helpers are not defined in the excerpt. Code length: The implementation is reasonably concise, but unused imports and verbose exception construction add some overhead. Action granularity: Most statements perform one clear action, with multiline expressions formatted consistently. Reading flow: Execution proceeds naturally from request parameters to validation and retrieval, though framework-specific inheritance and helper calls require some Django familiarity.

Run 3

Code Structure: The method follows a logical sequence: extract date components, parse the date, select a queryset, validate future-date access, filter, and delegate retrieval. Nesting: Control flow is shallow, with only one conditional; the multiline exception formatting adds visual depth but little complexity. Clarity of intent: Descriptive method names, a class docstring, and targeted comments explain the purpose well, though undefined mixins/helpers and the abbreviated name 'qs' require some external context. Code length: The implementation is reasonably concise, although several imports are unused in this excerpt and exception formatting occupies substantial space. Action granularity: Each statement generally performs one distinct action, with multiline arguments improving readability. Reading flow: Execution proceeds naturally from inputs to validation to retrieval, with whitespace separating meaningful stages.