Sample

pyint-3319b9ee86c0-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines127

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4940–1; higher is more readable
Mi0.6510–1; higher is more readable
LLOC58Logical lines; fewer is more readable
DeepSeek V4 Pro60–20; mean of three runs
GPT-6.1 Sol120–20; mean of three runs
BTTF0.3470–1; higher is more readable

Views

Source code

from datetime import datetime from django.conf import settings from django.utils.crypto import constant_time_compare, salted_hmac from django.utils.http import base36_to_int, int_to_base36 class PasswordResetTokenGenerator: """ Strategy object used to generate and check tokens for the password reset mechanism. """ key_salt = "django.contrib.auth.tokens.PasswordResetTokenGenerator" algorithm = None _secret = None _secret_fallbacks = None def __init__(self): self.algorithm = self.algorithm or "sha256" def get(self): return self._secret or settings.SECRET_KEY def set(self, sec): self._secret = sec secret = property(_get_secret, _set_secret) def get2(self): if self._secret_fallbacks is None: return settings.SECRET_KEY_FALLBACKS return self._secret_fallbacks def set2(self, fal): self._secret_fallbacks = fal secret_fallbacks = property(_get_fallbacks, _set_fallbacks) def make(self, use): """ Return a token that can be used once to do a password reset for the given user. """ return self.make2( use, self.num(self.now2()), self.secret, ) def check(self, use2, tok): """ Check that a password reset token is correct for a given user. """ if not (use2 and tok): return False # Parse the token try: ts2, _2 = tok.split("-") except ValueError: return False try: ts3 = base36_to_int(ts2) except ValueError: return False # Check that the timestamp/uid has not been tampered with for sec2 in [self.secret, *self.secret_fallbacks]: if constant_time_compare( self.make2(use2, ts3, sec2), tok, ): break else: return False # Check the timestamp is within limit. if (self.num(self.now2()) - ts3) > settings.PASSWORD_RESET_TIMEOUT: return False return True def make2(self, use3, tim, sec3): # timestamp is number of seconds since 2001-1-1. Converted to base 36, # this gives us a 6 digit string until about 2069. ts4 = int_to_base36(tim) hash = salted_hmac( self.key_salt, self.make3(use3, tim), secret=sec3, algorithm=self.algorithm, ).hexdigest()[ ::2 ] # Limit to shorten the URL. return "%s-%s" % (ts4, hash) def make3(self, use4, tim2): """ Hash the user's primary key, email (if available), and some user state that's sure to change after a password reset to produce a token that is invalidated when it's used: 1. The password field will change upon a password reset (even if the same password is chosen, due to password salting). 2. The last_login field will usually be updated very shortly after a password reset. Failing those things, settings.PASSWORD_RESET_TIMEOUT eventually invalidates the token. Running this data through salted_hmac() prevents password cracking attempts using the reset token, provided the secret isn't compromised. """ # Truncate microseconds so that tokens are consistent even if the # database doesn't support microseconds. login = ( "" if use4.last_login is None else use4.last_login.replace(microsecond=0, tzinfo=None) ) email2 = use4.get_email_field_name() ema = getattr(use4, email2, "") or "" return f"{use4.pk}{use4.password}{login}{tim2}{ema}" def num(self, dt2): return int((dt2 - datetime(2001, 1, 1)).total_seconds()) def now2(self): # Used for mocking in tests return datetime.now()

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.3032.552−100.074
Source linesThe number of non-empty source lines.127+50.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.398−6.597

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.128−3.496
Indentation frequencyHow rapidly indentation changes from line to line.97+2.618
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.97−1.805
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.126.875+1.364
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.78.227+0.458
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.051+0.448
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.78.969+0.32

Intercept 0.07 + feature contributions = -0.023 (log-odds).
Score = sigmoid(-0.023) = 0.494.

Score0.651
Score58
Run 1

The code is difficult to read due to poor naming conventions (e.g., 'use', 'make2', 'make3'), inconsistent method structure, and a mix of clear comments with unclear or missing ones. The token generation logic is spread across multiple methods with vague names, making it hard to follow the flow. Nesting is moderate but not deeply complex. The class lacks clear separation of concerns, and property definitions are awkwardly placed. Code length is reasonable but not concise due to redundant method names and unclear abstractions. Overall, the code is functional but not highly readable.

Run 2

The code is highly unreadable due to poorly named methods and variables (e.g., 'make', 'make2', 'make3', 'use3', 'tim2', 'sec3', 'get2', 'set2', 'num', 'now2'). These ambiguous names obscure the logic and intent, making the flow difficult to follow. The structure is tangled; for instance, the property definitions reference functions (`_get_secret`, `_get_fallbacks`) that are not defined in the provided code, creating confusion. There is unnecessary complexity and nesting in the `check` method, including a for-else construct that is hard to parse. The action granularity is inconsistent, with some lines containing multiple operations. Overall, the code requires significant mental effort to understand due to its cryptic naming and tangled organization.

Run 3

The code appears to be a modified version of Django's PasswordResetTokenGenerator with intentionally obscured naming. Methods like make, make2, make3, check, num, now2, get, set, get2, set2, use, use2, use3, use4, tim, tim2, ts2, ts3, ts4 are ambiguous and hinder clarity of intent. The class structure is logical, but the obfuscated names disrupt reading flow. Nesting is moderate, with some try/except blocks and loops. Action granularity is acceptable, with one action per line mostly. Code length is reasonable. Overall readability is significantly reduced due to unclear naming conventions.

Run 1

Code Structure: Responsibilities are separated into small methods, but property declarations reference undefined accessor names, breaking coherence. Nesting: Guard clauses keep validation mostly flat; the loop and conditional nesting are modest. Clarity of intent: Docstrings and comments explain token generation well, but names such as make2, make3, use4, and ts3 obscure distinct roles. Code length: Implementation is reasonably concise, with useful documentation rather than substantial repetition. Action granularity: Most statements perform one action per line, although chained hashing and slicing require extra interpretation. Reading flow: Generation, validation, and supporting helpers follow a logical order, but inconsistent naming and awkward multiline slicing interrupt comprehension. Overall, the organization and documentation help, while ambiguous identifiers and mismatched property accessors significantly reduce readability.

Run 2

Code Structure: Logically divided into token generation, validation, hashing, and time helpers, but property declarations reference undefined accessor names, undermining coherence. Nesting: Mostly shallow, with early returns keeping validation manageable; the loop-else requires extra attention. Clarity of intent: Docstrings and comments explain the password-reset mechanism well, but generic names such as make2, get2, use3, and ts3 obscure individual responsibilities and data roles. Code length: Reasonably concise for its functionality; extensive documentation is useful rather than redundant. Action granularity: Generally one action per statement, although chained hashing and awkward multiline slicing make one expression harder to parse. Reading flow: The overall sequence is natural, but inconsistent naming, broken accessor references, and unusual formatting interrupt comprehension.

Run 3

Code Structure: Well-separated methods organize token generation, validation, hashing, and time handling, but properties reference undefined accessor names rather than the declared methods, undermining coherence. Nesting: Shallow nesting and early returns keep validation readable; the loop-else requires some attention. Clarity of intent: Docstrings and comments explain the mechanism, but generic names such as make2, get2, use4, and ts3 obscure roles and relationships. Code length: Mostly concise, with useful explanatory documentation, though awkward multiline slicing adds visual noise. Action granularity: Statements generally perform one action each; chained hashing and slicing remain manageable. Reading flow: The overall sequence is logical, but inconsistent naming, broken accessor references, and formatting interruptions force readers to repeatedly infer meaning.