You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug? Inconsistent type inference between open() and Path().open() #6666
After spending quite a while one this, I'm not sure if this is an intended mode of operation, a mypy issue or a typeshed issue. If I have this in the wrong place or if it is not an issue, please close and I will re-raise in typeshed if appropriate.
I have run into an issue with inconsistent type-inferences for open() and pathlib.Path().open().
However, running mypy reveal_type on fp and fp1 yields:
Revealed type is 'typing.TextIO'
Revealed type is 'typing.IO[Any]'
I would expect both of these to reveal typing.TextIO. I found this issue when using a routine that switched TextIO output between sys.stdout (TextIO) and a file opened with Path().open() (IO).
This is on python 3.7.2 and mypy 0.700 with arguments: --follow-imports=silent, --show-column-numbers, --disallow-untyped-defs.
Right now we have a plugin that special-cases builtins.open() but not Path.open(). This should be solved in typeshed by making the definition of Path.open() overloaded on various Literal types. So I am closing this as "not a mypy bug" but I recommend that you submit a PR to typeshed to add this.
Activity
gvanrossum commentedon Apr 12, 2019
Right now we have a plugin that special-cases builtins.open() but not Path.open(). This should be solved in typeshed by making the definition of Path.open() overloaded on various Literal types. So I am closing this as "not a mypy bug" but I recommend that you submit a PR to typeshed to add this.
BuongiornoTexas commentedon Apr 12, 2019
Thanks. Will do.
I figured with an issue number of 6666, this was always going to be short lived :-).
gvanrossum commentedon Apr 12, 2019
Well, there's always https://en.wikipedia.org/wiki/Chinese_numerology#Six
ilevkivskyi commentedon Apr 12, 2019
Superseded by python/typeshed#2911