Sample
pyint-85add32b3b0e-I13
Lower every eligible synchronous for loop to a while loop
Scores
| Method | Score | Scale |
|---|---|---|
| Posnett | 0 | 0–1; higher is more readable |
| Dorn | 0.885 | 0–1; higher is more readable |
| Mi | 0.662 | 0–1; higher is more readable |
| LLOC | 20 | Logical lines; fewer is more readable |
| DeepSeek V4 Pro | 16.67 | 0–20; mean of three runs |
| GPT-6.1 Sol | 17.33 | 0–20; mean of three runs |
| BTTF | 0.67 | 0–1; higher is more readable |
Views
Loading feature diagnosis…
Source regions
Feature contributions
Feature contributions
| Feature | Value | Contribution (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. | 664.856 | −21.94 |
| Source linesThe number of non-empty source lines. | 27 | +10.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.504 | −6.755 |
Intercept 8.87 + feature contributions = -9.026 (log-odds).
Score = sigmoid(-9.026) = 0.
Feature contributions
| Feature | Value | Contribution (log-odds) |
|---|---|---|
| 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. | 73.929 | +0.534 |
| Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *. | 0.051 | +0.446 |
| Number layout frequencyHow rapidly the number of numeric values per line changes through the code. | 1 | +0.398 |
| Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right. | 74 | +0.39 |
| Indentation frequencyHow rapidly indentation changes from line to line. | 26 | +0.162 |
| Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code. | 27 | +0.08 |
| Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom. | 26.773 | −0.036 |
Intercept 0.07 + feature contributions = 2.045 (log-odds).
Score = sigmoid(2.045) = 0.885.
| Score | 0.662 |
|---|
| Score | 20 |
|---|
Run 1
The code is well-structured with clear imports and a single, focused class definition. It uses the attrs library effectively to reduce boilerplate. The _OrValidator class has a logical organization with distinct methods for call logic and representation. Nesting is minimal with only one loop and try/except block inside the __call__ method. Intent is clear: validate if any validator in a list passes. Code length is concise and appropriately sized for the functionality. Action granularity is generally good, though the try/except/else block could be slightly clearer. Reading flow is natural with a clear progression from class definition to method implementations. The main readability concerns are the single-letter variable 'v' and the dense try/except/else block in __call__, which could benefit from a helper method or more explicit control flow. Overall, this is readable code that follows common Python patterns.
Run 2
The code is well-structured with clear class and method definitions. The use of the attrs decorator reduces boilerplate and clarifies intent. Nesting is minimal, limited to a single for-loop with try/except/else, which is acceptable. However, readability is slightly hindered by the broad exception handling with multiple noqa comments, which may obscure intent, and by the generic variable name 'v' for validators. The f-strings and repr methods are concise, but the exception handling flow, with its continue/else/return pattern, could be clearer with a comment or refactoring. Overall, the code is readable but not outstanding.
Run 3
The code is a well-structured, readable Python class definition. It has a clear purpose: implementing an 'or' validator that passes if any sub-validator succeeds, otherwise raising a ValueError. The class is concise with a single-level loop and try/except/else blocks, maintaining flat nesting. Each action (loop, try, continue, return, raise) is clearly separated with good line granularity. Imports are grouped logically. Naming is descriptive (_OrValidator, validators, inst, attr, value) and the error message is informative. The only minor issues are the terse variable names 'inst' and 'v' and the slightly dense contextmanager/Pattern imports (likely used elsewhere), but these are conventional in attrs validators and don't significantly harm readability.
Run 1
Code Structure: The class cleanly separates validation behavior from representation, though several unused imports add clutter. Nesting: The loop and try/except/else introduce moderate nesting but remain easy to follow. Clarity of intent: The class name, validators attribute, and error message clearly communicate that any validator may succeed; the abbreviated name v and broad exception handling slightly obscure details. Code length: The implementation is concise, with no unnecessary logic, although the import list is excessive for this snippet. Action granularity: Each line generally performs one action, and error-message construction is separated from raising the exception. Reading flow: Validation proceeds naturally from trying each validator to returning on success or raising after all fail. The suppression comment is visually noisy, and a blank line before the decorated class would improve formatting.
Run 2
Code Structure: The validator is logically organized into state, validation behavior, and representation. Nesting: The loop and try/except introduce moderate but manageable nesting. Clarity of intent: The class name, error message, and early return clearly express OR-style validation; however, the short name 'v' and broad exception handling obscure some detail. Code length: The implementation is concise, though several imports are unused in the provided snippet. Action granularity: Each line performs a single clear action. Reading flow: Validation attempts, continuation on failure, return on success, and final failure follow a natural sequence. Framework decorators and lint-suppression annotations add minor reading overhead.
Run 3
Code Structure: The class cleanly groups validator storage, invocation, and representation, although several imports are unused in this snippet. Nesting: The loop and try/except/else introduce moderate nesting, but continue and return keep control flow manageable. Clarity of intent: The class name, error message, and representation clearly communicate OR validation; the short names v, inst, and attr are less descriptive, and catching every Exception can obscure which failures are expected. Code length: The implementation is concise with little redundancy, aside from unused imports. Action granularity: Each line generally performs one action. Reading flow: Execution naturally progresses from trying validators to returning on success or raising after all fail; the suppression comment adds minor visual noise.