[issue43380] Assigning function parameter to class attribute by the same name

jennydaman report at bugs.python.org
Tue Mar 2 20:22:53 EST 2021


jennydaman <jdmzh+python at protonmail.com> added the comment:

# Example

Consider these three examples, which are theoretically identical

```
a = 4

class A:
    a = a

print(A.a)

def createB(b):
    class B:
        z = b
    print(B.z)
    
createB(5)

def createD(d):
    class D:
        d = d
    print(D.d)
    
createD(6)
```

## Expected Output

```
4
5
6
```

## Actual Output

```
4
5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in createD
  File "<stdin>", line 3, in D
NameError: name 'd' is not defined
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43380>
_______________________________________


More information about the Python-bugs-list mailing list