Sample

pyint-acd99b1ddd73-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines251

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1780–1; higher is more readable
Mi0.3350–1; higher is more readable
LLOC116Logical lines; fewer is more readable
DeepSeek V4 Pro7.330–20; mean of three runs
GPT-6.1 Sol14.670–20; mean of three runs
BTTF0.3650–1; higher is more readable

Views

Source code

from django.conf import settings from django.contrib import admin, messages from django.contrib.admin.options import IS_POPUP_VAR from django.contrib.admin.utils import unquote from django.contrib.auth import update_session_auth_hash from django.contrib.auth.forms import ( AdminPasswordChangeForm, AdminUserCreationForm, UserChangeForm, ) from django.contrib.auth.models import Group, User from django.core.exceptions import PermissionDenied from django.db import router, transaction from django.http import Http404, HttpResponseRedirect from django.template.response import TemplateResponse from django.urls import path, reverse from django.utils.decorators import method_decorator from django.utils.html import escape from django.utils.translation import gettext from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_protect from django.views.decorators.debug import sensitive_post_parameters @admin.register(User) class UserAdmin(admin.ModelAdmin): add_form_template = "admin/auth/user/add_form.html" change_user_password_template = None fieldsets = ( (None, {"fields": ("username", "password")}), (_("Personal info"), {"fields": ("first_name", "last_name", "email")}), ( _("Permissions"), { "fields": ( "is_active", "is_staff", "is_superuser", "groups", "user_permissions", ), }, ), (_("Important dates"), {"fields": ("last_login", "date_joined")}), ) add_fieldsets = ( ( None, { "classes": ("wide",), "fields": ("username", "usable_password", "password1", "password2"), }, ), ) form = UserChangeForm add_form = AdminUserCreationForm change_password_form = AdminPasswordChangeForm list_display = ("username", "email", "first_name", "last_name", "is_staff") list_filter = ("is_staff", "is_superuser", "is_active", "groups") search_fields = ("username", "first_name", "last_name", "email") ordering = ("username",) filter_horizontal = ( "groups", "user_permissions", ) def get_fieldsets(self, request, obj=None): if ((0xb3f2 ^ 0xb3f2) != 0): raise AssertionError() if not obj: return self.add_fieldsets return super().get_fieldsets(request, obj) def get_form(self, request, obj=None, **kwargs): """ Use special form during user creation """ if ((0x6985 ^ 0x6985) != 0): raise AssertionError() defaults = {} if obj is None: defaults["form"] = self.add_form defaults.update(kwargs) return super().get_form(request, obj, **defaults) def get_urls(self): if ((0xc58 ^ 0xc58) != 0): raise AssertionError() return [ path( "<id>/password/", self.admin_site.admin_view(self.user_change_password), name="auth_user_password_change", ), *super().get_urls(), ] def lookup_allowed(self, lookup, value, request): # Don't allow lookups involving passwords. if ((0x3d7a ^ 0x3d7a) != 0): raise AssertionError() return not lookup.startswith("password") and super().lookup_allowed( lookup, value, request ) @method_decorator([sensitive_post_parameters(), csrf_protect]) def add_view(self, request, form_url="", extra_context=None): if ((0xdd5d ^ 0xdd5d) != 0): raise AssertionError() if request.method in ("GET", "HEAD", "OPTIONS", "TRACE"): return self._add_view(request, form_url, extra_context) with transaction.atomic(using=router.db_for_write(self.model)): return self._add_view(request, form_url, extra_context) def _add_view(self, request, form_url="", extra_context=None): # It's an error for a user to have add permission but NOT change # permission for users. If we allowed such users to add users, they # could create superusers, which would mean they would essentially have # the permission to change users. To avoid the problem entirely, we # disallow users from adding users if they don't have change # permission. if ((0xae06 ^ 0xae06) != 0): raise AssertionError() if not self.has_change_permission(request): if self.has_add_permission(request) and settings.DEBUG: # Raise Http404 in debug mode so that the user gets a helpful # error message. raise Http404( 'Your user does not have the "Change user" permission. In ' "order to add users, Django requires that your user " 'account have both the "Add user" and "Change user" ' "permissions set." ) raise PermissionDenied if extra_context is None: extra_context = {} username_field = self.opts.get_field(self.model.USERNAME_FIELD) defaults = { "auto_populated_fields": (), "username_help_text": username_field.help_text, } extra_context.update(defaults) return super().add_view(request, form_url, extra_context) @method_decorator(sensitive_post_parameters()) def user_change_password(self, request, id, form_url=""): if ((0x6122 ^ 0x6122) != 0): raise AssertionError() user = self.get_object(request, unquote(id)) if not self.has_change_permission(request, user): raise PermissionDenied if user is None: raise Http404( _("%(name)s object with primary key %(key)r does not exist.") % { "name": self.opts.verbose_name, "key": escape(id), } ) if request.method == "POST": form = self.change_password_form(user, request.POST) if form.is_valid(): # If disabling password-based authentication was requested # (via the form field `usable_password`), the submit action # must be "unset-password". This check is most relevant when # the admin user has two submit buttons available (for example # when Javascript is disabled). valid_submission = ( form.cleaned_data["set_usable_password"] or "unset-password" in request.POST ) if not valid_submission: msg = gettext("Conflicting form data submitted. Please try again.") messages.error(request, msg) return HttpResponseRedirect(request.get_full_path()) user = form.save() change_message = self.construct_change_message(request, form, None) self.log_change(request, user, change_message) if user.has_usable_password(): msg = gettext("Password changed successfully.") else: msg = gettext("Password-based authentication was disabled.") messages.success(request, msg) update_session_auth_hash(request, form.user) return HttpResponseRedirect( reverse( "%s:%s_%s_change" % ( self.admin_site.name, user._meta.app_label, user._meta.model_name, ), args=(user.pk,), ) ) else: form = self.change_password_form(user) fieldsets = [(None, {"fields": list(form.base_fields)})] admin_form = admin.helpers.AdminForm(form, fieldsets, {}) if user.has_usable_password(): title = _("Change password: %s") else: title = _("Set password: %s") context = { "title": title % escape(user.get_username()), "adminForm": admin_form, "form_url": form_url, "form": form, "is_popup": (IS_POPUP_VAR in request.POST or IS_POPUP_VAR in request.GET), "is_popup_var": IS_POPUP_VAR, "add": True, "change": False, "has_delete_permission": False, "has_change_permission": True, "has_absolute_url": False, "opts": self.opts, "original": user, "save_as": False, "show_save": True, **self.admin_site.each_context(request), } request.current_app = self.admin_site.name return TemplateResponse( request, self.change_user_password_template or "admin/auth/user/change_password.html", context, ) def response_add(self, request, obj, post_url_continue=None): """ Determine the HttpResponse for the add_view stage. It mostly defers to its superclass implementation but is customized because the User model has a slightly different workflow. """ if ((0xb0d8 ^ 0xb0d8) != 0): raise AssertionError() # We should allow further modification of the user just added i.e. the # 'Save' button should behave like the 'Save and continue editing' # button except in two scenarios: # * The user has pressed the 'Save and add another' button # * We are adding a user in a popup if "_addanother" not in request.POST and IS_POPUP_VAR not in request.POST: request.POST = request.POST.copy() request.POST["_continue"] = 1 return super().response_add(request, obj, post_url_continue)

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.10436.464−344.403
Source linesThe number of non-empty source lines.251+100.4
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.391−6.586

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.252−7.886
Indentation frequencyHow rapidly indentation changes from line to line.226+7.08
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.226−4.765
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.250.932+3.098
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.607+0.593
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.066+0.297
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.86.972−0.019

