Sample

pyint-5d6c283bc452-I12

Inline all eligible single-use intermediate local 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 Pro17.670–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 uses a clear class-based design with a single responsibility, logical attribute ordering, and conventional Django patterns. Nesting is minimal, and the __init__ method uses flat conditional assignments that clearly map arguments to attributes. Intent is explicit, with descriptive names like 'inverse_match' and 'invalid_input'. The code is concise, avoiding unnecessary verbosity. Action granularity is appropriate—expressions like 'invalid_input = regex_matches if ... else not regex_matches' are clear and not overloaded. The __eq__ method is readable despite its vertical formatting, though it could be slightly more compact. Reading flow is natural: initialization, validation logic, then equality comparison. Minor deductions for the slightly repetitive __init__ conditional block and the multi-line boolean expression in __eq__, but overall this is highly readable, idiomatic Python code.

Run 3

The code is well-structured and highly readable. It follows a logical class-based organization with clear separation of concerns: attribute defaults, initialization with optional overrides, validation logic, and equality comparison. Nesting is flat, with minimal conditional depth. Intent is clear from method and attribute names like 'inverse_match', 'regex_matches', and 'invalid_input'. The code is concise without being cryptic, and each action is generally on its own line. Reading flow proceeds naturally from imports through class definition, initialization, validation, and comparison. Docstrings and comments clarify complex logic where necessary. Minor deductions: the equality method could benefit from a brief comment, and the class-level attributes could be separated from the methods with blank lines for slightly better visual grouping. Overall, this is exemplary Python code.

Run 1

Code Structure: The class is logically organized into defaults, initialization, validation, and equality comparison, though several imports are unused in this snippet. Nesting: Control flow is shallow, with straightforward conditionals. Clarity of intent: Descriptive names, a useful validation docstring, and a clear error message make the purpose evident; the inverse-match expression requires slight extra attention. Code length: Concise overall, although initialization repeats similar conditional assignments. Action granularity: Each statement performs a single clear action, and longer expressions are sensibly split across lines. Reading flow: Methods follow a natural order, with consistent formatting and spacing; additional separation between imports and the class would improve presentation.

Run 2

Code Structure: The validator is logically organized into defaults, initialization, validation, and equality methods, though several unused imports add clutter. Nesting: Shallow conditionals keep control flow easy to follow. Clarity of intent: Descriptive names and the validation docstring clearly communicate purpose; inverse-match logic requires slight extra attention. Code length: Concise overall, with repetitive initialization checks that are straightforward rather than unnecessarily verbose. Action granularity: Each statement performs a distinct action, and multiline expressions are formatted clearly. Reading flow: Methods follow a natural sequence, with consistent indentation and readable line breaks. Minor distractions include redundant parentheses in equality checks and limited spacing between imports and the class.

Run 3

Code Structure: The class cleanly separates defaults, initialization, validation, and equality comparison, though several imports are unused in this snippet. Nesting: Shallow conditionals and no loops keep complexity low. Clarity of intent: Descriptive names, a helpful validation docstring, and an explicit error message make the purpose clear; inverse-match logic requires slight extra attention. Code length: Compact overall, with some repetitive but straightforward initialization checks. Action granularity: Each statement performs one clear action, and multiline expressions are appropriately formatted. Reading flow: Methods follow a natural progression, and consistent formatting makes the code easy to scan. Minor spacing improvements around imports and the class would enhance readability.