Skip to content

MyPy daemon version 1.7.0+ crashes if colorama is installed and reporting (cubertura) is used. #16678

@sshishov

Description

@sshishov

Bug Report

MyPy daemon version 1.7.0+ crashes if colorama is installed and reporting (cubertura) is used.
The issue is related to this MR: #16252
The wrapper should implement "ALL" abstract method to make sure that it is not broken somewhere down the stream. IO has standard interface which can be used anywhere in the code (plugins or other 3rd party libraries).
More specifically the wrapper does not implement flush which is used in colorama

To Reproduce

Install latest:

  • mypy 1.7.0+
  • colorama 0.4.6+

Run dmypy run with cubertura reporting enabled in config file

In pyproject.toml or mypy.ini put the following lines:

cobertura_xml_report = "src/mypy-reports"
xslt_txt_report = "src/mypy-reports"
xslt_html_report = "src/mypy-reports"

Expected Behavior

MyPy daemon should not crash

Actual Behavior

MyPy daemon crash with exception:

python -m mypy.dmypy run .

dmypy: Ignoring report generation settings. Start/restart cannot generate reports.
Daemon started
Daemon crashed!
Traceback (most recent call last):
  File "mypy/dmypy_server.py", line 236, in serve
  File "mypy/dmypy_server.py", line 285, in run_command
  File "mypy/dmypy_server.py", line 353, in cmd_run
  File "mypy/dmypy_server.py", line 424, in check
  File "mypy/dmypy_server.py", line 463, in initialize_fine_grained
  File "mypy/build.py", line 189, in build
  File "mypy/build.py", line 286, in _build
  File "mypy/report.py", line 95, in finish
  File "mypy/report.py", line 698, in on_finish
  File "${VENV}/lib/python3.11/site-packages/colorama/ansitowin32.py", line 47, in write
    self.__convertor.write(text)
  File "${VENV}/lib/python3.11/site-packages/colorama/ansitowin32.py", line 177, in write
    self.write_and_convert(text)
  File "${VENV}/lib/python3.11/site-packages/colorama/ansitowin32.py", line 205, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "${VENV}/lib/python3.11/site-packages/colorama/ansitowin32.py", line 211, in write_plain_text
    self.wrapped.flush()
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'WriteToConn' object has no attribute 'flush'

Generated Cobertura report:%

Your Environment

  • Mypy version used: 1.7.1
  • Mypy command-line flags: dmypy run -- --cache-fine-grained
  • Mypy configuration options from mypy.ini (and other config files):
cobertura_xml_report = "src/mypy-reports"
xslt_txt_report = "src/mypy-reports"
xslt_html_report = "src/mypy-reports"
plugins = [
    "mypy_django_plugin.main",
    "mypy_drf_plugin.main",
    "pydantic.mypy",
]
enable_error_code = [
    "ignore-without-code",
    "possibly-undefined",
    "redundant-self",
    "unused-awaitable",
]
strict = true
warn_unreachable = true
ignore_missing_imports = true
  • Python version used: 3.11.5

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions