Sample

pyint-2f0a9afa8879-I10

Deterministically remove some optional blank lines and bracketed line breaks

Matched original source

Lines22

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5740–1; higher is more readable
Mi0.3140–1; higher is more readable
LLOC17Logical lines; fewer is more readable
DeepSeek V4 Pro13.670–20; mean of three runs
GPT-6.1 Sol14.670–20; mean of three runs
BTTF0.7390–1; higher is more readable

Views

Source code

from collections.abc import Iterable from django.apps import apps from django.contrib import auth from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager from django.contrib.auth.hashers import make_password from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied from django.core.mail import send_mail from django.db import models from django.db.models.manager import EmptyManager from django.utils import timezone from django.utils.translation import gettext_lazy as _ from .validators import UnicodeUsernameValidator class PermissionManager(models.Manager): use_in_migrations = True def get_by_natural_key(self, codename, app_label, model): return self.get( codename=codename, content_type=ContentType.objects.db_manager(self.db).get_by_natural_key( app_label, model ), )

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.901.892−29.762
Source linesThe number of non-empty source lines.22+8.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.559−6.838

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.1+0.398
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.057+0.384
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.23+0.222
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.83.957+0.109
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.21.8−0.105
Indentation frequencyHow rapidly indentation changes from line to line.22+0.024

Intercept 0.07 + feature contributions = 0.297 (log-odds).
Score = sigmoid(0.297) = 0.574.

Score0.314
Score17
Run 1

The code is generally readable but has some structural inconsistencies. The imports are organized logically, and the class structure is clear. However, the get_by_natural_key method has awkward indentation and spacing - the parameters on line 2 are poorly aligned (codename=codename, content_type=ContentType.objects.db_manager(self.db).get_by_natural_key(app_label, model) are not formatted consistently). The method could benefit from better parameter formatting for improved readability. The nesting level is low, which is good. The intent is clear - it's a custom manager for retrieving permissions by natural key. The code length is concise, but the action of retrieving content_type is embedded within the get() call, making it slightly harder to follow. Overall, it's readable but could be improved with better formatting and perhaps breaking out the content_type retrieval into a separate variable for clarity.

Run 2

The code is generally readable, with clear imports, good use of Django conventions, and a straightforward class definition. The `PermissionManager` is concise and logically organized. However, the `get_by_natural_key` method has an awkward line break in the `self.get` call — the first argument (`codename`) starts on a new line with excessive indentation, and arguments cause inconsistent alignment. This disrupts natural reading flow. The method itself is flat, and each action is mostly on its own line, but the overly long `content_type` assignment (spanning three lines) makes scanning slightly harder. Overall, intent is clear for someone familiar with Django, but formatting issues prevent a perfect score.

Run 3

The code is largely readable, but the final method `get_by_natural_key` is formatted poorly. The indentation for `codename=codename` is misaligned, and the line break in `return self.get(` creates unnatural stretching. The `get_by_natural_key` call itself breaks the reading flow by placing the argument on the next line with excessive indentation. The rest of the imports and class structure are standard and clear. However, the method body violates multiple criteria: nesting is slightly deep due to the chained method call, action granularity is uneven, and reading flow is disrupted by unnecessary line breaks and misalignment. It could be simplified and reformatted for better clarity.

Run 1

Code Structure: The manager class and lookup method are logically organized, but numerous unrelated imports distract from the small implementation. Nesting: Shallow overall, with only a nested lookup call. Clarity of intent: Descriptive class, method, and parameter names make the permission lookup understandable. Code length: The method is concise, though the import section is disproportionately long for the shown code. Action granularity: Statements generally perform one action each; the nested call is cohesive rather than overloaded. Reading flow: Import-to-class-to-method ordering is natural, but missing blank lines around definitions and excessive spacing before codename disrupt scanning.

Run 2

Code Structure: Imports precede a small manager class in a logical order, though many imports are unused in this snippet. Nesting: Shallow overall, with a nested lookup inside the return expression that remains easy to follow. Clarity of intent: Descriptive class, method, and parameter names clearly convey retrieval of a permission by its natural key. Code length: The method is concise, but the extensive import list adds unnecessary visual overhead for the shown functionality. Action granularity: Statements are separate, although the content-type lookup is embedded within the permission query. Reading flow: Generally natural, but excessive spacing before codename and missing blank lines between imports, the class, and its method detract from readability.

Run 3

Code Structure: The manager class and lookup method are logically organized, but numerous unused imports obscure this small snippet. Nesting: Shallow nesting keeps the method easy to follow; the nested content-type lookup adds only modest complexity. Clarity of intent: Descriptive class, method, and parameter names clearly communicate a natural-key permission lookup, although Django familiarity helps. Code length: The implementation is concise, but the import block is disproportionately long for the functionality shown. Action granularity: The return expression combines two related lookups without excessive statement packing, though placing codename on the opening line reduces visual clarity. Reading flow: The lookup reads naturally overall, but irregular spacing after self.get( and missing blank lines between imports, the class, and its method interrupt the flow.