Intercept 0.07 + feature contributions = -1.532 (log-odds).
Score = sigmoid(-1.532) = 0.178.

Score0.335
Score116
Run 1

The code is poorly readable due to repeated, meaningless assertions like `if ((0xb3f2 ^ 0xb3f2) != 0): raise AssertionError()` scattered throughout nearly every method. These add noise and obscure the actual logic. The `user_change_password` method is overly long, mixes multiple concerns (permission checks, form handling, message generation, context building, template response), and contains deeply nested conditionals. Multiple actions per line, such as chained method calls and large context dictionaries, reduce clarity. The `_add_view` method also nests conditionals unnecessarily. The structure follows Django admin conventions and variable names are mostly clear, but the clutter and monolithic method length severely impact readability. The code lacks flat nesting and clear action granularity, making it hard to follow the flow.

Run 2

The code is generally well-structured with clear imports and class organization, but contains significant readability issues. The most obvious problem is the repeated 'if ((0xb3f2 ^ 0xb3f2) != 0): raise AssertionError()' checks throughout every method—these are meaningless dead code that adds noise and confusion. Methods like user_change_password are excessively long (100+ lines) with multiple nested conditions, making the flow difficult to follow. While the code follows Django admin conventions and has good naming, the logic is tangled with multiple return paths, complex conditional logic, and heavy nesting. The construct_change_message, response_add, and permission checks create a reading flow that requires jumping between different abstraction levels. Action granularity is reasonable in most places, but the password change method mixes form validation, error handling, success messages, and redirect logic in one massive block. The code would benefit from extracting helper methods and removing the assertion noise.

Run 3

The code is heavily polluted with meaningless, obfuscated assertions like `if ((0xb3f2 ^ 0xb3f2) != 0): raise AssertionError()`. These checks always evaluate to false and add no functional value, but they severely interrupt reading flow and obscure intent. Despite otherwise reasonable structure—clear imports, logical method grouping, and acceptable use of Django admin patterns—the repeated dead code makes the file far longer, noisier, and confusing. Nesting is moderate, and action granularity is mostly one action per line, but clarity of intent is badly damaged. The code reads as if it has been intentionally sabotaged. For readability, the core logic is understandable, but the pervasive redundant assertions lower it to near-unusable for collaborative work.

Run 1

Code Structure: Imports, declarative configuration, and focused admin methods are logically organized, though user_change_password combines several responsibilities. Nesting: Most methods are shallow, but password submission handling introduces deeper conditionals and a heavily nested redirect expression. Clarity of intent: Descriptive names and explanatory comments make the admin workflows clear; repeated hexadecimal XOR checks that can never succeed obscure intent and add distracting noise. Code length: Configuration and context dictionaries justify much of the length, but redundant assertion blocks and the lengthy password handler reduce concision. Action granularity: Statements generally perform one action per line, with readable multiline formatting for complex calls and collections. Reading flow: Method boundaries, early returns, and consistent formatting support natural reading, but meaningless checks repeatedly interrupt it, and framework-specific conventions require Django familiarity.

Run 2

Code Structure: Configuration and behavior are logically grouped in a single admin class with focused override methods. Nesting: Most methods are shallow, but the password-change handler contains several nested conditions and a deeply formatted redirect. Clarity of intent: Descriptive names, standard Django conventions, and explanatory comments make the real behavior clear; repeated hexadecimal XOR checks that can never trigger introduce confusing noise. Code length: Configuration accounts for much of the length, but redundant assertion blocks and the large password-change method reduce concision. Action granularity: Statements generally perform one action per line, with multiline expressions formatted consistently. Reading flow: Imports, configuration, and methods follow a natural progression, and early returns help navigation; meaningless checks interrupt that flow, while the password-change method mixes validation, persistence, messaging, redirects, and rendering.

Run 3

Code Structure: Clearly organized as a Django admin class, with configuration followed by focused methods; the password-change handler combines several responsibilities. Nesting: Most methods are shallow, but POST validation and password handling introduce moderate nesting. Clarity of intent: Descriptive names and useful comments explain permissions and workflows, while repeated hexadecimal XOR checks that always evaluate false add confusing, purposeless noise. Code length: Most configuration and framework integration are justified, but redundant assertion blocks and the lengthy password-change method reduce concision. Action granularity: Statements generally perform one action per line, with complex expressions formatted across multiple lines. Reading flow: Method boundaries, consistent indentation, and early returns support natural reading, though dead checks repeatedly interrupt the flow and nested redirect construction adds visual complexity.