Skip to content

Commit

Permalink
disable frozen types when enable_patching
Browse files Browse the repository at this point in the history
Summary:
Disables freezing of types when enable_patching is true.

The most common use case for `enable_patching` is testing, where patching of types may be required (i.e. overriding class properties).

Reviewed By: alexmalyshev

Differential Revision: D64559941

fbshipit-source-id: 095651728be21454d374b3ab145ef74e041e33ab
  • Loading branch information
pilleye authored and facebook-github-bot committed Oct 18, 2024
1 parent 6cf6307 commit c4c34cf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Modules/_cinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "boolobject.h"
#include "cinder/hooks.h"
#include "internal/pycore_shadow_frame.h"
#include "pycore_interp.h"
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "frameobject.h"


Expand Down Expand Up @@ -95,7 +97,12 @@ cinder_freeze_type(PyObject *self, PyObject *o)
);
return NULL;
}
((PyTypeObject*)o)->tp_flags |= Ci_Py_TPFLAGS_FROZEN;

PyInterpreterState *interp = _PyInterpreterState_GET();
assert(interp != NULL);
if (!interp->config.enable_patching) {
((PyTypeObject*)o)->tp_flags |= Ci_Py_TPFLAGS_FROZEN;
}
Py_INCREF(o);
return o;
}
Expand Down

0 comments on commit c4c34cf

Please sign in to comment.