[New-bugs-announce] [issue43380] Assigning function parameter to class attribute by the same name

jennydaman report at bugs.python.org
Tue Mar 2 19:36:29 EST 2021


New submission from jennydaman <jdmzh+python at protonmail.com>:

# 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
```

----------
components: Interpreter Core
messages: 387987
nosy: jennydaman
priority: normal
severity: normal
status: open
title: Assigning function parameter to class attribute by the same name
type: behavior
versions: Python 3.10, Python 3.9

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


More information about the New-bugs-announce mailing list