Remove open plugin, not needed with overloaded signatures on typeshed#7794
Remove open plugin, not needed with overloaded signatures on typeshed#7794ilai-deutel wants to merge 10 commits intopython:masterfrom
Conversation
test-data/unit/pythoneval.test
Outdated
| [out] | ||
| _program.py:3: note: Revealed type is 'typing.BinaryIO' | ||
| _program.py:4: note: Revealed type is 'typing.BinaryIO' | ||
| _program.py:3: note: Revealed type is 'typing.IO[Any]' |
There was a problem hiding this comment.
These seem like regressions. Why can mypy no longer infer BinaryIO here?
There was a problem hiding this comment.
p.open(mode='rb', errors='replace') raises an exception (ValueError: binary mode doesn't take an errors argument), so its type is not really BinaryIO.
mypy infers it is a IO[Any] because of the fallback overload with mode: str, but ideally open should have a return type of NoReturn in this case. I wonder if adding an overload variant with a return type of NoReturn would solve the problem.
There was a problem hiding this comment.
NoReturn is not really intended for error cases. Falling back to the default return type on error case seems fine to me.
There was a problem hiding this comment.
To be clear, when you say "default return type", do you mean IO[Any] or BinaryIO?
There was a problem hiding this comment.
Looking at this it seems to me it is better to improve this plugin instead of removing it. For example, the p.open(mode='rb', errors='replace') call will silently fall back to the default overload, but with the plugin we can detect the error and give a nice error message (matching the runtime one).
There was a problem hiding this comment.
I modified the plugin to detect use of text-only arguments in binary mode.
|
The CI failure is caused by python/typeshed#3446. |
|
Fixed upstream, AppVeyor tests now pass |
JukkaL
left a comment
There was a problem hiding this comment.
I think that is close to ready to merge, but there is still an issue with the Python 2 signature of open().
|
Since Jukka made previous reviews, I think it would make sense if he will review. |
|
Hi @JukkaL, is there anything else I need to do before we can merge this PR? |
|
I'm sorry about this, but I'm going to close this in favor of #9275. (Which I'm also not sure if it is going to get merged) |
python/typeshed#3371 adds overloaded signatures for
open(),Path.open(), etc.Consequently:
reveal_type(open())now produceserror: All overload variants of "open" require at least one argumentinstead ofToo few arguments for "open".This pull request should probably not be merged before python/typeshed#3371. However, we have a circular dependency:
mypy_selftestin the typeshed PR fails because of the issues withmypytests mentioned above. We can use CI on this PR to make sure the tests will pass on typeshed after merging both PRs.After python/typeshed#3371 is merged, the typeshed submodule will need to be updated.