Skip to content

Commit

Permalink
Merge pull request #6 from ken-morel/dev
Browse files Browse the repository at this point in the history
Fix overriding self error in comberloaders call when using with pyoload
  • Loading branch information
ken-morel authored Jul 29, 2024
2 parents 977e6a7 + 5d280c1 commit e6d832f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def first():
pass

@first.fail
def second(e):
pass
def second():
print(first.error)
```

## failback
Expand All @@ -101,7 +101,7 @@ def first():
pass

@first.failback
def second(e=None): # e will be passed if module fails to load
def second():
pass
```
# callbacks
Expand Down
12 changes: 6 additions & 6 deletions src/comberload.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import functools
import sys

from functools import wraps
Expand Down Expand Up @@ -32,7 +31,7 @@ def fallback_get_input():
"""

__version__ = "1.1.1"
__version__ = "1.1.2"
worker_running = False
should_work = True
backlog = []
Expand Down Expand Up @@ -68,14 +67,14 @@ def __init__(self, modules: list[str], func: Callable):
self.comberloaded = False
wraps(func)(self)

def call(self, *args, **kw):
def call(__comberloaded_special__self, *args, **kw):
"""
The default call for comberloaded instance, calla the
fallback if given, else returns None
"""
if self._fallback is None:
if __comberloaded_special__self._fallback is None:
return None
return self._fallback(*args, **kw)
return __comberloaded_special__self._fallback(*args, **kw)

def fallback(self, func: Callable):
"""
Expand Down Expand Up @@ -204,7 +203,8 @@ def _worker(self):
if len(set(self.failed) & set(loader.modules)) > 0:
loader.comberloaded = False
loader.failed = True
loader.call = functools.partial(loader._fail, e)
loader.call = loader._fail
loader.error = e
else:
if module in self.backlog:
self.backlog.remove(module)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_comberload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def test_comberload():
import comberload

assert comberload.__version__ == "1.1.1"
assert comberload.__version__ == "1.1.2"

@comberload("sys")
def foo():
Expand Down

0 comments on commit e6d832f

Please sign in to comment.