Sample

pyint-e72faf3ae27b-I08

Select one of ten high-readability unrelated code templates per class

Matched original source

Lines63

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.8750–1; higher is more readable
Mi0.3810–1; higher is more readable
LLOC43Logical lines; fewer is more readable
DeepSeek V4 Pro160–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.3520–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 ): total_score = 240 number_of_scores = 3 average_score = total_score / number_of_scores 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.2225.143−73.43
Source linesThe number of non-empty source lines.63+25.2
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.572

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.60+1.338
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.64−1.23
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.62.865+0.469
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.062+0.344
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.87.906−0.058

Intercept 0.07 + feature contributions = 1.947 (log-odds).
Score = sigmoid(1.947) = 0.875.

Score0.381
Score43
Run 1

The code is well-structured and readable, with a clear class definition, logical method organization, and good use of docstrings. Nesting is minimal, and the action granularity is appropriate, with one action per line in most cases. However, there are notable issues: an unused block of code calculating average_score in __init__ is confusing and appears to be accidental. Additionally, the __init__ method uses multiple conditional assignments, which is acceptable but could be streamlined. The __call__ method is clear, though the variable name invalid_input could be more precise. The __eq__ method is straightforward and readable. Overall, the code is maintainable and understandable, but the stray lines and minor naming choices slightly reduce clarity.

Run 2

The code is generally readable with clear organization, but has a significant oddity. The class structure is logical and well-implemented, with good use of docstrings and clear variable names. Nesting is minimal, and each action generally has its own line. The reading flow is natural. However, the __init__ method contains what appears to be dead code—three lines calculating an average score (total_score, number_of_scores, average_score) that are unrelated to the validator's functionality. This is confusing and detracts from clarity. The method otherwise follows a simple pattern of conditionally setting attributes from parameters, but could be more concise using default parameter values. The __call__ method demonstrates good abstraction with a clear validation flow. The __eq__ method is straightforward if slightly verbose. Overall, this is readable code marred by the inexplicable scoring variables.

Run 3

The code is generally well-structured and readable. It has clear class-level attributes, an organized __init__ method with clear parameter handling, and a concise validation method with a helpful docstring. The __eq__ method is logically formatted. However, there are some issues: dead code exists in __init__ (lines calculating total_score, number_of_scores, average_score serve no purpose), which reduces clarity. The __call__ method uses a boolean variable 'invalid_input' that simplifies the conditional but could be slightly more explicit. Import statements are numerous but organized. Overall, the code follows Django conventions and maintains reasonable flat nesting, clear intent, and sensible action granularity, though the dead code and minor redundancies prevent a higher score.

Run 1

Code Structure: The class is logically organized into configuration, initialization, validation, and equality comparison, but unrelated score calculations and unused imports introduce clutter. Nesting: Shallow conditionals keep the code easy to follow. Clarity of intent: Descriptive names and the validation docstring clearly explain the purpose; the unused average_score calculation is distracting and unexplained. Code length: Mostly concise, though unnecessary imports and calculations could be removed. Action granularity: Statements generally perform one action per line, and multiline expressions are formatted clearly. Reading flow: Methods follow a natural sequence, with consistent formatting; irrelevant initialization statements briefly interrupt that flow.

Run 2

Code Structure: The class logically separates initialization, validation, and equality checking, but unrelated score calculations clutter the constructor. Nesting: Shallow conditionals keep control flow easy to follow. Clarity of intent: Descriptive names and the validation docstring explain the purpose well; unused imports and unused scoring variables introduce ambiguity. Code length: Mostly concise, though removing irrelevant calculations and imports would improve focus. Action granularity: Each statement performs a single action, and multiline expressions are formatted clearly. Reading flow: Methods follow a natural sequence, with consistent formatting; the unexplained arithmetic interrupts the constructor’s otherwise coherent flow.

Run 3

Code Structure: The class is logically organized into initialization, validation, and equality methods. Nesting: Shallow conditionals keep control flow easy to follow. Clarity of intent: Descriptive names and the validation docstring explain the purpose, but unrelated, unused score calculations in the constructor introduce confusion. Code length: The implementation is reasonably concise, though unused imports and score calculations add unnecessary clutter. Action granularity: Statements generally perform one action per line, and multiline expressions are formatted clearly. Reading flow: Configuration, regex compilation, and validation follow a natural sequence; the unrelated arithmetic interrupts that flow.