Sample

pyint-fd5108bdbbaa-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines82

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.2990–1; higher is more readable
Mi0.4730–1; higher is more readable
LLOC36Logical lines; fewer is more readable
DeepSeek V4 Pro14.330–20; mean of three runs
GPT-6.1 Sol16.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, data: Mapping[str, _VT] | Iterable[tuple[str, _VT]] | None = None, **kwargs: _VT, ) -> None: self._store = OrderedDict() if not (data is None): pass else: 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 not (isinstance(other, Mapping)): return NotImplemented else: other_dict: CaseInsensitiveDict[Any] = CaseInsensitiveDict(other) # type: ignore[reportUnknownArgumentType] # 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.2511.766−82.888
Source linesThe number of non-empty source lines.82+32.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.702−7.053

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.83−1.902
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.976−1.417
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.119.988+1.131
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.53−0.795
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.81.851+0.734
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.073+0.231

Intercept 0.07 + feature contributions = -0.851 (log-odds).
Score = sigmoid(-0.851) = 0.299.

Score0.473
Score36
Run 1

The code is generally well-structured and readable, with clear docstrings, type hints, and separation of methods. However, some sections reduce clarity and flow: the `if not (data is None): pass else: data = {}` block is awkward and should be simplified to `if data is None: data = {}`. The `__eq__` method uses a similar inverted conditional and contains a type-ignore comment that adds noise. Variable naming is mostly clear, but `_store.values()` usage in `copy` and `__iter__` could be clarified with unpacking for readability. Nesting is minimal overall, action granularity is appropriate, and the reading flow is natural aside from the mentioned conditionals. The class is concise but not overly compressed. Minor refactoring of conditionals and removal of unnecessary type-ignore comments would improve readability.

Run 2

The code has good type hints, docstrings, and a clear purpose. However, several structural issues reduce readability. The __init__ method has awkward logic: the `if not (data is None): pass else: data = {}` pattern is confusing and should be simplified to `data = data or {}`. The __eq__ method is structurally odd: the else branch creates an unused variable and the flow is broken. The if/else with pass and the unused `other_dict` variable hurt clarity of intent. Nesting is generally flat, and action granularity is acceptable. Reading flow is mostly natural, but the __init__ and __eq__ sections interrupt it. Code length is concise overall, but the docstring is long relative to the implementation. The logic for case-insensitive storage is easy to follow in __setitem__ and __getitem__. Overall, the code is maintainable but would benefit from cleaning up the branching patterns and removing dead code.

Run 3

The code is well-structured with clear separation of methods, consistent type hints, and a thorough docstring that explains behavior with examples. Nesting is minimal, and each action is generally on its own line. The `__init__` method has an awkward and unnecessarily convoluted conditional (`if not (data is None): pass else: data = {}`), which harms clarity and could be simplified to `if data is None: data = {}`. The `__eq__` method also has a mildly awkward conditional returning `NotImplemented`, but it remains readable. Overall, intent is clear, the class API is logical, and reading flow is natural.

Run 1

Code Structure: Well-organized mapping class with small, focused methods and a consistent internal representation. Nesting: Mostly flat; unnecessary else branches in initialization and equality add minor complexity. Clarity of intent: Descriptive names, type annotations, and documentation explain case-insensitive behavior clearly, but _VT is never defined in the provided snippet, and unused imports distract. Code length: Methods are concise, although the lengthy docstring and redundant pass branch could be streamlined. Action granularity: Statements generally perform one action per line; generator expressions remain manageable. Reading flow: Standard mapping methods follow a natural sequence, but negated conditions such as 'if not (data is None)' are less direct than simple positive checks. Overall, highly approachable code with several avoidable distractions.

Run 2

Code Structure: Clearly organized into small mapping methods around a consistent internal store. Nesting: Shallow throughout, although the constructor's no-op branch and the unnecessary else after an early return add clutter. Clarity of intent: Descriptive method names, type annotations, comments, and the class docstring explain case-insensitive behavior well; however, _VT is undefined in the snippet, and negated conditions are less direct than necessary. Code length: Most methods are concise, though the constructor could be simplified and some documentation is verbose. 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 and representation. Long annotations and the inline type-ignore comment slightly interrupt scanning.

Run 3

Code Structure: Well organized into small, standard mapping methods with a consistent internal representation. Nesting: Very shallow, although redundant else branches and a no-op pass add unnecessary control flow. Clarity of intent: The class docstring, type annotations, and descriptive method names clearly explain case-insensitive behavior; however, _VT is not defined in the provided snippet, and negated conditions are awkward. Code length: Mostly concise, but the constructor and equality check could be simplified, and the docstring is somewhat lengthy. Action granularity: Statements generally perform one action each; generator expressions are compact and understandable. Reading flow: Methods follow a natural progression from initialization through mapping operations to comparison and copying, with consistent formatting. Minor distractions include unused TypeVar and overload imports, an unnecessary comment, and the long inline type-ignore annotation.