Sample

pyint-aea035ef9ee2-I08

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

Matched original source

Lines83

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.2930–1; higher is more readable
Mi0.4720–1; higher is more readable
LLOC38Logical lines; fewer is more readable
DeepSeek V4 Pro170–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.4010–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: return self._store[key.lower()][1] 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.""" return ((lowerkey, keyval[1]) 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]: remaining_steps = 3 while remaining_steps > 0: remaining_steps -= 1 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.2551.406−84.196
Source linesThe number of non-empty source lines.83+33.2
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.705−7.058

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.84−1.938
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.94−1.415
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.119.988+1.132
Indentation frequencyHow rapidly indentation changes from line to line.53+1.096
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.54−0.818
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.82.81+0.748
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.072+0.244

Intercept 0.07 + feature contributions = -0.882 (log-odds).
Score = sigmoid(-0.882) = 0.293.

Score0.472
Score38
Run 1

The code is generally well-structured and readable. It has clear intent, reasonable nesting, and mostly one action per line. The class docstring is excellent. However, there is a confusing dead code block in `copy()` (the `while remaining_steps` loop does nothing) which harms clarity and should be removed. Overall, the code is clean and maintainable.

Run 2

The code is well-structured with clear separation of methods and logical organization. The class has a clear purpose documented in its docstring, including usage examples. Nesting is minimal and flat, with only basic conditional logic in __eq__. Intent is clear through descriptive method names and type hints. Code length is concise and appropriate. Action granularity is good, with one operation per line. Reading flow is natural, following standard Python dictionary implementation patterns. Minor deductions for the unnecessary while loop in copy() which appears to be leftover debug code, and the __eq__ method has slightly awkward type checking flow.

Run 3

The code is well-structured and highly readable. The class has a clear, single responsibility and follows standard mapping patterns. Methods are concise with low nesting and one action per line. Type hints and docstrings clearly express intent. The main flaw is the `copy` method: it contains a pointless `while` loop that serves no purpose, likely leftover debug or placeholder code. This hurts clarity and should be removed. Otherwise, the code flows naturally and is easy to follow.

Run 1

Code Structure: Methods are logically organized around the mapping interface, though _VT is not defined in the snippet and several imports are unused. Nesting: Control flow is shallow and easy to follow. Clarity of intent: Descriptive method names, type hints, and documentation clearly explain case-insensitive lookup and preserved key casing; tuple indexing is slightly less explicit. Code length: Most methods are concise, but copy() contains a pointless countdown loop that adds noise and suggests missing intent. Action granularity: Statements generally perform one action per line, with compact generator expressions remaining understandable. Reading flow: The progression from initialization through mapping operations, comparison, copying, and representation is natural. The long type-ignore line and unnecessary loop interrupt otherwise clean reading.

Run 2

Code Structure: Methods are logically organized around the mapping interface, although _VT is never defined and some imports are unused. Nesting: Control flow is shallow and easy to follow. Clarity of intent: The class docstring, type annotations, and storage comment clearly explain case-insensitive behavior; however, the pointless countdown in copy() introduces confusion. Code length: Most methods are concise, but the countdown and unused imports add unnecessary material. Action granularity: Statements generally perform one action per line; generator expressions compactly express iteration without excessive complexity. Reading flow: Initialization, core mapping operations, comparison, copying, and representation follow a natural progression. Tuple indexing and the long type-ignore line slightly interrupt readability. Overall, the implementation is readable, but the undefined type variable and unexplained loop undermine an otherwise clean design.

Run 3

Code Structure: Methods are logically organized around the mapping interface, although _VT is never defined and some imports are unused. Nesting: Control flow is shallow and easy to follow. Clarity of intent: The class docstring, type annotations, and descriptive method names explain case-insensitive behavior well; however, the pointless countdown in copy() obscures its otherwise simple purpose. Code length: Most methods are concise, but the countdown and some verbose documentation add unnecessary length. Action granularity: Statements generally perform one action per line; generator expressions remain reasonably readable. Reading flow: Construction, basic operations, comparison, copying, and representation follow a natural sequence. Dense tuple indexing and the long type-ignore line introduce minor friction. Overall, the code is highly approachable but weakened by distracting dead work and incomplete typing setup.