Show More
@@ -2841,9 +2841,11 b' class InteractiveShell(SingletonConfigurable):' | |||
|
2841 | 2841 | """ |
|
2842 | 2842 | ns = self.user_ns.copy() |
|
2843 | 2843 | ns.update(sys._getframe(depth+1).f_locals) |
|
2844 | ns.pop('self', None) | |
|
2845 | 2844 | try: |
|
2846 | cmd = formatter.format(cmd, **ns) | |
|
2845 | # We have to use .vformat() here, because 'self' is a valid and common | |
|
2846 | # name, and expanding **ns for .format() would make it collide with | |
|
2847 | # the 'self' argument of the method. | |
|
2848 | cmd = formatter.vformat(cmd, args=[], kwargs=ns) | |
|
2847 | 2849 | except Exception: |
|
2848 | 2850 | # if formatter couldn't format, just let it go untransformed |
|
2849 | 2851 | pass |
@@ -258,6 +258,18 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
258 | 258 | ip.run_cell('makemacro()') |
|
259 | 259 | nt.assert_in('macro_var_expand_locals', ip.user_ns) |
|
260 | 260 | |
|
261 | def test_var_expand_self(self): | |
|
262 | """Test variable expansion with the name 'self', which was failing. | |
|
263 | ||
|
264 | See https://github.com/ipython/ipython/issues/1878#issuecomment-7698218 | |
|
265 | """ | |
|
266 | ip.run_cell('class cTest:\n' | |
|
267 | ' classvar="see me"\n' | |
|
268 | ' def test(self):\n' | |
|
269 | ' res = !echo Variable: {self.classvar}\n' | |
|
270 | ' return res[0]\n') | |
|
271 | nt.assert_in('see me', ip.user_ns['cTest']().test()) | |
|
272 | ||
|
261 | 273 | def test_bad_var_expand(self): |
|
262 | 274 | """var_expand on invalid formats shouldn't raise""" |
|
263 | 275 | # SyntaxError |
General Comments 0
You need to be logged in to leave comments.
Login now