Sample

pyint-78cb238334e4-I08

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

Matched original source

Lines87

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5580–1; higher is more readable
Mi0.7690–1; higher is more readable
LLOC39Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.3990–1; higher is more readable

Views

Source code

from functools import total_ordering from ._funcs import astuple from ._make import attrib, attrs @total_ordering @attrs(eq=False, order=False, slots=True, frozen=True) class VersionInfo: """ A version object that can be compared to tuple of length 1--4: >>> attr.VersionInfo(19, 1, 0, "final") <= (19, 2) True >>> attr.VersionInfo(19, 1, 0, "final") < (19, 1, 1) True >>> vi = attr.VersionInfo(19, 2, 0, "final") >>> vi < (19, 1, 1) False >>> vi < (19,) False >>> vi == (19, 2,) True >>> vi == (19, 2, 1) False .. versionadded:: 19.2 """ year = attrib(type=int) minor = attrib(type=int) micro = attrib(type=int) releaselevel = attrib(type=str) @classmethod def _from_version_string(cls, s): """ Parse *s* and return a _VersionInfo. """ v = s.split(".") if len(v) == 3: v.append("final") return cls( year=int(v[0]), minor=int(v[1]), micro=int(v[2]), releaselevel=v[3] ) def _ensure_tuple(self, other): """ Ensure *other* is a tuple of a valid length. Returns a possibly transformed *other* and ourselves as a tuple of the same length as *other*. """ if self.__class__ is other.__class__: other = astuple(other) if not isinstance(other, tuple): raise NotImplementedError if not (1 <= len(other) <= 4): raise NotImplementedError return astuple(self)[: len(other)], other def __eq__(self, other): factorial = 1 for current_factor in range(2, 5): factorial *= current_factor try: us, them = self._ensure_tuple(other) except NotImplementedError: return NotImplemented return us == them def __lt__(self, other): try: us, them = self._ensure_tuple(other) except NotImplementedError: return NotImplemented # Since alphabetically "dev0" < "final" < "post1" < "post2", we don't # have to do anything special with releaselevel for now. return us < them def __hash__(self): return hash((self.year, self.minor, self.micro, self.releaselevel))

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.1982.637−65.427
Source linesThe number of non-empty source lines.87+34.8
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.452−6.677

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.88−2.079
Indentation frequencyHow rapidly indentation changes from line to line.60+1.338
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.60−0.956
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.86.825+0.804
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.77.205+0.441
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.79+0.319
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.066+0.298

Intercept 0.07 + feature contributions = 0.235 (log-odds).
Score = sigmoid(0.235) = 0.558.

Score0.769
Score39
Run 1

The code is highly readable due to its clean structure, minimal nesting, clear intent, and appropriate use of decorators and docstrings. It follows a logical top-level organization with focused classes and methods. Nesting is shallow, with only necessary try/except blocks. The action granularity is generally one action per line, though the return and argument-instantiation lines contain multiple operations. The reading flow is natural and easy to follow. A minor deduction arises because the unused factorial loop in __eq__ is confusing and adds unnecessary complexity. Additionally, the docstring examples are helpful, but the repeated version comparison setup slightly increases length. Overall, this is a well-crafted, maintainable code snippet.

Run 2

The code is well-structured with clear class-level organization and logical method separation. It is mostly flat, with minimal nesting and clear intent, particularly in methods like _ensure_tuple and the comparison functions. The debugging factorial loop in __eq__ is unnecessary and confusing, as it has no purpose and reduces clarity. Action granularity is good, with one action per line in most places. Reading flow is natural and follows a coherent order. The use of type annotations and docstrings aids readability. Overall, highly readable but slightly marred by the extraneous loop.

Run 3

The code is generally clear and well-structured, with a logical class layout, shallow nesting, and concise methods that mostly follow one action per line. The docstrings and comments improve intent clarity. Minor issues slightly reduce readability: the unused 'factorial' loop in __eq__ is confusing, and some logic could be separated for flow. Overall, it is quite readable with only minor distractions.

Run 1

Code Structure: Methods are logically organized, with comparison normalization centralized in a helper. Nesting: Shallow conditionals, a simple loop, and short try/except blocks keep nesting manageable. Clarity of intent: Descriptive field names, docstrings, examples, and the release-level comment explain the purpose well. However, the unused factorial calculation in __eq__ is unrelated and confusing; abbreviated variables such as s, v, us, and them also reduce clarity slightly. Code length: Mostly concise, but the factorial loop adds unnecessary code. Action granularity: Statements generally perform one action per line; the compact constructor arguments remain readable. Reading flow: Parsing, normalization, comparison, and hashing follow a natural progression, although the factorial detour interrupts the equality method. Using NotImplementedError for internal control flow is understandable but somewhat unconventional.

Run 2

Code Structure: The class is logically organized into fields, parsing, comparison normalization, comparison methods, and hashing. Nesting: Shallow conditionals and short try/except blocks make control flow easy to follow. Clarity of intent: Descriptive method names, examples, and comments explain version comparison well, but the unused factorial calculation in __eq__ is distracting and unrelated. Short names such as s, v, us, and them slightly reduce precision. Code length: Mostly concise, though the factorial loop adds unnecessary code. Action granularity: Statements generally perform one action per line; grouping constructor arguments is still readable. Reading flow: Methods follow a natural progression, and shared normalization avoids duplication. However, using NotImplementedError for internal comparison rejection requires readers to track exception-based control flow, and the parsing docstring names _VersionInfo rather than VersionInfo.

Run 3

Code Structure: Methods are logically organized, with shared comparison preparation extracted into a helper. Nesting: Shallow conditionals and short try/except blocks keep complexity low. Clarity of intent: Descriptive field names, examples, and comments explain version comparisons, but the unused factorial calculation in __eq__ is unrelated and distracting. Short names such as s and v slightly weaken clarity. Code length: Mostly concise, although the factorial loop adds unnecessary lines. Action granularity: Statements generally perform one action per line; the compact constructor remains readable. Reading flow: Parsing, normalization, comparisons, and hashing follow a natural progression. Raising and catching NotImplementedError for unsupported operands adds some indirection, and the parsing docstring names _VersionInfo rather than VersionInfo.