Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'functools.partial' object has no attribute '__module__' #1232

Open
bravegag opened this issue Mar 1, 2025 · 2 comments · May be fixed by #1233
Open

AttributeError: 'functools.partial' object has no attribute '__module__' #1232

bravegag opened this issue Mar 1, 2025 · 2 comments · May be fixed by #1233

Comments

@bravegag
Copy link

bravegag commented Mar 1, 2025

I'm using the latest release 0.6.2 on Python 3.9.15 but getting the following stacktrace while running the Backtest, any ideas what's wrong?

Traceback (most recent call last):
...
    from backtesting import Strategy
  File "/opt/dev/myvenv/lib/python3.9/site-packages/backtesting/__init__.py", line 68, in <module>
    from . import lib  # noqa: F401
  File "/opt/dev/myvenv/lib/python3.9/site-packages/backtesting/lib.py", line 28, in <module>
    from .backtesting import Backtest, Strategy
  File "/opt/dev/myvenv/lib/python3.9/site-packages/backtesting/backtesting.py", line 1775, in <module>
    __all__ = [getattr(v, '__name__', k)
  File "/opt/dev/myvenv/lib/python3.9/site-packages/backtesting/backtesting.py", line 1777, in <listcomp>
    if ((callable(v) and v.__module__ == __name__ or     # callables from this module
AttributeError: 'functools.partial' object has no attribute '__module__'
@bravegag
Copy link
Author

bravegag commented Mar 1, 2025

Ok I fixed it by changing the backtesting's backtesting.py and lib.py bottom code to the following (note the new hasattr before just assuming there is a __module__ attribute):

# NOTE: Don't put anything below this __all__ list
__all__ = [getattr(v, '__name__', k)
           for k, v in globals().items()                                                    # export
           if ((callable(v) and (hasattr(v, '__module__') and v.__module__ == __name__) or  # callables from this module
                k.isupper()) and                                                            # or CONSTANTS
               not getattr(v, '__name__', k).startswith('_'))]                              # neither marked internal

# NOTE: Don't put anything below here. See above.

@kernc should I PR this?

@Limfocit
Copy link

Limfocit commented Mar 3, 2025

@bravegag had the same issue, created a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants