This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ppperry
Recipients ppperry
Date 2018-01-21.23:46:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1516578386.14.0.467229070634.issue32615@psf.upfronthosting.co.za>
In-reply-to
Content
Take the following code:

    import builtins
    class K(dict):
	def __getitem__(self, k):
		if k not in builtins.__dict__:
			print("get %s" % k)
		return dict.__getitem__(self, k)
	def __setitem__(self, k, v):
		print("set %s" % k)
		dict.__setitem__(self, k, v)
    exec("""
        foo = "bar"
        foo
        try:
            qyz
        except NameError:
	    pass
        class K:
	    baz = foo
	    def f(ggg=foo): pass
        def g(ggg=foo):
	    global f
	    f = 87
            f
        g()
    """,K())

This should consitently either call or not call the overridden methods on the dictionary, producing either no output or:

    set foo
    get foo
    get qyz
    get foo
    get foo
    set K
    get foo
    set g
    get g
    set f
    get f
    
Instead, only sometime the override gets called, producing

    set foo
    get foo
    get qyz
    set K
    get foo
    set g
    get g
    get f

meaning that 
    (a) modifications of global variables via global statements
    (b) code at class-level

ignore overridden methods, whereas everything else follows them
History
Date User Action Args
2018-01-21 23:46:26ppperrysetrecipients: + ppperry
2018-01-21 23:46:26ppperrysetmessageid: <1516578386.14.0.467229070634.issue32615@psf.upfronthosting.co.za>
2018-01-21 23:46:26ppperrylinkissue32615 messages
2018-01-21 23:46:25ppperrycreate