[issue46835] ImportError: bad magic number in ... does not indicate where is that file located

2022-02-24 Thread Brett Cannon


Change by Brett Cannon :


--
nosy: +brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46835] ImportError: bad magic number in ... does not indicate where is that file located

2022-02-23 Thread Miro Hrončok

Change by Miro Hrončok :


--
keywords: +patch
pull_requests: +29658
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/31534

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46835] ImportError: bad magic number in ... does not indicate where is that file located

2022-02-23 Thread Petr Viktorin


Petr Viktorin  added the comment:

I assume a PR review should be enough.

--
components: +Library (Lib) -Interpreter Core

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46835] ImportError: bad magic number in ... does not indicate where is that file located

2022-02-23 Thread Miro Hrončok

Miro Hrončok  added the comment:

Apparently, the exception already contains a path attribute with exactly the 
kind of information I'd like to see.

What if the message was:

ImportError: bad magic number in '/usr/bin/six.pyc': b'\x03\xf3\r\n'

Would that be accepted as a PR? Should I discuss this on the mailing list?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46835] ImportError: bad magic number in ... does not indicate where is that file located

2022-02-23 Thread Miro Hrončok

New submission from Miro Hrončok :

Recently I've been debugging a very nasty bug report that looked like this:

Traceback (most recent call last):
  File "/usr/bin/jupyter-notebook", line 5, in 
from notebook.notebookapp import main
  File "/usr/lib/python3.10/site-packages/notebook/notebookapp.py", line 
78, in 
from .services.kernels.kernelmanager import MappingKernelManager, 
AsyncMappingKernelManager
  File 
"/usr/lib/python3.10/site-packages/notebook/services/kernels/kernelmanager.py", 
line 18, in 
from jupyter_client.session import Session
  File "/usr/lib/python3.10/site-packages/jupyter_client/session.py", line 
41, in 
from jupyter_client.jsonutil import extract_dates, squash_dates, 
date_default
  File "/usr/lib/python3.10/site-packages/jupyter_client/jsonutil.py", line 
10, in 
from dateutil.parser import parse as _dateutil_parse
  File "/usr/lib/python3.10/site-packages/dateutil/parser/__init__.py", 
line 2, in 
from ._parser import parse, parser, parserinfo, ParserError
  File "/usr/lib/python3.10/site-packages/dateutil/parser/_parser.py", line 
42, in 
import six
ImportError: bad magic number in 'six': b'\x03\xf3\r\n'

For details, see https://bugzilla.redhat.com/2057340 and 
https://github.com/benjaminp/six/issues/359


What would really make things much easier to understand would be if the 
exception mentioned what is the path of 'six'.


Consider this example:

A rogue .py file in /usr/bin:

$ sudo touch /usr/bin/copy.py

Programs fail with:

Traceback (most recent call last):
  File "/usr/bin/...", line ..., in 
...
ImportError: cannot import name 'deepcopy' from 'copy' (/usr/bin/copy.py)

Immediately I can see there is /usr/bin/copy.py which is probably not supposed 
to be there.

However, when it is a pyc instead:

$ sudo touch /usr/bin/copy.pyc

Programs fail with:

Traceback (most recent call last):
  File "/usr/bin/...", line ..., in 
...
ImportError: bad magic number in 'copy': b''

Now I have no idea where "copy" is.


The is a request for that exception to give that infomartion.

--
components: Interpreter Core
messages: 413788
nosy: hroncok, petr.viktorin
priority: normal
severity: normal
status: open
title: ImportError: bad magic number in ... does not indicate where is that 
file located
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com