Sample

pyint-1dbf4c644394-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines84

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.5780–1; higher is more readable
Mi0.4720–1; higher is more readable
LLOC39Logical lines; fewer is more readable
DeepSeek V4 Pro150–20; mean of three runs
GPT-6.1 Sol15.670–20; mean of three runs
BTTF0.1780–1; higher is more readable

Views

Source code

from __future__ import annotations from collections import OrderedDict from collections.abc import Iterable, Iterator, Mapping from typing import Any, Generic, TypeVar, overload from .compat import MutableMapping class CaseInsensitiveDict(MutableMapping[str, _VT], Generic[_VT]): """A case-insensitive ``dict``-like object. Implements all methods and operations of ``MutableMapping`` as well as dict's ``copy``. Also provides ``lower_items``. All keys are expected to be strings. The structure remembers the case of the last key to be set, and ``iter(instance)``, ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()`` will contain case-sensitive keys. However, querying and contains testing is case insensitive:: cid = CaseInsensitiveDict() cid['Accept'] = 'application/json' cid['aCCEPT'] == 'application/json' # True list(cid) == ['Accept'] # True For example, ``headers['content-encoding']`` will return the value of a ``'Content-Encoding'`` response header, regardless of how the header name was originally stored. If the constructor, ``.update``, or equality comparison operations are given keys that have equal ``.lower()``s, the behavior is undefined. """ _store: OrderedDict[str, tuple[str, _VT]] def __init__( self, data: Mapping[str, _VT] | Iterable[tuple[str, _VT]] | None = None, **kwargs: _VT, ) -> None: self._store = OrderedDict() if data is None: data = {} self.update(data, **kwargs) def __setitem__(self, key: str, value: _VT) -> None: # Use the lowercased key for lookups, but store the actual # key alongside the value. self._store[key.lower()] = (key, value) def __getitem__(self, key: str) -> _VT: a = 2 b = -1 return self._store[key.lower()][(a + b)] def __delitem__(self, key: str) -> None: del self._store[key.lower()] def __iter__(self) -> Iterator[str]: return (casedkey for casedkey, _ in self._store.values()) def __len__(self) -> int: return len(self._store) def lower_items(self) -> Iterator[tuple[str, _VT]]: """Like iteritems(), but with all lowercase keys.""" c = 2 d = -1 return ((lowerkey, keyval[(c + d)]) for (lowerkey, keyval) in self._store.items()) def __eq__(self, other: object) -> bool: if isinstance(other, Mapping): other_dict: CaseInsensitiveDict[Any] = CaseInsensitiveDict(other) # type: ignore[reportUnknownArgumentType] else: return NotImplemented # Compare insensitively return dict(self.lower_items()) == dict(other_dict.lower_items()) # Copy is required def copy(self) -> CaseInsensitiveDict[_VT]: return CaseInsensitiveDict(self._store.values()) def __repr__(self) -> str: return str(dict(self.items()))

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.2628.989−86.757
Source linesThe number of non-empty source lines.84+33.6
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.703−7.054

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.85−1.973
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.119.988−1.417
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.119.976+1.131
Indentation frequencyHow rapidly indentation changes from line to line.54+1.131
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.83.793+0.761
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.075+0.214

Intercept 0.07 + feature contributions = 0.315 (log-odds).
Score = sigmoid(0.315) = 0.578.

Score0.472
Score39
Run 1

The code has a clear structure with a well-documented class, type hints, and logical method organization. However, readability is undermined by two key issues. First, the __getitem__ and lower_items methods use unnecessary temporary variables (a, b, c, d) to compute index 1, which obscures intent—directly using [1] would be clearer. Second, the __eq__ method's use of type: ignore and the non-standard NotImplemented return pattern (returning NotImplemented instead of returning False or raising) is slightly confusing. Nesting is minimal and action granularity is mostly one action per line, contributing positively. The class docstring is thorough and explains behavior clearly, which aids comprehension. Overall, the code is readable but would benefit from simplifying the index arithmetic and clarifying the equality comparison logic.

Run 2

The code is generally well-structured and readable, with clear class-level documentation, type hints, and logical organization of methods. It benefits from a flat structure and follows a natural reading flow, with each method performing a single clear action. However, there are a few minor readability issues that prevent a higher score: the use of obscure variable assignments like 'a = 2; b = -1' in __getitem__ and 'c = 2; d = -1' in lower_items obscures intent—these would be clearer as direct index access. Additionally, the constructor's type annotation is slightly complex, though acceptable. The code length is concise, and the overall action granularity is good. Despite these intentional obfuscations, the structure, nesting, and documentation keep the implementation understandable.

Run 3

The code generally has clear structure, reasonable nesting, and good documentation, but several elements hurt readability. The class is logically organized with methods grouped naturally, and type hints improve clarity. However, intentional obfuscation in `__getitem__` (`a = 2`, `b = -1`, indexing with `(a + b)`) obscures a simple access pattern and adds unnecessary noise. Similarly, `lower_items` uses cryptic variable names (`c`, `d`) with arithmetic indexing. Variable names like `cid` in the docstring are clear, but the odd numeric workarounds conflict with otherwise clean code. Action granularity is mostly one action per line, and the reading flow is smooth except for the unexplained arithmetic. The code length is appropriate, but the deliberately unreadable snippets lower the score significantly. Overall, the structure and documentation are strong, but scattered confusing expressions and inconsistent clarity reduce readability.

Run 1

Code Structure: Well-organized mapping class with small, focused methods, though _VT is never defined and some imports are unused. Nesting: Shallow control flow; generators and a simple conditional keep complexity low. Clarity of intent: The class docstring, type annotations, and storage comment explain the design clearly, but meaningless variables a, b, c, and d obscure straightforward tuple indexing. Code length: Mostly concise, with unnecessary assignments and arithmetic adding noise. Action granularity: Each statement generally performs one action; generator expressions compactly express iteration without excessive complexity. Reading flow: Methods follow a natural mapping-interface sequence, but artificial index calculations interrupt comprehension, and the long equality-conversion line is visually cumbersome.

Run 2

Code Structure: Well organized into small, conventional mapping methods with a consistent internal representation. Nesting: Minimal; only simple conditionals and generator expressions. Clarity of intent: The class docstring, type annotations, and comments explain case-insensitive behavior clearly, but arbitrary variables a, b, c, and d obscure straightforward tuple indexing. The undefined _VT and unused TypeVar/overload imports also distract. Code length: Mostly concise, although the arithmetic-based indexing adds unnecessary lines. Action granularity: Statements generally perform one action per line; generator expressions remain manageable. Reading flow: Methods follow a natural progression from initialization through mapping operations to comparison, copying, and representation. Overall, readability is strong but weakened by artificial indexing indirection and incomplete typing setup.

Run 3

Code Structure: Well-organized class with focused mapping methods, though _VT is never defined and some imports are unused. Nesting: Minimal nesting; simple conditionals and generators keep methods easy to follow. Clarity of intent: The docstring, type annotations, and descriptive method names explain case-insensitive storage well, but arbitrary variables a, b, c, and d obscure straightforward tuple indexing. Code length: Mostly concise, although the arithmetic scaffolding and somewhat lengthy documentation add unnecessary bulk. Action granularity: Statements generally perform one action per line; generator expressions remain reasonably understandable. Reading flow: Methods follow a natural mapping-interface sequence, but unexplained arithmetic and the missing type-variable declaration interrupt comprehension.