Commits

Tyler Wade  committed bcac3e9

Make changing sys.flag.optimize in pyinteractive.py cleaner

  • Participants
  • Parent commits 5e679b2

Comments (0)

Files changed (2)

File pypy/bin/pyinteractive.py

 
     space = option.make_objspace(config)
 
-    if interactiveconfig.optimize:
-        flags_w = space.sys.get('flags').getitems_copy()
-        #change optimize flag's value
-        import pdb; pdb.set_trace()
-        flags_w[6] = space.wrap(2)
-        w_flags = type(space.sys.get('flags'))(flags_w)
-        w_flags.user_setup(space, space.sys.get('flags').w__class__)
-        space.sys.w_dict.setitem(space.wrap('flags'), w_flags)
-
     space._starttime = starttime
     space.setitem(space.sys.w_dict, space.wrap('executable'),
                   space.wrap(argv[0]))
 
+    if interactiveconfig.optimize:
+        flags_w = space.sys.get('flags').getitems_copy()
+        #change the optimize flag's value
+        flags_w[6] = space.wrap(2)
+        space.appexec([space.wrap(flags_w)], """(flags):
+            import sys
+            sys.flags = type(sys.flags)(flags)
+        """)
+
     # call pypy_find_stdlib: the side-effect is that it sets sys.prefix and
     # sys.exec_prefix
     executable = argv[0]

File pypy/interpreter/astcompiler/test/test_compiler.py

         w_saved_flags = space.sys.get('flags')
         flags_w = space.sys.get('flags').getitems_copy()
         flags_w[6] = space.wrap(1)
-        w_flags = type(space.sys.get('flags'))(flags_w)
-        w_flags.user_setup(space, w_saved_flags.w__class__)
-        space.sys.w_dict.setitem(space.wrap('flags'), w_flags)
+        space.appexec([space.wrap(flags_w)], """(flags):
+            import sys
+            sys.flags = type(sys.flags)(flags)
+        """)
+
         try:
             self.run(source)
         finally: