Sample

pyint-22aee56c115d-I02

Shorten method, parameter, and local names without collisions

Matched original source

Lines80

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3280–1; higher is more readable
Mi0.4450–1; higher is more readable
LLOC35Logical lines; fewer is more readable
DeepSeek V4 Pro100–20; mean of three runs
GPT-6.1 Sol13.670–20; mean of three runs
BTTF0.4460–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, dat: Mapping[str, _VT] | Iterable[tuple[str, _VT]] | None = None, **kwa: _VT, ) -> None: self._store = OrderedDict() if dat is None: dat = {} self.update(dat, **kwa) def __setitem__(self, key2: str, val: _VT) -> None: # Use the lowercased key for lookups, but store the actual # key alongside the value. self._store[key2.lower()] = (key2, val) def __getitem__(self, key3: str) -> _VT: return self._store[key3.lower()][1] def __delitem__(self, key4: str) -> None: del self._store[key4.lower()] def __iter__(self) -> Iterator[str]: return (cas for cas, _2 in self._store.values()) def __len__(self) -> int: return len(self._store) def lower2(self) -> Iterator[tuple[str, _VT]]: """Like iteritems(), but with all lowercase keys.""" return ((low, key5[1]) for (low, key5) in self._store.items()) def __eq__(self, oth: object) -> bool: if isinstance(oth, Mapping): other2: CaseInsensitiveDict[Any] = CaseInsensitiveDict(oth) # type: ignore[reportUnknownArgumentType] else: return NotImplemented # Compare insensitively return dict(self.lower2()) == dict(other2.lower_items()) # Copy is required def cop(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.2461.042−81.214
Source linesThe number of non-empty source lines.80+32
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.742−7.113

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.81−1.832
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.113.975−1.162
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.113.975+1.034
Indentation frequencyHow rapidly indentation changes from line to line.50+0.992
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.51−0.749
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.79.835+0.706
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.074+0.224

Intercept 0.07 + feature contributions = -0.716 (log-odds).
Score = sigmoid(-0.716) = 0.328.

Score0.445
Score35
Run 1

The code has a clear class purpose and docstring but suffers from several readability issues. The structure is reasonable with logical method ordering, but naming is inconsistent and confusing (e.g., 'key2', 'key3', 'key4', 'key5', 'oth', 'other2', 'lower2', 'cop'). The '__eq__' method is awkward with a type-ignored cast and an unnecessary reassignment. Some methods mix intent with implementation details, and the generator expressions reduce clarity. Nesting is generally flat, which is good, but variable names force the reader to infer meaning. Action granularity is mostly one action per line, though concatenated operations and inline comments add minor clutter. Overall, while functionally structured, the poor naming and unclear equality logic significantly reduce readability.

Run 2

The code has clear intent and decent structure, but suffers from poor naming, inconsistent method names, and a missing method. Variable names like key2, key3, key4, key5, _2, and oth are cryptic. Method names are inconsistent: lower2 should be lower_items, cop should be copy, and __eq__ calls other2.lower_items() which does not exist (likely a bug). The generator expressions are concise but slightly reduce readability due to unclear placeholder names. Nesting is flat, and action granularity is mostly one action per line, aiding flow. The docstring is helpful but long. Overall, the code is understandable, but these naming and consistency issues hurt readability significantly.

Run 3

The code has decent structure with clear class definition and method separation, but suffers from poor naming choices and inconsistent implementation patterns. Variable names like key2, key3, key4, key5, cas, _2, and oth lack clarity and require mental mapping to understand. The method lower2 is misleadingly named since it returns items, not just keys, while the docstring references lower_items which doesn't exist. The method cop is likely a typo for copy, which is confusing. The action granularity is mostly one action per line, and nesting is minimal, which is positive. However, the reading flow is disrupted by these naming inconsistencies and the mismatch between documentation and implementation. The __eq__ method creates a full CaseInsensitiveDict from other mappings, which is a bit indirect but functional. The iterator uses a generator expression that's reasonably clear, but the variable name cas for original-case keys is cryptic. Overall, the code is functional but requires close reading to understand due to naming issues and documentation mismatches.

Run 1

Code Structure: Methods are logically organized around the mapping interface, though undefined _VT and inconsistent method names undermine coherence. Nesting: Minimal nesting and short methods make control flow easy to follow. Clarity of intent: The class docstring and storage comment clearly explain case-insensitive behavior, but names such as dat, kwa, key2, key5, lower2, and cop are vague or misleading. Documentation promises lower_items and copy, while implementations use different names; equality also calls the absent lower_items method. Code length: Implementation is concise, although the docstring is comparatively lengthy and includes outdated iterator terminology. Action granularity: Statements generally perform one action per line; generator expressions are compact without excessive complexity. Reading flow: Conventional method ordering supports natural reading, but inconsistent naming, tuple indexing, and the long inline type-ignore comment interrupt comprehension.

Run 2

Code Structure: Methods are logically organized around the mapping interface, but _VT is undefined and method names conflict with documented usage. Nesting: Very shallow, with simple conditionals and comprehensions. Clarity of intent: The class docstring and storage comment explain the design well, but names such as dat, kwa, key2, key5, lower2, and cop obscure meaning. Equality calls lower_items(), although the implemented method is lower2(), undermining confidence in the intended behavior. Code length: Implementation is concise; the substantial docstring provides useful context but references unsupported or renamed methods. Action granularity: Most lines perform one clear action, although the equality conversion line is crowded by an annotation and suppression comment. Reading flow: Standard mapping methods create a natural progression, but inconsistent naming and documentation force readers to reconcile discrepancies.

Run 3

Code Structure: The class is logically organized into small mapping methods, but _VT is undefined and documented method names differ from implementations. Nesting: Minimal nesting makes control flow easy to follow. Clarity of intent: The docstring and storage comment explain case-insensitive behavior well, but names such as dat, kwa, key2, key5, lower2, and cop obscure meaning. Equality calls lower_items(), although only lower2() is defined, creating confusion. Code length: Methods are concise; the lengthy docstring is mostly useful, though outdated references and unused imports add noise. Action granularity: Statements generally perform one action per line, with compact generator expressions remaining manageable. Reading flow: Standard mapping-method ordering supports natural reading, but inconsistent naming, missing type-variable setup, and documentation mismatches interrupt comprehension.