Skip to content

Commit

Permalink
make _log_to_history module-level
Browse files Browse the repository at this point in the history
this avoids issue specific to Python 3.9, TypeError: 'staticmethod'
object is not callable (since this method -- now function -- is used as
a decorator)
  • Loading branch information
daler committed Dec 29, 2024
1 parent ebdbfbf commit 9039e05
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions pybedtools/bedtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,42 @@ def wrapped(self, *args, **kwargs):
return decorator


def _log_to_history(method: Callable):
"""
Decorator to add a method and its kwargs to the history.
Assumes that you only add this decorator to bedtool instances that
return other bedtool instances
"""

def decorated(self, *args, **kwargs):

# this calls the actual method in the first place; *result* is
# whatever you get back
result = method(self, *args, **kwargs)

# add appropriate tags
parent_tag = self._tag
result_tag = result._tag

history_step = HistoryStep(
method, args, kwargs, self, parent_tag, result_tag
)

# only add the current history to the new bedtool if there's
# something to add
if len(self.history) > 0:
result.history.append(self.history)

# but either way, add this history step to the result.
result.history.append(history_step)

return result

decorated.__doc__ = method.__doc__
return decorated


class BedTool(object):
TEMPFILES = filenames.TEMPFILES

Expand Down Expand Up @@ -901,43 +937,6 @@ def delete_temporary_history(self, ask: bool = True, raw_input_func=None):
os.unlink(fn)
return

@staticmethod
def _log_to_history(method: Callable):
"""
Decorator to add a method and its kwargs to the history.
Assumes that you only add this decorator to bedtool instances that
return other bedtool instances
"""

def decorated(self, *args, **kwargs):

# this calls the actual method in the first place; *result* is
# whatever you get back
result = method(self, *args, **kwargs)

# add appropriate tags
parent_tag = self._tag
result_tag = result._tag

# log the sucka
history_step = HistoryStep(
method, args, kwargs, self, parent_tag, result_tag
)

# only add the current history to the new bedtool if there's
# something to add
if len(self.history) > 0:
result.history.append(self.history)

# but either way, add this history step to the result.
result.history.append(history_step)

return result

decorated.__doc__ = method.__doc__
return decorated

def filter(self, func: Callable, *args, **kwargs) -> BedTool:
"""
Filter features by user-defined function.
Expand Down

0 comments on commit 9039e05

Please sign in to comment.