File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1026,6 +1026,28 @@ static int Proxy_set_wrapped(ProxyObject *self,
1026
1026
1027
1027
/* ------------------------------------------------------------------------- */
1028
1028
1029
+ static PyObject * Proxy_get_factory (
1030
+ ProxyObject * self )
1031
+ {
1032
+ Py_INCREF (self -> factory );
1033
+ return self -> factory ;
1034
+ }
1035
+
1036
+ /* ------------------------------------------------------------------------- */
1037
+
1038
+ static int Proxy_set_factory (ProxyObject * self ,
1039
+ PyObject * value )
1040
+ {
1041
+ if (value ) Py_INCREF (value );
1042
+ Py_DECREF (self -> factory );
1043
+
1044
+ self -> factory = value ;
1045
+
1046
+ return 0 ;
1047
+ }
1048
+
1049
+ /* ------------------------------------------------------------------------- */
1050
+
1029
1051
static PyObject * Proxy_getattro (
1030
1052
ProxyObject * self , PyObject * name )
1031
1053
{
@@ -1253,6 +1275,8 @@ static PyGetSetDef Proxy_getset[] = {
1253
1275
(setter )Proxy_set_annotations , 0 },
1254
1276
{ "__wrapped__" , (getter )Proxy_get_wrapped ,
1255
1277
(setter )Proxy_set_wrapped , 0 },
1278
+ { "__factory__" , (getter )Proxy_get_factory ,
1279
+ (setter )Proxy_set_factory , 0 },
1256
1280
{ NULL },
1257
1281
};
1258
1282
Original file line number Diff line number Diff line change @@ -1607,6 +1607,18 @@ def foo():
1607
1607
assert proxy .__factory__ is foo
1608
1608
1609
1609
1610
+ def test_patching_the_factory (lazy_object_proxy ):
1611
+ def foo ():
1612
+ raise AttributeError ("boom!" )
1613
+ proxy = lazy_object_proxy .Proxy (foo )
1614
+ pytest .raises (AttributeError , lambda : proxy .__wrapped__ )
1615
+ assert proxy .__factory__ is foo
1616
+
1617
+ proxy .__factory__ = lambda : foo
1618
+ pytest .raises (AttributeError , proxy )
1619
+ assert proxy .__wrapped__ is foo
1620
+
1621
+
1610
1622
def test_new (lazy_object_proxy ):
1611
1623
a = lazy_object_proxy .Proxy .__new__ (lazy_object_proxy .Proxy )
1612
1624
b = lazy_object_proxy .Proxy .__new__ (lazy_object_proxy .Proxy )
You can’t perform that action at this time.
0 commit comments