Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
evt_fugx1
dcu_megatron
Commits
e2ce7847
Commit
e2ce7847
authored
Apr 09, 2025
by
dongcl
Browse files
support for removing staticmethod
parent
95f13c48
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
dcu_megatron/adaptor/patch_utils.py
dcu_megatron/adaptor/patch_utils.py
+9
-2
No files found.
dcu_megatron/adaptor/patch_utils.py
View file @
e2ce7847
...
...
@@ -48,8 +48,14 @@ class Patch:
return
id
(
self
.
patch_func_or_cls
)
@
staticmethod
def
remove_wrappers
(
func
):
def
remove_wrappers
(
module
,
func_name
,
func
):
while
True
:
if
(
module
.
__dict__
and
func_name
in
module
.
__dict__
and
isinstance
(
module
.
__dict__
[
func_name
],
(
staticmethod
,
classmethod
))
):
func
=
module
.
__dict__
[
func_name
].
__func__
if
hasattr
(
func
,
'__wrapped__'
)
and
func
.
__wrapped__
is
not
None
:
func
=
func
.
__wrapped__
elif
hasattr
(
func
,
'__closure__'
)
and
func
.
__closure__
is
not
None
:
...
...
@@ -91,7 +97,7 @@ class Patch:
# remove original wrappers
if
self
.
remove_origin_wrappers
:
final_patch_func_or_cls
=
self
.
remove_wrappers
(
final_patch_func_or_cls
)
final_patch_func_or_cls
=
self
.
remove_wrappers
(
self
.
orig_module
,
self
.
orig_func_or_cls_name
,
final_patch_func_or_cls
)
# add new wrappers
for
wrapper
in
self
.
wrappers
:
...
...
@@ -103,6 +109,7 @@ class Patch:
if
self
.
orig_func_or_cls_name
is
not
None
and
hasattr
(
value
,
self
.
orig_func_or_cls_name
)
\
and
id
(
getattr
(
value
,
self
.
orig_func_or_cls_name
))
==
self
.
orig_func_or_cls_id
:
setattr
(
value
,
self
.
orig_func_or_cls_name
,
final_patch_func_or_cls
)
self
.
is_applied
=
True
@
staticmethod
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment