Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marked the std streams as possibly be None #11826

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Apr 24, 2024

Closes: #11778

This comment has been minimized.

@srittau
Copy link
Collaborator Author

srittau commented Apr 24, 2024

Looking at the primer output:

With the exception of cwltool (and streamlit, where only the error message has changed), these are all unintended, but positive side-effects of this change. In all cases, valid objects that were not derived from TextIO were assigned to the streams. We should probably look into replacing TextIO with a protocol at some point.

The cwltool tests assign a string to the streams. This is now unfortunately a false negative, but still worth it, in my opinion.

Copy link
Contributor

@mondeja mondeja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that __stdin__, __stdout__ and __stderr__ may also be None. See the linked issue.

@srittau
Copy link
Collaborator Author

srittau commented Apr 29, 2024

Good catch. I will try using regular None for now. I think this makes sense for the underscored attributes.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

rich (https://github.com/Textualize/rich)
+ rich/console.py:93: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno"  [union-attr]
+ rich/console.py:97: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno"  [union-attr]
+ rich/console.py:101: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno"  [union-attr]
- rich/live.py:180: error: Subclass of "TextIO" and "FileProxy" cannot exist: would have incompatible method signatures  [unreachable]
- rich/live.py:183: error: Subclass of "TextIO" and "FileProxy" cannot exist: would have incompatible method signatures  [unreachable]

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/capture.py:204: error: Item "None" of "TextIOWrapper | None" has no attribute "encoding"  [union-attr]
+ src/_pytest/faulthandler.py:65: error: Item "None" of "TextIOWrapper | None" has no attribute "fileno"  [union-attr]

tornado (https://github.com/tornadoweb/tornado)
+ tornado/test/runtests.py:174: error: Unused "type: ignore" comment  [unused-ignore]

werkzeug (https://github.com/pallets/werkzeug)
- tests/test_debug.py:196: error: Incompatible types in assignment (expression has type "HTMLStringO", variable has type "TextIO")  [assignment]
- tests/test_debug.py:199: error: "TextIO" has no attribute "reset"  [attr-defined]
- tests/test_debug.py:201: error: "TextIO" has no attribute "reset"  [attr-defined]
- tests/test_debug.py:213: error: Incompatible types in assignment (expression has type "HTMLStringO", variable has type "TextIO")  [assignment]
- tests/test_debug.py:216: error: "TextIO" has no attribute "reset"  [attr-defined]

scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/log.py:117: error: Unused "type: ignore" comment  [unused-ignore]

cwltool (https://github.com/common-workflow-language/cwltool)
+ tests/test_context.py:17: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_context.py:18: error: Unused "type: ignore" comment  [unused-ignore]

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/web/bootstrap_test.py:107:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:107:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:131:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:131:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:153:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:153:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:177:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:177:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:201:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:201:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:221:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:221:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:245:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:245:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:270:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:270:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:295:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:295:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:312:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:312:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:333:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:333:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:342:15: error: "TextIO" has no attribute "getvalue"  [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:342:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue"  [union-attr]

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.

sys standard streams can be None
2 participants