File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -494,6 +494,23 @@ class ObjectSubclass:
494
494
with self .assertRaises (TypeError ):
495
495
proxy [obj ] = 0
496
496
497
+ def test_constructor (self ):
498
+ FrameLocalsProxy = type ([sys ._getframe ().f_locals
499
+ for x in range (1 )][0 ])
500
+ self .assertEqual (FrameLocalsProxy .__name__ , 'FrameLocalsProxy' )
501
+
502
+ def make_frame ():
503
+ x = 1
504
+ y = 2
505
+ return sys ._getframe ()
506
+
507
+ proxy = FrameLocalsProxy (make_frame ())
508
+ self .assertEqual (proxy , {'x' : 1 , 'y' : 2 })
509
+
510
+ # constructor expects 1 argument (frame)
511
+ with self .assertRaises (TypeError ):
512
+ FrameLocalsProxy ()
513
+
497
514
498
515
class FrameLocalsProxyMappingTests (mapping_tests .TestHashMappingProtocol ):
499
516
"""Test that FrameLocalsProxy behaves like a Mapping (with exceptions)"""
Original file line number Diff line number Diff line change @@ -310,6 +310,13 @@ framelocalsproxy_dealloc(PyObject *self)
310
310
static PyObject *
311
311
framelocalsproxy_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
312
312
{
313
+ if (PyTuple_GET_SIZE (args ) != 1 ) {
314
+ PyErr_Format (PyExc_TypeError ,
315
+ "FrameLocalsProxy expected 1 argument, got %zd" ,
316
+ PyTuple_GET_SIZE (args ));
317
+ return NULL ;
318
+ }
319
+
313
320
PyFrameLocalsProxyObject * self = (PyFrameLocalsProxyObject * )type -> tp_alloc (type , 0 );
314
321
if (self == NULL ) {
315
322
return NULL ;
You can’t perform that action at this time.
0 commit comments