@@ -5188,58 +5188,51 @@ test_no_setattr_nonnative()
51885188from testutil import assertRaises
51895189
51905190class DelAttr:
5191- __deletable__ = ["regular_attr "]
5191+ __deletable__ = ["del_counter "]
51925192
51935193 _attributes: dict[str, object]
5194- regular_attr : int
5194+ del_counter : int = 0
51955195
5196- def __init__(self, regular_attr: int) -> None:
5197- object.__setattr__(self, "regular_attr", regular_attr)
5196+ def __init__(self) -> None:
51985197 object.__setattr__(self, "_attributes", {})
51995198
52005199 def __setattr__(self, key: str, val: object) -> None:
5201- if key == "regular_attr ":
5202- object.__setattr__(self, key , val)
5200+ if key == "del_counter ":
5201+ object.__setattr__(self, "del_counter" , val)
52035202 else:
52045203 self._attributes[key] = val
52055204
52065205 def __delattr__(self, key: str) -> None:
5207- if key == "regular_attr ":
5208- object.__delattr__( self, "regular_attr")
5206+ if key == "del_counter ":
5207+ self.del_counter += 1
52095208 else:
52105209 del self._attributes[key]
52115210
52125211def test_deletable_attr() -> None:
5213- i = DelAttr(101)
5214- assert i.regular_attr == 101
5215-
5216- del i.regular_attr
5217- with assertRaises(AttributeError):
5218- i.regular_attr
5219-
5220- i.regular_attr = 102
5221- assert i.regular_attr == 102
5212+ i = DelAttr()
5213+ assert i.del_counter == 0
5214+ del i.del_counter
5215+ assert i.del_counter == 1
52225216
52235217[case testDelAttrWithDeletableAttrInterpreted]
52245218class DelAttr:
5225- __deletable__ = ["regular_attr "]
5219+ __deletable__ = ["del_counter "]
52265220
52275221 _attributes: dict[str, object]
5228- regular_attr : int
5222+ del_counter : int = 0
52295223
5230- def __init__(self, regular_attr: int) -> None:
5231- object.__setattr__(self, "regular_attr", regular_attr)
5224+ def __init__(self) -> None:
52325225 object.__setattr__(self, "_attributes", {})
52335226
52345227 def __setattr__(self, key: str, val: object) -> None:
5235- if key == "regular_attr ":
5236- object.__setattr__(self, key , val)
5228+ if key == "del_counter ":
5229+ object.__setattr__(self, "del_counter" , val)
52375230 else:
52385231 self._attributes[key] = val
52395232
52405233 def __delattr__(self, key: str) -> None:
5241- if key == "regular_attr ":
5242- object.__delattr__( self, "regular_attr")
5234+ if key == "del_counter ":
5235+ self.del_counter += 1
52435236 else:
52445237 del self._attributes[key]
52455238
@@ -5248,14 +5241,9 @@ from native import DelAttr
52485241from testutil import assertRaises
52495242
52505243def test_deletable_attr() -> None:
5251- i = DelAttr(101)
5252- assert i.regular_attr == 101
5253-
5254- del i.regular_attr
5255- with assertRaises(AttributeError):
5256- i.regular_attr
5257-
5258- i.regular_attr = 102
5259- assert i.regular_attr == 102
5244+ i = DelAttr()
5245+ assert i.del_counter == 0
5246+ del i.del_counter
5247+ assert i.del_counter == 1
52605248
52615249test_deletable_attr()
0 commit comments