I have a class which has an instance variable of type enum.Flag. It implements __getattr__
so that
i can return the boolean state of a flag given by name.
The code works fine when running without debugging, producing the expected output.
However, when i run it using the Visual Studio Debugger (VS 2019, 16.7.4, Python 3.6, 64-bit), it always stops in the __getattr__
method and i need to continue 100 times until i can continue normally. I have no breakpoint set!
I tested the very same code in IDLE. IDLE does NOT stop in getattr during debugging!
How can i get rid of those annoying false positives disturbing my debug session?
from enum import Flag, auto
from copy import deepcopy
class MyFlags(Flag):
FOO = auto()
BAR = auto()
BAZ = auto()
class Features:
__slots__ = ('_features', )
def __init__(self, bitmask):
self._features = bitmask
@property
def bitmask(self):
return self._features
def __getattr__(self, attr):
try:
return bool(MyFlags[attr].value & self._features)
except:
raise AttributeError(attr)
f = Features(5)
print(f.bitmask)
print(f.FOO)
print(f.BAR)
print(f.BAZ)
f = Features(3)
print(f.bitmask)
print(f.FOO)
print(f.BAR)
print(f.BAZ)
g = deepcopy(f)
print(f.bitmask)
print(f.FOO)
print(f.BAR)
print(f.BAZ)