This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Invalid coding error hidden on Windows
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: SyntaxError: encoding problem: iso-8859-1 on Windows
View: 20844
Assigned To: Nosy List: eryksun, paul.moore, steve.dower, tim.golden, ubershmekel, zach.ware
Priority: normal Keywords:

Created on 2019-05-05 06:32 by ubershmekel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
log_monitor.py ubershmekel, 2019-05-05 06:32 Reproducing exception
Messages (5)
msg341420 - (view) Author: Yuval Greenfield (ubershmekel) * Date: 2019-05-05 06:32
These lines fail on Windows in a surprising way:

    # -*- coding: utf8 -*-
    import threading
    print("threading %s" % threading)


Normally they would throw this:

  ```File "C:\Python36\Lib\site-packages\missinglink_kernel\callback\log_monitor.py", line 1
SyntaxError: encoding problem: utf8```

But attached is a file that throws this instead:

```
Traceback (most recent call last):
  File "C:\Python36\Lib\site-packages\missinglink_kernel\callback\log_monitor.py", line 2, in <module>
    import threading
NameError: name 'threading' is not defined
```

It seems that the amount of lines in the file will cause the exception hiding bug to manifest.

This issue did reproduce on my Windows machine here:

* Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
* Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
* Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32

It did NOT reproduce on my Mac at all:

It does not repro on my mac at all:
* Python 3.7.1 (default, Dec 14 2018, 13:28:58)  [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
* Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
msg341421 - (view) Author: Yuval Greenfield (ubershmekel) * Date: 2019-05-05 06:34
Note I am aware the actual problem is "utf8" vs "utf-8". But for some reason on Windows the exception does not reflect that.
msg341459 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2019-05-05 16:56
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32

I can't reproduce this on Windows. And it does seem an unlikely combination of effect and cause.

Do I take it that if you take out all the "logging..." lines, the thing works? ie you do correctly import threading and it shows a reasonable value when you print(threading)?
msg341468 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2019-05-05 18:32
> Note I am aware the actual problem is "utf8" vs "utf-8". 

That shouldn't be an issue since "utf8" is an alias. 

The fact that your test file has LF line endings is an issue. It should be fixed in 3.7.4. See issue 20844.
msg341488 - (view) Author: Yuval Greenfield (ubershmekel) * Date: 2019-05-06 07:34
Replacing `utf8` with `utf-8` is the best workaround in my situation. Using the `utf8` alias is required to reproduce the issue based on my testing and the cited issue (https://bugs.python.org/issue20844).

Thank you for the reference.
History
Date User Action Args
2022-04-11 14:59:14adminsetgithub: 80981
2019-05-06 07:34:24ubershmekelsetmessages: + msg341488
2019-05-05 18:32:02eryksunsetstatus: open -> closed

superseder: SyntaxError: encoding problem: iso-8859-1 on Windows

nosy: + eryksun
messages: + msg341468
resolution: duplicate
stage: resolved
2019-05-05 16:56:41tim.goldensetmessages: + msg341459
2019-05-05 06:59:37SilentGhostsettype: compile error -> behavior
2019-05-05 06:34:24ubershmekelsetmessages: + msg341421
2019-05-05 06:32:07ubershmekelcreate