Sample

pyint-be949521de88-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines235

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1980–1; higher is more readable
Mi0.3350–1; higher is more readable
LLOC100Logical lines; fewer is more readable
DeepSeek V4 Pro4.670–20; mean of three runs
GPT-6.1 Sol11.330–20; mean of three runs
BTTF0.3790–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(self, req, obj2=None): if not obj2: return self.add_fieldsets return super().get_fieldsets(req, obj2) def get2(self, req2, obj3=None, **kwa): """ Use special form during user creation """ def2 = {} if obj3 is None: def2["form"] = self.add_form def2.update(kwa) return super().get_form(req2, obj3, **def2) def get3(self): return [ path( "<id>/password/", self.admin_site.admin_view(self.user2), name="auth_user_password_change", ), *super().get_urls(), ] def lookup2(self, loo, val, req3): # Don't allow lookups involving passwords. return not loo.startswith("password") and super().lookup_allowed( loo, val, req3 ) @method_decorator([sensitive_post_parameters(), csrf_protect]) def add(self, req4, form2="", extra=None): if req4.method in ("GET", "HEAD", "OPTIONS", "TRACE"): return self.add2(req4, form2, extra) with transaction.atomic(using=router.db_for_write(self.model)): return self.add2(req4, form2, extra) def add2(self, req5, form3="", extra2=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 not self.has_change_permission(req5): if self.has_add_permission(req5) 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 extra2 is None: extra2 = {} username = self.opts.get_field(self.model.USERNAME_FIELD) def3 = { "auto_populated_fields": (), "username_help_text": username.help_text, } extra2.update(def3) return super().add_view(req5, form3, extra2) @method_decorator(sensitive_post_parameters()) def user2(self, req6, id2, form4=""): use = self.get_object(req6, unquote(id2)) if not self.has_change_permission(req6, use): raise PermissionDenied if use is None: raise Http404( _("%(name)s object with primary key %(key)r does not exist.") % { "name": self.opts.verbose_name, "key": escape(id2), } ) if req6.method == "POST": for2 = self.change_password_form(use, req6.POST) if for2.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 = ( for2.cleaned_data["set_usable_password"] or "unset-password" in req6.POST ) if not valid: msg2 = gettext("Conflicting form data submitted. Please try again.") messages.error(req6, msg2) return HttpResponseRedirect(req6.get_full_path()) use = for2.save() change = self.construct_change_message(req6, for2, None) self.log_change(req6, use, change) if use.has_usable_password(): msg2 = gettext("Password changed successfully.") else: msg2 = gettext("Password-based authentication was disabled.") messages.success(req6, msg2) update_session_auth_hash(req6, for2.user) return HttpResponseRedirect( reverse( "%s:%s_%s_change" % ( self.admin_site.name, use._meta.app_label, use._meta.model_name, ), args=(use.pk,), ) ) else: for2 = self.change_password_form(use) fie = [(None, {"fields": list(for2.base_fields)})] admin2 = admin.helpers.AdminForm(for2, fie, {}) if use.has_usable_password(): tit = _("Change password: %s") else: tit = _("Set password: %s") con = { "title": tit % escape(use.get_username()), "adminForm": admin2, "form_url": form4, "form": for2, "is_popup": (IS_POPUP_VAR in req6.POST or IS_POPUP_VAR in req6.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": use, "save_as": False, "show_save": True, **self.admin_site.each_context(req6), } req6.current_app = self.admin_site.name return TemplateResponse( req6, self.change_user_password_template or "admin/auth/user/change_password.html", con, ) def response(self, req7, obj4, post=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. """ # 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 req7.POST and IS_POPUP_VAR not in req7.POST: req7.POST = req7.POST.copy() req7.POST["_continue"] = 1 return super().response_add(req7, obj4, post)

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.9538.49−314.77
Source linesThe number of non-empty source lines.235+94
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.371−6.556

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.236−7.32
Indentation frequencyHow rapidly indentation changes from line to line.210+6.527
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.210−4.398
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.234.91+2.874
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.894+0.598
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.065+0.313
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.87.992−0.062

Intercept 0.07 + feature contributions = -1.398 (log-odds).
Score = sigmoid(-1.398) = 0.198.

Score0.335
Score100
Run 1

The code suffers from extremely poor naming (e.g., `get`, `get2`, `get3`, `lookup2`, `add`, `add2`, `user2`, parameters like `req3`, `obj2`, `def2`), which obscures intent and breaks readability. Many methods are misleading or incorrectly overridden. Structure is tangled: some methods contain large monolithic blocks with multiple actions and mixed responsibilities (e.g., `user2`). Nesting is moderately deep in places, and reading flow is unnatural because method names do not reflect purpose. Although the class layout starts conventionally with attributes and fieldsets, the subsequently malformed method overrides destroy clarity. There is some concise grouping of admin options, but overall the code requires significant effort to understand. It rates poorly because clear intent, structural organization, and action granularity are severely compromised despite partial Django conventions.

Run 2

This code is severely unreadable due to pervasive non-descriptive naming (get2, get3, user2, add2, req4, obj3, def3, for2), which obscures intent and forces constant mental mapping. It is unnecessarily verbose and convoluted, with methods that do too much and contain deeply nested conditionals (especially user2). The structure mimics Django's UserAdmin but adds layers of confusion through renamed/overridden methods without clear purpose. Action granularity is poor: many lines bundle multiple operations or obscure logic. Reading flow is disorganized, mixing custom logic with Django internals in a way that is hard to follow. While there are some comments, they do not compensate for the cryptic identifiers and tangled control flow. The code appears to be an obfuscated version of standard Django admin user management, making it harder to maintain and debug.

Run 3

The code is very difficult to read due to poor naming conventions. Functions and variables use non-descriptive names like `get`, `get2`, `get3`, `lookup2`, `obj2`, `req3`, `def2`, `def3`, `for2`, `use`, `tit`, `con`, etc. Many method overrides (e.g., `get`, `response`) seem broken or misdirected (calling `self.add_fieldsets` from `get`). The `get2` method shadows intended behavior with confusing parameters and only conditionally sets the form. Deeply nested logic, especially in `user2` and `add2`, makes the flow hard to follow. Critical actions and conditional branches are packed into long blocks. There is little separation of concerns or logical grouping, and the overall purpose of each method is often ambiguous despite docstrings. The code relies heavily on unexplained abbreviations and parameter re-declaration, making it hard to maintain or debug.

Run 1

1. Code Structure: Imports, configuration attributes, and separate methods provide logical organization, although the password-change method combines validation, persistence, messaging, and rendering. 2. Nesting: Most methods are relatively flat, but the POST/form-validation/password-handling branches introduce moderate nesting. 3. Clarity of intent: Django APIs, configuration names, and explanatory comments clarify behavior, but generic names such as get2, user2, req6, for2, and con substantially obscure intent; renamed framework hooks also make their intended roles harder to recognize. 4. Code length: Most configuration and formatting are justified, though lengthy comments and the large password-change method slow scanning. 5. Action granularity: Statements generally perform one action per line, with readable multiline expressions and no compressed statement chains. 6. Reading flow: Consistent indentation, spacing, and early exits support natural flow, but numbered identifiers require repeated context tracking and the long workflow interrupts easy comprehension.

Run 2

Code Structure: Configuration and behavior are logically separated into methods, but generic method names obscure their roles and relationships to Django hooks. Nesting: Most methods are shallow, though the password-change handler has several nested branches and a nested redirect expression. Clarity of intent: Django APIs, comments, and configuration convey the overall purpose, but names such as get2, req6, for2, and con substantially hinder understanding. Code length: Much of the length is justified by configuration and security checks, although the password handler combines several responsibilities and comments are occasionally verbose. Action granularity: Statements generally perform one action per line, with clear formatting of collections and calls. Reading flow: Configuration-first organization and early permission checks support a natural flow, but readers must repeatedly infer variable meanings and mentally translate renamed methods into their intended framework roles.

Run 3

Code Structure: Configuration and behavior are separated into methods, but generic method names obscure their roles and intended Django overrides. Nesting: Most methods remain shallow, though the password-change handler combines several nested branches. Clarity of intent: Comments, framework calls, and configuration names explain the overall purpose, but identifiers such as get2, req6, for2, and con significantly hinder understanding. Code length: Much of the length reflects necessary configuration, but the large password-change method and lengthy comments increase reading effort. Action granularity: Statements generally perform one action per line, with readable formatting for compound expressions and dictionaries. Reading flow: Imports, configuration, and handlers follow a coherent sequence, and early returns help navigation; however, inconsistent naming forces readers to repeatedly infer what variables and methods represent.