Sample

pyint-c63662bc16d1-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines64

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6680–1; higher is more readable
Mi0.5130–1; higher is more readable
LLOC26Logical lines; fewer is more readable
DeepSeek V4 Pro140–20; mean of three runs
GPT-6.1 Sol15.670–20; mean of three runs
BTTF0.6270–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 (not self.get_allow_future() and date > datetime.date.today()): pass else: 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.1711.55−56.481
Source linesThe number of non-empty source lines.64+25.6
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.49−6.735

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.64−1.23
Indentation frequencyHow rapidly indentation changes from line to line.55+1.165
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.55−0.841
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.84.954+0.566
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.63.93+0.484
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.054+0.418
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.938+0.068

Intercept 0.07 + feature contributions = 0.7 (log-odds).
Score = sigmoid(0.7) = 0.668.

Score0.513
Score26
Run 1

The code is generally clear with sensible docstrings and comments, and the class hierarchy is logical. However, readability is undermined by an awkward conditional with a no-op branch ('if not (...) pass else raise') which should be inverted, and by the get_object method doing multiple tasks (parsing date, checking future, filtering, delegating). The date lookup construction is concise but obscures the actual filter logic. Nesting is acceptable and imports are well-structured.

Run 2

The code is generally well-organized with clear imports, docstrings, and a logical flow. Structure is decent: it follows Django class-based view patterns and separates date parsing, queryset filtering, and future-date validation. However, readability suffers in a few places. The conditional 'if not (not self.get_allow_future() and date > datetime.date.today()): pass else: raise...' is a double negative that obscures intent and violates clarity of intent and action granularity. It should be rewritten as a simple positive check. The inline template string for the 404 message is verbose and hard to scan. Nesting is shallow, and line lengths are mostly reasonable. Variable names like 'qs' are conventional but slightly terse. Overall, the code is understandable for experienced Django developers but could be more concise and direct in its conditional logic.

Run 3

The code is reasonably structured but has readability issues that prevent a higher score. The conditional logic using `if not (not self.get_allow_future() and date > datetime.date.today()): pass else: raise Http404` is unnecessarily convoluted and violates clarity of intent. A simple `if not allow_future and date > today: raise Http404` would be far clearer. The nesting is minimal and flat, which is good, and actions are mostly one per line. However, the double negative in the conditional hurts reading flow, and the `pass` statement adds noise. The method is concise but could be improved with early returns and clearer boolean logic. The docstring helps clarify purpose, but the implementation doesn't match that clarity. Overall, the code structure is sound, but the confusing conditional pattern and unnecessary negation make it harder to read than it should be.

Run 1

Code Structure: The method is logically organized into date extraction, queryset selection, validation, filtering, and retrieval. Nesting: Mostly flat, with only one conditional, although its empty pass branch is unnecessary. Clarity of intent: Descriptive method names, a helpful docstring, and comments explain the purpose, but the double-negative future-date condition obscures otherwise simple validation. Code length: Reasonably concise; removing the pass/else construction would shorten and clarify it. Action granularity: Statements generally perform one action each, and multiline calls and mappings are formatted clearly. Reading flow: The sequence is natural, but the inverted conditional interrupts comprehension. Mixins and the date-parsing helper are not defined in the snippet, requiring external context.

Run 2

Code Structure: The class and method are logically organized around parsing a date, validating it, filtering a queryset, and retrieving an object. Nesting: Mostly flat, with only a shallow conditional. Clarity of intent: Descriptive method names, a docstring, and comments explain the purpose, but the double-negated future-date condition and empty pass branch obscure straightforward validation. External mixins and helpers require context. Code length: The method is reasonably concise, though the conditional could be simplified and several imports appear unused in this snippet. Action granularity: Statements generally perform one action each, and multiline arguments and error formatting are legible. Reading flow: The sequence is natural, but the inverted if/else interrupts it; directly raising when future dates are disallowed would improve readability.

Run 3

Code Structure: The method is logically organized into date extraction, queryset selection, future-date validation, filtering, and object retrieval. Nesting: Mostly flat, with only one conditional, although its empty pass branch is unnecessary. Clarity of intent: Descriptive method names, a class docstring, and comments explain the purpose well; the double-negative condition obscures the future-date restriction. Code length: Generally concise, but the pass/else construction and several imports unused in this snippet add clutter. Action granularity: Each statement performs a distinct action, and multiline calls and dictionary formatting remain readable. Reading flow: Execution follows a natural sequence, but the inverted conditional interrupts comprehension. Referenced mixins and helper functions are not shown, requiring external context.