[issue43969] "bad magic number" when Python 2's pyc file exists without py file

2021-11-04 Thread Mitchell Hentges


Mitchell Hentges  added the comment:

I'm going to close this here - I currently don't have the cycles to push this 
forward. Besides, this issue only occurs in environments that are using both 
Python 2 and 3, and as Python 2's EOL date gets further in the past, the 
severity of this ticket decreases.

For future readers, if you need a workaround for this exact problem, it was 
solved by my team with this import hook: 
https://hg.mozilla.org/mozilla-central/file/50e4a4e6975a7f828277a2b9c3cc9770a6c94107/build/mach_initialize.py#l630

--
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue43969] "bad magic number" when Python 2's pyc file exists without py file

2021-04-30 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Unless you find documentation that says otherwise, this an enhancement proposal 
for 3.11.

If no core developer (other than me) jumps on this, you might use git blame to 
fine out who committed code in the area you proposed changing.

--
nosy: +terry.reedy
type: behavior -> enhancement
versions: +Python 3.11 -Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

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



[issue43969] "bad magic number" when Python 2's pyc file exists without py file

2021-04-29 Thread Mitchell Hentges


Mitchell Hentges  added the comment:

Looking closer into this, it appears that Python 3 will still try to load 
non-__pycache__ `.pyc` files. Perhaps I'm missing context, but aren't those 
only supposed by to written and read by Python 2?

Location where `pyc` loader is registered: 
https://github.com/python/cpython/blob/v3.9.4/Lib/importlib/_bootstrap_external.py#L1571-L1572
Location where `__pycache__` loading happens is part of SourceFileLoader here: 
https://github.com/python/cpython/blob/v3.9.4/Lib/importlib/_bootstrap_external.py#L870

I'll attach a patch to remove this pyc-loading for convenience, but I don't 
have enough context to be confident that it's the correct solution.

--
keywords: +patch
message_count: 1.0 -> 2.0
pull_requests: +24422
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25731

___
Python tracker 

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



[issue43969] "bad magic number" when Python 2's pyc file exists without py file

2021-04-28 Thread Mitchell Hentges


New submission from Mitchell Hentges :

Python 3 imports may fail if a Python 2 .pyc file exists without an 
accompanying .py file.

-

My project vendors code, and we recently updated "requests" to a drastically 
newer version.

As part of this version change, `requests/packages/__init__.py` was removed, 
and  `requests/packages.py` was added.

This project is long-lived, and many people have imported `requests` with 
Python 2. So, `requests/packages/__init__.pyc` exists.

After making this update, importing requests with Python 3 fails:
`ImportError: bad magic number in 'parent.child': b'\x03\xf3\r\n'`

Interestingly, deleting `requests/packages/__init__.pyc` allows Python 3 to 
work again.

-

I've attached a "reproduction" script that produces the directory structure and 
tweak required to cause the failure.
I'm running Python 2.7.18 and Python 3.9.1.

--
components: Interpreter Core
files: repro.sh
messages: 392254
nosy: mitchhentges
priority: normal
severity: normal
status: open
title: "bad magic number" when Python 2's pyc file exists without py file
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49997/repro.sh

___
Python tracker 

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