[issue40249] __import__ doesn't honour globals

2020-04-15 Thread Brett Cannon


Brett Cannon  added the comment:

Algorithm is documented as part of the language reference: 
https://docs.python.org/3/reference/import.html

--

___
Python tracker 

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



[issue40249] __import__ doesn't honour globals

2020-04-14 Thread Stefan Seefeld


Stefan Seefeld  added the comment:

I'm not entirely sure, but have to admit that the sentence

"The function imports the module name, potentially using the given globals and 
locals to determine how to interpret the name in a package context."

is a bit obscure. What does "determine how to interpret the name" actually mean 
? Is the algorithm described anywhere in detail ? In that case, a simple 
reference might be enough.

--

___
Python tracker 

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



[issue40249] __import__ doesn't honour globals

2020-04-14 Thread Brett Cannon


Brett Cannon  added the comment:

How would you propose changing the wording found at 
https://docs.python.org/3/library/functions.html?highlight=__import__#__import__?

--
nosy: +brett.cannon

___
Python tracker 

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



[issue40249] __import__ doesn't honour globals

2020-04-10 Thread Stefan Seefeld


Stefan Seefeld  added the comment:

OK, thanks for the clarification. I think this is obscure enough to warrant at 
least a paragraph or two to clarify the semantics of these arguments.
I changed the issue "components" and "type" to reflect that.

--
assignee:  -> docs@python
components: +Documentation -Interpreter Core
nosy: +docs@python
type: behavior -> enhancement

___
Python tracker 

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



[issue40249] __import__ doesn't honour globals

2020-04-10 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

globals is only used when level > 0, to resolve relative names like in `import 
..foo`. You have to set keys __package__ and __spec__ or __name__ and __path__ 
in this case.

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue40249] __import__ doesn't honour globals

2020-04-10 Thread Stefan Seefeld


New submission from Stefan Seefeld :

I'm trying to import custom scripts that expect the presence of certain 
variables in the global namespace.
It seems `__import__('script', globals=dict(foo='bar'))` doesn't have the 
expected effect of injecting "foo" into the namespace and making it accessible 
to the script being loaded.

Is this a bug in `__import__` or am I missing something ? If the behaviour is 
expected, how can I achieve the desired behaviour ?

--
components: Interpreter Core
messages: 366160
nosy: stefan
priority: normal
severity: normal
status: open
title: __import__ doesn't honour globals
type: behavior
versions: Python 3.6

___
Python tracker 

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