Skip to content

Fix 'WriteToConn' object has no attribute 'flush'#16801

Merged
hauntsaninja merged 2 commits intopython:masterfrom
meshy:fix-WriteToConn-type
Jan 30, 2024
Merged

Fix 'WriteToConn' object has no attribute 'flush'#16801
hauntsaninja merged 2 commits intopython:masterfrom
meshy:fix-WriteToConn-type

Conversation

@meshy
Copy link
Copy Markdown
Contributor

@meshy meshy commented Jan 19, 2024

WriteToConn replaces stdout and stderr to capture output, but causes issues because it doesn't implement the TextIO API (as expected of sys.stdout and sys.stderr).

By stubbing the rest of the TextIO API we prevent issues with other code which uses more of the API than we had previously accounted for.

Fixes #16678

This default isn't used anywhere in the codebase.
@github-actions

This comment has been minimized.

@meshy meshy marked this pull request as ready for review January 19, 2024 22:55
Comment thread mypy/dmypy_util.py Outdated
@meshy meshy force-pushed the fix-WriteToConn-type branch from 3241a72 to aee0c2a Compare January 20, 2024 22:37
This class replaced stdout and stderr to capture output, but caused
issues because it didn't implement the full API of sys.stdout and
sys.stderr.

By fully stubbing the TextIO API we prevent issues with other code
which uses more of the API than we had previously accounted for.

Fixes python#16678
@meshy meshy force-pushed the fix-WriteToConn-type branch from b939bb3 to a405475 Compare January 20, 2024 22:40
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit 06b01c8 into python:master Jan 30, 2024
@hauntsaninja
Copy link
Copy Markdown
Collaborator

Thanks for the fix!

@meshy meshy deleted the fix-WriteToConn-type branch January 30, 2024 09:30
@mattwedge
Copy link
Copy Markdown

Is there any chance this could make it into a 1.7.2 release? Or is 1.7 not really maintained any more?

@brianschubert
Copy link
Copy Markdown
Collaborator

@mattwedge Generally mypy doesn't backport bugfixes. Is there a reason you can't upgrade to a release that includes this fix (1.9+)?

@mattwedge
Copy link
Copy Markdown

@mattwedge Generally mypy doesn't backport bugfixes. Is there a reason you can't upgrade to a release that includes this fix (1.9+)?

It's for a Django project which uses django-stubs which as you can see at https://pypi.org/project/django-stubs/ requires that we use mypy 1.7.x for Django 4. It seems that in order to use the latest mypy we would have to upgrade to Django 5

@brianschubert
Copy link
Copy Markdown
Collaborator

You may have luck trying version combinations outside of the ones in that table. The latest version of that table now has this text below it, which gives some insight:

What "partial" support means, and why we don't pin to the exact Django/mypy version, is explained in
typeddjango/django-stubs#2101 (comment).

From skimming the linked discussion comment, it seems that the latest versions of django-stubs are still mostly compatible with Django 4, and should work fine with a range of mypy versions.

The reason django-stubs relies on particular versions of mypy is to guard against plugin API changes. From what I can tell, there were no plugin API changes between v1.4 and v1.11, so all versions from within that range should be equally compatible. (there was one plugin API change in v1.12, which would require using django-stubs v5.1.1 or later).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants