Skip to content

Support TextIOWrapper.reconfigure() #3049

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

Closed
grantwwu opened this issue Jun 11, 2019 · 6 comments · Fixed by #4035
Closed

Support TextIOWrapper.reconfigure() #3049

grantwwu opened this issue Jun 11, 2019 · 6 comments · Fixed by #4035
Labels
stubs: false positive Type checkers report false errors

Comments

@grantwwu
Copy link

I'm getting a

"TextIO" has no attribute "reconfigure"

error for

sys.stdin.reconfigure(encoding="latin-1")

It's a new Python 3.7 feature. Was informed in Gitter that this hadn't been added to Typeshed yet and to open a ticket for it.

See https://docs.python.org/3/whatsnew/3.7.html#io

@srittau srittau added size-medium stubs: false positive Type checkers report false errors labels Jun 11, 2019
@srittau
Copy link
Collaborator

srittau commented Jun 11, 2019

Currently sys.stdin et al. are typed as TextIO, not TextIOWrapper. This would need to be changed as well, although I am not sure that this does not cause complications. But adding TextIOWrapper.reconfigure() would be welcome in any case.

@serhiy-storchaka
Copy link
Member

For the following code

import sys, io

if isinstance(sys.stdout, io.TextIOWrapper) and sys.version_info >= (3, 7):
    sys.stdout.reconfigure(errors="replace")

I get the error:

reconfigure37.py:4: error: "TextIOWrapper" has no attribute "reconfigure"

MyPy understand that sys.stdout is a TextIOWrapper instance.

@serhiy-storchaka
Copy link
Member

What is worse -- I cannot silence the error by adding # type: ignore, because on Python 3.6 I get error: unused 'type: ignore' comment.

@grantwwu
Copy link
Author

I haven't touched MyPy in many months but your platform check might be too complex for https://mypy.readthedocs.io/en/stable/common_issues.html#python-version-and-system-platform-checks to understand. Try splitting it into two ifs?

@srittau
Copy link
Collaborator

srittau commented May 14, 2020

FWIW, I just checked the following with mypy 0.770 using --warn-unused-ignores under both Python 3.6.9 and 3.7.4 and it works or me:

import sys, io

if isinstance(sys.stdout, io.TextIOWrapper) and sys.version_info >= (3, 7):
    sys.stdout.reconfigure(errors="replace")  # type: ignore

That said, we'll gladly accept a PR that adds TextIOWrapper.reconfigure() :)

@serhiy-storchaka
Copy link
Member

It is the same if split on two ifs.

adam-grant-hendry added a commit to adam-grant-hendry/commitizen that referenced this issue Jul 10, 2023
adam-grant-hendry added a commit to adam-grant-hendry/commitizen that referenced this issue Jul 25, 2023
adam-grant-hendry added a commit to adam-grant-hendry/commitizen that referenced this issue Jul 31, 2023
Lee-W pushed a commit to commitizen-tools/commitizen that referenced this issue Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants