[pywin32-bugs] [ pywin32-Patches-3438431 ] ImportFile (Ctrl-I) iter bug
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2011-11-16 10:40:53
|
Patches item #3438431, was opened at 2011-11-15 10:42 Message generated for change (Comment added) made by kxroberto You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551956&aid=3438431&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: kxroberto (kxroberto) Assigned to: Nobody/Anonymous (nobody) Summary: ImportFile (Ctrl-I) iter bug Initial Comment: diff -ur --strip _orig/scriptutils.py ./scriptutils.py --- _orig/scriptutils.py 2010-08-25 17:46:40 +0000 +++ ./scriptutils.py 2011-11-15 18:37:26 +0000 @@ -391,7 +391,7 @@ path, modName = os.path.split(pathName) modName, modExt = os.path.splitext(modName) newPath = None - for key, mod in sys.modules.iteritems(): + for key, mod in list(sys.modules.iteritems()): if hasattr(mod, '__file__'): fname = mod.__file__ base, ext = os.path.splitext(fname) solves: Ctrl-I / FileImport: >>> Traceback (most recent call last): File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\intpyapp.py", line 330, in OnFileImport scriptutils.ImportFile() File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 394, in ImportFile for key, mod in sys.modules.iteritems(): RuntimeError: dictionary changed size during iteration win32ui.error: Error in Command Message handler for command ID 36867, Code 0 Note: in pure Python2 "sys.modules.iteritems()" would be ok. But for 2to3 the list(sys.modules.iteritems()) should be consistent ---------------------------------------------------------------------- >Comment By: kxroberto (kxroberto) Date: 2011-11-16 02:40 Message: well, I do not completely understand the comment and 2to3 and if/how its used for pywin32 (auto-)maintenance ;-) (I don't really use Py3 except a raw one for esoteric fun tests. The problems start with my fingers not wanting to type all those extra braces for the many print statements ...). Isn't the problem that Py3 has only .items() but that behaves (oversmart & intransparently) like Py2's .iteritems(). Thus the problem of iteration over a dicts items while the dict itself changes, remains. But 2to3 I guess (?) doesn't auto-translate d.items() to list(d.items()) ? If so I see no other possib than "list(sys.modules.iteritems())" to trick it for working universal. C:\Python23\Lib>python32 Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. File "C:\bin\pythonrc.py", line 19 print "-------------- First: PRESS ENTER 2x in GDB! -------------" ^ SyntaxError: invalid syntax >>> d={2:3,5:6} >>> d.items <built-in method items of dict object at 0x00B25930> >>> d.iteritems Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'dict' object has no attribute 'iteritems' >>> for x in d.keys(): del d[x] ... Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: dictionary changed size during iteration >>> for x in list(d.keys()): del d[x] ... >>> >>> ---------------------------------------------------------------------- Comment By: Mark Hammond (mhammond) Date: 2011-11-16 01:46 Message: oops - just saw your comment :) I admit I like the items() version better as it is more "consistent" WRT other existing code - the fact that 2to3 changes it is actually a feature ---------------------------------------------------------------------- Comment By: Mark Hammond (mhammond) Date: 2011-11-16 01:44 Message: Wouldt sys,modules.items() be even better? ---------------------------------------------------------------------- Comment By: kxroberto (kxroberto) Date: 2011-11-15 10:46 Message: Note: in pure Python2 "sys.modules.items()" would be ok. But for 2to3 the list(sys.modules.iteritems()) should be consistent ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551956&aid=3438431&group_id=78018 |