Sample

pyint-28b1c761299c-I12

Inline all eligible single-use intermediate local variables

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 Sol180–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 well-structured, with clear class responsibilities and logical method flow. It uses flat control flow with only one if statement, and actions are split across lines sensibly. The intent is explicit - filtering a queryset by date before delegating to the parent get_object. Comments explain non-obvious behavior without being excessive. Variable names are descriptive (qs, lookup_kwargs, year/month/day). The only minor downsides: underscores in _date_from_string and _make_single_date_lookup suggest private helpers, but this is idiomatic Django. The function is concise yet readable, combining multiple imports neatly. Overall, highly maintainable code that balances brevity with clarity.

Run 3

The code is well-structured and follows Django conventions clearly. The imports are organized. Class definition and method are logically placed. Nesting is mostly flat, with only one conditional block that handles a single case. Variable names are descriptive (year, month, day, date, qs, lookup_kwargs), making the intent clear. Comments are helpful and not excessive. However, the get_object method has multiple logical steps involving date parsing, queryset retrieval, conditional checking, filtering, and super() call, which is typical for a base class but may feel slightly dense. The method is still readable due to clear line separation and consistent formatting. The action granularity is adequate. Reading flow is natural from input extraction to final return.

Run 1

Code Structure: The class and method follow a logical sequence: extract date components, construct the date, select a queryset, validate future access, filter, and retrieve the object. Nesting: Minimal nesting, with a single conditional and no loops. Clarity of intent: The class docstring, descriptive method names, and comments clearly explain the date-based lookup; however, externally defined mixins and helpers require additional context, and 'qs' is less descriptive than 'queryset'. Code length: Appropriately concise, though several imports are unused in this snippet. Action granularity: Each statement performs a distinct action, and multiline calls improve legibility. Reading flow: Execution proceeds naturally from input preparation through validation to retrieval; the formatted error message briefly interrupts the flow but remains readable.

Run 2

Code Structure: The method is logically organized into date extraction, parsing, queryset selection, future-date validation, filtering, and object retrieval. Nesting: Control flow is shallow, with only one conditional; nested formatting adds some visual complexity. Clarity of intent: Descriptive method names, a useful class docstring, and explanatory comments make the purpose clear, though mixins and helper definitions are outside the snippet and 'qs' is abbreviated. Code length: The implementation is reasonably concise, but several imports are unused in this excerpt and the exception message occupies substantial space. Action granularity: Each statement performs a focused action, with multiline calls formatted cleanly. Reading flow: Execution follows a natural progression from URL date inputs to the final object lookup, with whitespace separating meaningful stages.

Run 3

Code Structure: The class and method are logically organized into date extraction, queryset selection, validation, filtering, and retrieval. Nesting: Only one conditional is used, keeping control flow shallow. Clarity of intent: Descriptive method names, a focused docstring, and explanatory comments make the purpose clear, although external mixins and helper functions require surrounding context, and 'qs' is somewhat abbreviated. Code length: The implementation is concise overall; multiline date parsing and exception formatting add length but remain readable. Action granularity: Each statement generally performs one action, with a straightforward conditional expression for queryset selection. Reading flow: Execution proceeds naturally from request parameters to the final object lookup. Some imports appear unused in this excerpt, adding minor visual clutter.