Sample

pyint-60965bca0178-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines60

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8690–1; higher is more readable
Mi0.3750–1; higher is more readable
LLOC40Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.4630–1; higher is more readable

Views

Source code

import ipaddress import math import re from pathlib import Path from urllib.parse import urlsplit from django.core.exceptions import ValidationError from django.utils.deconstruct import deconstructible from django.utils.http import MAX_URL_LENGTH from django.utils.ipv6 import is_valid_ipv6_address from django.utils.regex_helper import _lazy_re_compile from django.utils.translation import gettext_lazy as _ from django.utils.translation import ngettext_lazy @deconstructible class RegexValidator: regex = "" message = _("Enter a valid value.") code = "invalid" inverse_match = False flags = 0 def __init__( self, regex=None, message=None, code=None, inverse_match=None, flags=None ): if regex is not None: self.regex = regex if message is not None: self.message = message if code is not None: self.code = code if inverse_match is not None: self.inverse_match = inverse_match if flags is not None: self.flags = flags if self.flags and not isinstance(self.regex, str): raise TypeError( "If the flags are set, regex must be a regular expression string." ) self.regex = _lazy_re_compile(self.regex, self.flags) def __call__(self, value): """ Validate that the input contains (or does *not* contain, if inverse_match is True) a match for the regular expression. """ regex_matches = self.regex.search(str(value)) invalid_input = regex_matches if self.inverse_match else not regex_matches if invalid_input: raise ValidationError(self.message, code=self.code, params={"value": value}) def __eq__(self, other): return ( isinstance(other, RegexValidator) and self.regex.pattern == other.regex.pattern and self.regex.flags == other.regex.flags and (self.message == other.message) and (self.code == other.code) and (self.inverse_match == other.inverse_match) )

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.2118.047−69.896
Source linesThe number of non-empty source lines.60+24
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.381−6.571

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.57+1.234
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.61−1.123
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.88+0.615
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.59.854+0.427
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.063+0.332
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.88−0.062

Intercept 0.07 + feature contributions = 1.891 (log-odds).
Score = sigmoid(1.891) = 0.869.

Score0.375
Score40
Run 1

The code is generally well-structured with clear intent, flat nesting, and good action granularity. Each validation step is separated logically. However, minor issues prevent a higher score: variable names like 'invalid_input' are slightly ambiguous, and the __init__ method uses repetitive conditional assignments that could be simplified. The docstring helps clarify purpose, and line length is reasonable. Overall, it maintains good readability patterns with only minor opportunities for improvement.

Run 2

The code is well-structured and readable. It follows a clear class-based approach with logical organization of attributes and methods. The RegexValidator class has clear intent - validating input against regex patterns with customizable options. Nesting is minimal with only one if-block in __call__. Action granularity is appropriate, with one main action per line. The reading flow is natural, progressing from initialization to validation. The __init__ method is slightly verbose with repetitive None checks, but clear. Type checking in __eq__ is well-implemented. The docstring effectively explains the inverse_match behavior. However, the code could be more concise in __init__ using conditional assignments, and the __eq__ method's multi-line boolean comparison, while readable, could benefit from helper methods for complex conditions.

Run 3

The code is well-structured, with clear class and method organization. Nesting is minimal, with only one conditional inside __call__. Intent is clear—this is a Django-style regex validator with explicit parameters and docstring. Code length is appropriate for its functionality. Action granularity is mostly one action per line, though some lines in __eq__ and __call__ could be split for even greater clarity. Reading flow is natural, from class definition to initialization, then validation logic, then equality comparison. Imports are all used and logically grouped. The use of lazy regex compilation and type checking is clear and purposeful. Overall, highly readable and maintainable.

Run 1

Code Structure: The class is logically organized into defaults, initialization, validation, and equality comparison. Nesting: Shallow conditionals and no nested loops make control flow easy to follow. Clarity of intent: Descriptive names, a validation docstring, and a clear error message communicate purpose; the inverse-match expression requires slight extra attention. Code length: The implementation is concise, though repetitive initialization checks and unused imports add minor clutter. Action granularity: Statements generally perform one action per line, with multiline formatting used appropriately for longer expressions. Reading flow: Methods follow a natural progression, and consistent formatting supports scanning. Minor drawbacks include limited import grouping and redundant parentheses in equality comparisons.

Run 2

Code Structure: The validator is logically organized into defaults, initialization, validation, and equality comparison, although several imports are unused in this snippet. Nesting: Control flow is shallow, with straightforward conditionals and no deeply nested blocks. Clarity of intent: Descriptive names and the validation docstring make the purpose clear; the inverse-match expression requires slight extra attention. Code length: The implementation is concise overall, though initialization repeats similar assignments and equality checks include unnecessary parentheses. Action granularity: Statements generally perform one action each, and multiline expressions improve scanning. Reading flow: Methods follow a natural lifecycle, formatting is consistent, and validation proceeds predictably. Minor import clutter and the lack of a blank line separating imports from the decorated class slightly reduce readability.

Run 3

Code Structure: The class is logically organized into defaults, initialization, validation, and equality comparison, though several imports are unused in this snippet. Nesting: Shallow conditionals keep control flow easy to follow. Clarity of intent: Descriptive names and the validation docstring clearly explain behavior; the inverse-match expression requires slight extra attention. Code length: Concise overall, with some repetitive but straightforward initialization checks. Action granularity: Each statement performs a distinct action, and multiline expressions are formatted cleanly. Reading flow: Methods follow a natural sequence, with consistent indentation and spacing. Minor distractions include redundant parentheses in equality comparisons and unused imports.