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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
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 The cwltool tests assign a string to the streams. This is now unfortunately a false negative, but still worth it, in my opinion. |
There was a problem hiding this 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.
Good catch. I will try using regular |
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]
|
Closes: #11778