Sample

pyint-5ac04f18e448-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines60

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8710–1; higher is more readable
Mi0.4420–1; higher is more readable
LLOC40Logical lines; fewer is more readable
DeepSeek V4 Pro150–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.4390–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, reg=None, mes=None, cod=None, inverse=None, fla=None ): if reg is not None: self.regex = reg if mes is not None: self.message = mes if cod is not None: self.code = cod if inverse is not None: self.inverse_match = inverse if fla is not None: self.flags = fla 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, val): """ Validate that the input contains (or does *not* contain, if inverse_match is True) a match for the regular expression. """ regex2 = self.regex.search(str(val)) invalid = regex2 if self.inverse_match else not regex2 if invalid: raise ValidationError(self.message, code=self.code, params={"value": val}) def __eq__(self, oth): return ( isinstance(oth, RegexValidator) and self.regex.pattern == oth.regex.pattern and self.regex.flags == oth.regex.flags and (self.message == oth.message) and (self.code == oth.code) and (self.inverse_match == oth.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.2149.209−70.924
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.366−6.549

Intercept 8.87 + feature contributions = -44.603 (log-odds).
Score = sigmoid(-44.603) = 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.86+0.583
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.59.885+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.066+0.301
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.86+0.023

Intercept 0.07 + feature contributions = 1.913 (log-odds).
Score = sigmoid(1.913) = 0.871.

Score0.442
Score40
Run 1

The code is generally well-structured and readable, with clear class organization and logical method separation. The __init__ method follows a consistent pattern for optional parameters, and __call__ has a clear validation flow with minimal nesting. However, readability is slightly reduced by abbreviated parameter names (reg, mes, cod, inverse, fla, oth) that obscure intent, though they are conventional in Django's codebase. The validation logic is concise with one primary action per line, and the __eq__ method is straightforward despite its multi-line boolean expression. Overall, the code demonstrates good structure, flat nesting, and clear control flow, making it maintainable and understandable.

Run 2

The code is generally readable with clear class structure and good use of standard Django patterns. However, the __init__ method uses overly abbreviated parameter names (reg, mes, cod, inverse, fla) that significantly reduce clarity. The method is unnecessarily long with repetitive conditional checks for each parameter. The __call__ method is concise and clear, with good variable naming. The __eq__ method has a logical structure but could be simplified. Import statements are well-organized. Overall, the code could be improved with better parameter naming and a more concise initialization approach, but the structure and logic flow are adequate.

Run 3

The code is generally readable with clear class structure and reasonable method organization. It uses descriptive variable names (registry, message, code) but abbreviations like 'reg', 'mes', 'cod', 'inverse', 'fla', 'val', and 'oth' reduce clarity. The __init__ method has flat, linear parameter checking which is good for readability. The __call__ method is concise with clear intent, though the regex2/invalid logic could be clearer. The __eq__ method is well-structured but could benefit from better parameter naming. Overall nesting is minimal, action granularity is appropriate, and the reading flow is natural. Main improvements would be full parameter names and slightly clearer variable naming in the __call__ method.

Run 1

Code Structure: The class is logically organized into defaults, initialization, validation, and equality checking, though numerous unused imports add clutter. Nesting: Shallow conditionals and early exceptions keep the code easy to follow. Clarity of intent: Descriptive class attributes and the validation docstring explain the purpose, but abbreviated parameters such as reg, mes, cod, fla, and oth, plus the vague regex2 name, reduce clarity. Code length: The implementation is reasonably concise; repeated initialization checks are straightforward rather than unnecessarily verbose. Action granularity: Each statement generally performs one action, and the multiline equality expression is clearly separated. Reading flow: Methods follow a natural sequence and formatting is consistent, although the unnecessarily split short constructor signature and distracting imports slightly interrupt the flow.

Run 2

Code Structure: The class is logically organized into configuration, initialization, validation, and equality checks, although unused imports add clutter. Nesting: Shallow conditionals keep control flow easy to follow. Clarity of intent: Descriptive class attributes and the validation docstring explain the purpose, but abbreviated parameters such as reg, mes, cod, fla, and oth, plus the vague name regex2, reduce clarity. Code length: The implementation is reasonably concise, though unused imports and unnecessary parentheses slightly inflate it. Action granularity: Statements generally perform one action per line, and multiline expressions are clearly separated. Reading flow: Methods follow a natural sequence and formatting is consistent overall, but the awkwardly split constructor signature and abbreviated identifiers interrupt otherwise smooth reading.

Run 3

Code Structure: The class logically separates initialization, validation, and equality checks, though several unused imports add clutter. Nesting: Shallow conditionals keep the code easy to follow. Clarity of intent: Descriptive class attributes and the validation docstring clarify purpose, but abbreviated parameters such as reg, mes, cod, fla, and oth, plus the vague regex2 variable, reduce clarity. Code length: The implementation is reasonably concise, although unused imports and unnecessary parentheses in equality comparisons add noise. Action granularity: Each statement performs a single clear action, with a readable multiline equality expression. Reading flow: Methods follow a natural progression and use consistent indentation, but the awkwardly wrapped constructor signature and lack of import grouping slightly disrupt scanning.