[issue33237] Improve AttributeError message for partially initialized module

2018-10-30 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> fixed
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



[issue33237] Improve AttributeError message for partially initialized module

2018-10-30 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e by Serhiy Storchaka in 
branch 'master':
bpo-33237: Improve AttributeError message for partially initialized module. 
(GH-6398)
https://github.com/python/cpython/commit/3e429dcc242e48fa4cbb1a91cf7c416c37b97b4e


--

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-10-20 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Example:

$ cat foo.py
import bar
bar.baz
$ cat bar.py
import foo
baz = 2
$ ./python foo.py 
Traceback (most recent call last):
  File "foo.py", line 1, in 
import bar
  File "/home/serhiy/py/cpython/bar.py", line 1, in 
import foo
  File "/home/serhiy/py/cpython/foo.py", line 2, in 
bar.baz
AttributeError: module 'bar' has no attribute 'baz'

Patched:

$ ./python foo.py 
Traceback (most recent call last):
  File "foo.py", line 1, in 
import bar
  File "/home/serhiy/py/cpython/bar.py", line 1, in 
import foo
  File "/home/serhiy/py/cpython/foo.py", line 2, in 
bar.baz
AttributeError: partially initialized module 'bar' has no attribute 'baz' (most 
likely due to a circular import)

--

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-04-10 Thread Nick Coghlan

Nick Coghlan  added the comment:

The main idea that comes to mind is to cache a reference to 
`_frozen_importlib._module_locks` in the interpreter state, and do a key lookup 
in there (since any in-progress import should have a lock allocated to it).

That would be a separate performance issue though - for this issue, we're on an 
error handling path, so the speed with which the error gets reported isn't 
critical (although it does technically slow down try/except import fallback 
chains).

--

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-04-09 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

I have applied the Nick's suggestion. Needed to find a place for new test.

The code is copied from PyImport_ImportModuleLevelObject(). I'm not happy from 
how verbose it is. And testing mod.__spec__._initialized adds relatively large 
overhead for importing already imported module in 
PyImport_ImportModuleLevelObject(). Is it possible to invent a faster way for 
checking whether the module is partially imported?

--

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-04-07 Thread Nick Coghlan

Nick Coghlan  added the comment:

Oops, just realised my suggested text had an extraneous double quote in it due 
to a copy-and-paste error. Fixed version:

AttributeError: partially initialized module 'spam' has no attribute 'ham' 
(most likely due to a circular import).

--

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-04-07 Thread Brett Cannon

Brett Cannon  added the comment:

+1 from me for Nick's suggestion.

--

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-04-06 Thread Nick Coghlan

Nick Coghlan  added the comment:

While I like the idea of this change, the "partially initialized" addition is 
fairly subtle, and relatively easy to miss.

Perhaps append "(most likely due to a circular import)" to the partially 
initialized case?:

AttributeError: partially initialized "module 'spam' has no attribute 'ham' 
(most likely due to a circular import).

Crucially, for folks encountering the error for the first time, that also 
introduces them to the main phrase they may want to search for: "circular 
import".

The "most likely" weasel wording stems from the fact that the problem won't 
always be with the circular import - they may have just straight up referenced 
the wrong module or the wrong attribute name, so the apparently circular import 
is an error.

--

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-04-06 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +6104
stage:  -> patch review

___
Python tracker 

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



[issue33237] Improve AttributeError message for partially initialized module

2018-04-06 Thread Serhiy Storchaka

New submission from Serhiy Storchaka :

Cyclic import usually leads to an AttributeError "module 'spam' has no 
attribute 'ham'" which usually is confusing because in normal case 'spam.ham' 
exists, and the user can have no ideas why it is disappeared.

The proposed PR allows to specialize the AttributeError message for partially 
initialized module. Any suggestions about the error message?

--
components: Interpreter Core
messages: 315019
nosy: brett.cannon, eric.snow, ncoghlan, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Improve AttributeError message for partially initialized module
type: enhancement
versions: Python 3.8

___
Python tracker 

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