-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
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 |
This comment has been minimized.
This comment has been minimized.
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:127: 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:178:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:178:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:203:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:203:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:224:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:224:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:248:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:248:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:273:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:273:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:298:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:298:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:315:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:315:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:336:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:336:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
- lib/tests/streamlit/web/bootstrap_test.py:345:15: error: "TextIO" has no attribute "getvalue" [attr-defined]
+ lib/tests/streamlit/web/bootstrap_test.py:345:15: error: Item "TextIO" of "Union[TextIO, Any]" has no attribute "getvalue" [union-attr]
|
stdin: TextIO | MaybeNone | ||
stdout: TextIO | MaybeNone | ||
stderr: TextIO | MaybeNone |
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.
Is there are reason why these are MaybeNone
instead of None
? I expect running mypy on sys.stdout.write("...")
without an appropriate if sys.stdout is not None
guard to tell me of the NoneType has no attribute write
error that I would get from running that snippet of code using pythonw.exe
. But instead it tells me that everything is fine.
Closes: #11778