Skip to content

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

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

Closed
bravegag opened this issue Mar 1, 2025 · 5 comments · Fixed by #1233
Closed

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

bravegag opened this issue Mar 1, 2025 · 5 comments · Fixed by #1233
Labels
bug Something isn't working

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
Contributor

Limfocit commented Mar 3, 2025

@bravegag had the same issue, created a PR

@kernc
Copy link
Owner

kernc commented Mar 11, 2025

Fixed in master and should be released in a day or two.

May I ask what prevents any of you from upgrading from Python 3.9 to a later version? Its EOL is closing in.

@kernc kernc added the bug Something isn't working label Mar 11, 2025
@Limfocit
Copy link
Contributor

I have 3.10.11 version

@bravegag
Copy link
Author

Fixed in master and should be released in a day or two.

May I ask what prevents any of you from upgrading from Python 3.9 to a later version? Its EOL is closing in.

I just picked a version a long time ago and stuck to it, now upgrading everything to Python 3.12 (stable) and Miniconda 25.1.

I look forward getting profitable backtests :)

kernc added a commit that referenced this issue May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants