[issue27515] Dotted name re-import does not rebind after deletion

2016-07-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: I understand the reluctance to generically encourage something that does not always arise. With Nick's promise to help examine any particular problems with deletion of tkinter modules, should they arise, I feel comfortable closing this. I already tested and

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-16 Thread Nick Coghlan
Nick Coghlan added the comment: Terry: it's not a 100% guarantee, but it should be sufficient for your purposes (the more obscure failure modes mostly relate to C level globals, Python level module globals, pickling, and module import having side effects on state in other modules, and it's

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: Nick, do I understand correctly that if the reimport executes and I can access the module, everything should be okay? -- ___ Python tracker

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: I am pursuing 1. for 3.6. The first patch, moving 4 objects from pyshell to run and an import from run to pyshell, reduced a bloated len(sys.modules) from 193 to 156. I hope to get under 100. I will test 2., separately for each affected tkinter module, for

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-15 Thread Nick Coghlan
Nick Coghlan added the comment: To fully remove an imported submodule, you also need to purge it from the sys.modules cache: >>> import email.charset; email.charset >>> import sys >>> del email.charset; del sys.modules["email.charset"] >>> import email.charset;

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: Guido: I am aware that 'import tkinter.font' can create 0, 1, or 2 new modules and 0, 1, or 2 new name bindings, one in the *importing* module and one in the *imported* module. You are correct that point 2 in the doc only talks about the importing module,

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: Decorator: as I tried to say in msg270456, the two examples are artificial tests stripped to the bare minimum. So is use of email and charset, other than the fact that it exists in 2.7 as well as current 3.x. The real situation where this issue came up for

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-15 Thread Decorater
Decorater added the comment: I think on the 2nd example they did they got it wrong somewhat. I think this is what they wanted. >>> import email.charset; email.charset >>> del email #to actually delete the whole thing. >>> import email.charset; email.charset -- nosy: +Decorater

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread Guido van Rossum
Guido van Rossum added the comment: Are you sure you realize that "import email.charset" doesn't create a local variable named "email.charset"? It creates a local variable named "email" which happens to have an attribute "charset". The problem with "import pack; print(pack.sub)" being

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread Terry J. Reedy
Terry J. Reedy added the comment: I don't understand the statement that having 'import email.charset' set email.charset is an optional side effect. Without the name setting, the module is inaccessible except through sys.modules, which is not obvious to beginners. To me, making a module

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread R. David Murray
R. David Murray added the comment: So, Guido answered your actual question, and I was confused :( The important point is that email.charset still exists in sys.modules, so import doesn't reload it, and as Guido says module load is the thing that creates the attribute mapping. --

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread Guido van Rossum
Guido van Rossum added the comment: > On the second import, import finds email in sys.modules Actually, it only takes the shortcut because it also finds email.charset in sys.modules. -- ___ Python tracker

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread R. David Murray
R. David Murray added the comment: Heh, actually strike that last sentence. Doing a del doesn't remove the module from sys.modules, so the version of the email module with charset deleted is still there, and doing del email and import email or import email.charset will not change the fact

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread R. David Murray
R. David Murray added the comment: Or, to put it another way, you deleted the charset attribute from the email module. On the second import, import finds email in sys.modules, so it doesn't reimport it, so charset doesn't get recreated. So, the difference is you didn't do 'del email'.

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread Guido van Rossum
Guido van Rossum added the comment: I don't think this is a bug. You're paraphrasing step 2 incorrectly. The local name-binding behavior just creates a local named "email" -- it doesn't concern itself with ensuring that the email package has an attribute "charset". That attribute is set as a

[issue27515] Dotted name re-import does not rebind after deletion

2016-07-14 Thread Terry J. Reedy
New submission from Terry J. Reedy: https://docs.python.org/3/reference/simple_stmts.html#the-import-statement says that import , where can optionally be a dotted name referring to a module within a package, does two things: 1. Find a module object corresponding to , creating it if