@@ -74,6 +74,44 @@ def wrapper(wrapped, instance, args, kwargs):
7474 self .assertEqual (function .__qualname__ , "override_qualname" )
7575 self .assertEqual (instance .__qualname__ , "override_qualname" )
7676
77+ def test_delete_qualname (self ):
78+
79+ @passthru_decorator
80+ def function ():
81+ pass
82+
83+ function .__qualname__ = "override_qualname"
84+
85+ self .assertEqual (function .__qualname__ , "override_qualname" )
86+
87+ # CPython raises TypeError when deleting __qualname__ from a function
88+ # because the C-level setter rejects a NULL value. PyPy raises
89+ # AttributeError instead. Both indicate that deletion is not supported.
90+ self .assertRaises (
91+ (TypeError , AttributeError ), delattr , function , "__qualname__"
92+ )
93+
94+ def test_delete_qualname_modified_on_original (self ):
95+ def function ():
96+ pass
97+
98+ def wrapper (wrapped , instance , args , kwargs ):
99+ return wrapped (* args , ** kwargs )
100+
101+ instance = wrapt .FunctionWrapper (function , wrapper )
102+
103+ instance .__qualname__ = "override_qualname"
104+
105+ self .assertEqual (function .__qualname__ , "override_qualname" )
106+ self .assertEqual (instance .__qualname__ , "override_qualname" )
107+
108+ # CPython raises TypeError when deleting __qualname__ from a function
109+ # because the C-level setter rejects a NULL value. PyPy raises
110+ # AttributeError instead. Both indicate that deletion is not supported.
111+ self .assertRaises (
112+ (TypeError , AttributeError ), delattr , instance , "__qualname__"
113+ )
114+
77115 def test_update_module (self ):
78116 @passthru_decorator
79117 def function ():
@@ -160,6 +198,40 @@ def wrapper(wrapped, instance, args, kwargs):
160198 self .assertEqual (function .__annotations__ , override_annotations )
161199 self .assertEqual (instance .__annotations__ , override_annotations )
162200
201+ def test_delete_annotations (self ):
202+ @passthru_decorator
203+ def function ():
204+ pass
205+
206+ override_annotations = {"override_annotations" : "" }
207+ function .__annotations__ = override_annotations
208+
209+ self .assertEqual (function .__annotations__ , override_annotations )
210+
211+ del function .__annotations__
212+
213+ self .assertEqual (function .__annotations__ , {})
214+
215+ def test_delete_annotations_modified_on_original (self ):
216+ def function ():
217+ pass
218+
219+ def wrapper (wrapped , instance , args , kwargs ):
220+ return wrapped (* args , ** kwargs )
221+
222+ instance = wrapt .FunctionWrapper (function , wrapper )
223+
224+ override_annotations = {"override_annotations" : "" }
225+ instance .__annotations__ = override_annotations
226+
227+ self .assertEqual (function .__annotations__ , override_annotations )
228+ self .assertEqual (instance .__annotations__ , override_annotations )
229+
230+ del instance .__annotations__
231+
232+ self .assertEqual (function .__annotations__ , {})
233+ self .assertEqual (instance .__annotations__ , {})
234+
163235
164236if __name__ == "__main__" :
165237 unittest .main ()
0 commit comments