Sample

pyint-e069b99e2e1c-I05

Rewrite eligible decimal integer literals in hexadecimal notation

Matched original source

Lines60

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.6470–1; higher is more readable
Mi0.3750–1; higher is more readable
LLOC40Logical lines; fewer is more readable
DeepSeek V4 Pro16.330–20; mean of three runs
GPT-6.1 Sol180–20; mean of three runs
BTTF0.4080–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 = 0x0 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.384−6.577

Intercept 8.87 + feature contributions = -43.602 (log-odds).
Score = sigmoid(-43.602) = 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
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.57−0.887
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.865+0.427
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.063+0.333
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 = 0.607 (log-odds).
Score = sigmoid(0.607) = 0.647.

Score0.375
Score40
Run 1

The code is well-structured, with clear class-level defaults and a concise __init__ that only overrides provided parameters. Nesting is minimal, and intent is generally clear. It is concise and each line performs a focused action. The __call__ method uses a clean boolean logic approach, though the naming 'invalid_input' could be more explicit. __eq__ is readable but slightly verbose. Overall, it follows idiomatic Django patterns and maintains good readability.

Run 2

The code is well-structured and highly readable. It uses clear class and method definitions, consistent formatting, and logical organization. The __init__ method handles optional parameters with a flat series of independent if-statements, making it easy to follow. The validation logic in __call__ is concise and explicit, with a clear inline comment describing inverse_match behavior. The __eq__ method is readable but slightly long due to multiple conditions, though it remains clear. Nesting is minimal, and most lines contain only one action, aiding comprehension. The only minor issues are the somewhat dense import block and the multi-line boolean expression in __eq__, which slightly reduce flow. Overall, the code displays strong clarity of intent and maintainable structure.

Run 3

The code is generally well-structured with clear class organization and follows Django conventions. The __init__ method is verbose but readable due to its straightforward conditional pattern. Nesting is minimal. Action granularity is appropriate—each line performs a distinct action. The __call__ method clearly expresses validation logic in two lines. However, imports at the top are unused (ipaddress, math, re, Path, urlsplit, etc.), which harms clarity and adds unnecessary length. The __eq__ method chains multiple conditions across lines, which is acceptable but slightly dense. Overall, the code is readable and maintainable, but the redundant imports reduce its score.

Run 1

1. Code Structure: Clearly organized into class defaults, initialization, validation, and equality methods; unused imports add minor clutter. 2. Nesting: Mostly flat, with simple conditionals and no deeply nested logic. 3. Clarity of intent: Descriptive names and the validation docstring make the purpose clear, though inverse-match logic requires a little attention. 4. Code length: Concise overall; repeated optional-argument assignments are verbose but straightforward. 5. Action granularity: Statements generally perform one action each, and multiline expressions are formatted cleanly. 6. Reading flow: Natural progression and consistent formatting make the class easy to follow; framework-specific helpers introduce a small contextual burden.

Run 2

Code Structure: The class is logically organized into configuration defaults, initialization, validation, and equality comparison. Nesting: Control flow is shallow, with straightforward conditionals and no deeply nested blocks. Clarity of intent: Descriptive names and the validation docstring clearly communicate purpose, although the inverse-match expression requires brief interpretation. Code length: The implementation is reasonably concise; repeated optional-argument assignments are explicit but slightly verbose, and several imports are unused in this snippet. Action granularity: Each statement performs one clear action, with multiline expressions improving legibility. Reading flow: Consistent formatting and method ordering support natural top-to-bottom reading. Minor distractions include redundant parentheses in equality checks and the lack of a blank line separating imports from the class decorator.

Run 3

Code Structure: The class is logically organized into configuration defaults, initialization, validation, and equality comparison. Nesting: Control flow is shallow, with straightforward conditionals and no nested loops. Clarity of intent: Descriptive names and the validation docstring make the purpose clear, although the inverse-match expression requires a little interpretation. Code length: The implementation is concise overall; repeated initialization checks are reasonable, but several unused imports add clutter. Action granularity: Each statement performs a single clear action, and multiline expressions improve readability. Reading flow: Methods follow a natural sequence, with consistent formatting and useful whitespace. Minor distractions include redundant parentheses in equality checks and the less intuitive hexadecimal zero for flags.