Sample

pyint-590439e1feca-I06

Invert eligible conditions and exchange their branches

Matched original source

Lines43

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.3670–1; higher is more readable
Mi0.4230–1; higher is more readable
LLOC31Logical lines; fewer is more readable
DeepSeek V4 Pro13.330–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.6770–1; higher is more readable

Views

Source code

import email.message import email.policy import mimetypes import warnings from collections import namedtuple from datetime import datetime, timezone from email import charset as Charset from email import generator from email.errors import HeaderParseError from email.header import Header from email.headerregistry import Address, AddressHeader, parser from email.mime.base import MIMEBase from email.mime.message import MIMEMessage from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import formataddr, getaddresses, make_msgid from io import BytesIO, StringIO from pathlib import Path from django.conf import settings from django.core.mail.utils import DNS_NAME from django.utils.deprecation import ( RemovedInDjango70Warning, deprecate_posargs, warn_about_external_use, ) from django.utils.encoding import force_bytes, force_str, punycode from django.utils.timezone import get_current_timezone from .deprecation import ( CONNECTION_ARG_WARNING, FAIL_SILENTLY_ARG_WARNING, report_using_incompatibility, ) class SafeMIMEMultipart(MIMEMixin, MIMEMultipart): def __init__( self, _subtype="mixed", boundary=None, _subparts=None, encoding=None, **_params ): self.encoding = encoding MIMEMultipart.__init__(self, _subtype, boundary, _subparts, **_params) def __setitem__(self, name, val): name, val = forbid_multi_line_headers(name, val, self.encoding) MIMEMultipart.__setitem__(self, name, val)

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.1623.002−53.559
Source linesThe number of non-empty source lines.43+17.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.792−7.188

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Indentation frequencyHow rapidly indentation changes from line to line.43+0.75
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.43−0.566
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.44−0.522
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.06+0.356
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.42.784+0.188
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.86.977−0.019

Intercept 0.07 + feature contributions = -0.547 (log-odds).
Score = sigmoid(-0.547) = 0.367.

Score0.423
Score31
Run 1

The code is moderately readable but has several issues. The import section is lengthy but organized by type. The class definition is simple, but the __init__ method contains multiple operations in a single line and lacks type hints or docstrings. The __setitem__ method chains a helper function call with a parent method call, which reduces clarity. The use of double underscores and mixing of MIMEMixin and MIMEMultipart inheritance creates ambiguity about the class's true purpose. While the code is flat and not deeply nested, the lack of comments explaining the safety wrapper's intent hurts comprehension. The variable naming like _subtype and **_params is conventional for MIME but may confuse newcomers. Overall, the code is functional but could benefit from better documentation and clearer separation of actions.

Run 2

The code demonstrates strong organization and clarity. Imports are logically grouped: standard library, third-party (Django), and local modules, with specific utilities clearly separated. The class definition is flat and straightforward, with minimal nesting and good use of line breaks to maintain readability. The __init__ method has clear parameter naming, though the underscore-prefixed parameters may not be immediately obvious in intent. The __setitem__ method follows the single-responsibility principle by delegating header validation to a separate function (forbid_multi_line_headers) before calling the parent implementation, exemplifying good action granularity. The reading flow is natural and predictable. Minor deductions: some parameters lack type hints, which would improve clarity, and the underscore-prefixed parameter convention may be unfamiliar to newer Python developers. Additionally, the absence of docstrings makes the class's safety-related purpose less immediately apparent. The import block is somewhat lengthy but well-organized, reducing cognitive overhead.

Run 3

The code has a clear purpose with a good import structure and reasonable naming conventions. However, it has several readability issues. The 'SafeMIMEMultipart' class has moderate nesting and mixed responsibilities - it handles initialization, encoding, and header sanitization. The 'MIMEMixin' reference is undefined in the shown code, creating ambiguity. The '__setitem__' method does multiple actions in one line (calling 'forbid_multi_line_headers' and then setting the item), though it's reasonably concise. The method signatures are slightly long but readable. The code is neither deeply nested nor excessively flat, but the lack of docstrings or comments makes the intent of 'forbid_multi_line_headers' unclear. The 'encoding' attribute is stored but its usage isn't evident. Overall, functional but could benefit from better documentation, clearer separation of concerns, and more explicit action granularity.

Run 1

Code Structure: Imports and a small class are logically organized, although many imports are unused in this excerpt and the class lacks standard blank-line separation. Nesting: Methods are flat, with no nested control flow. Clarity of intent: The class name and forbid_multi_line_headers call clearly suggest safe multipart email handling; externally defined MIMEMixin and the validation helper leave some behavior implicit. Code length: The class is concise, but the extensive import block overwhelms the small implementation shown. Action granularity: Each statement performs one clear action. Reading flow: Initialization followed by header-assignment validation is natural, with consistent formatting and readable line wrapping.

Run 2

Code Structure: Imports are grouped coherently, followed by a small class with clearly separated methods, although many imports are unused in this snippet. Nesting: Methods are flat, with no nested control flow. Clarity of intent: SafeMIMEMultipart and forbid_multi_line_headers communicate the header-safety purpose well, though MIMEMixin and the validation helper are not defined here, and val is a generic name. Code length: The class is concise, but the extensive import section outweighs the implementation shown. Action granularity: Each statement performs one clear action; unpacking the validated header pair is straightforward. Reading flow: Initialization and header assignment follow a natural order, with readable multiline signature formatting. Additional spacing between imports and the class would improve visual separation.

Run 3

Code Structure: Imports are grouped logically and the class has two clearly separated methods, although many imports are unused in this excerpt. Nesting: Very shallow, with no nested conditionals or loops. Clarity of intent: The class name and header-validation call clearly communicate safe multipart message handling, but MIMEMixin and forbid_multi_line_headers are not defined in the excerpt, and val is a generic name. Code length: The class is concise; the extensive import section outweighs the implementation. Action granularity: Statements generally perform one action per line, with the tuple assignment naturally combining validation and unpacking. Reading flow: Initialization followed by header assignment handling is natural, though the long import preamble and limited spacing before the class slightly reduce readability.