Skip to content

Conversation

@Avasam
Copy link
Collaborator

@Avasam Avasam commented Oct 11, 2022

See https://peps.python.org/pep-0597/
This also happened to me on Windows in #8879 because of mathematical unicode characters as part of the comments:

(.venv) PS C:\Users\Avasam\Documents\Git\typeshed> python .\tests\check_new_syntax.py
Traceback (most recent call last):
  File "C:\Users\Avasam\Documents\Git\typeshed\tests\check_new_syntax.py", line 110, in <module>
    main()
  File "C:\Users\Avasam\Documents\Git\typeshed\tests\check_new_syntax.py", line 100, in main
    stub = f.read()
  File "C:\Program Files\Python39\lib\encodings\cp1252.py", line 23, in decode 
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 176166: 
character maps to <undefined>

There are linters to catch this, namely pylint (unspecified-encoding), flake8-encodings and flake8-file-encoding. I have tried both flake8 plugins mentioned and they gave me the same results, other than slightly different error messages:
image

@JelleZijlstra
Copy link
Member

Thanks! This is generally an issue on Windows only since Unix defaults to utf-8.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Avasam Avasam mentioned this pull request Oct 11, 2022
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines +47 to +48
requests.post("http://httpbin.org/anything", data=open("/tmp/foobar", "rb", encoding="UTF-8")).json()["data"]
requests.post("http://httpbin.org/anything", data=open("/tmp/foobar", "r", encoding="UTF-8")).json()["data"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in this file is never actually run (it's a test-case), but I guess there's no way of telling the flake8 plugin that, and I don't think this change does any actual harm :)

@AlexWaygood AlexWaygood merged commit 573ee94 into python:master Oct 11, 2022
@Avasam Avasam deleted the UnicodeDecodeError branch October 11, 2022 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants