I got a very strange behavior, where I can't use global variable as default value if a property has the same name, e.g.:
import datetime as dt
class A:
@property
def dt(self):
return 1
def foo(self, dt_=dt.datetime.min):
print(dt_ > dt.datetime.now())
pass
This gives an error:
Traceback (most recent call last):
File "tmp.py", line 4, in <module>
class A:
File "tmp.py", line 9, in A
def foo(self, dt_=dt.datetime.min):
AttributeError: 'property' object has no attribute 'datetime'
This seems counter-intuitive to me, why would a property override a global variable, but only in default assignment?
dt
works properly inside the method (can check by using a different default value).
What am I missing?
I checked on clean env of 3.8 and 3.10, so it doesn't seem to be a test version issue.
I use python provided by conda
.