ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

f-string: unmatched '(' when importing yfinance #2093

Open FX196 opened 1 month ago

FX196 commented 1 month ago

Describe bug

Syntax error in screener with Python 3.10. Error is coming from https://github.com/ranaroussi/yfinance/blob/main/yfinance/screener/screener.py#L101

Simple code that reproduces your problem

import yfinance

using Python 3.10

Debug log

No debug logs but have stack trace of the import error

Traceback (most recent call last):
  File "/home/runner/work/.../libs.py", line 2, in <module>
    import yfinance as yf
  File "/home/runner/work/.../venv/lib/python3.10/site-packages/yfinance/__init__.py", line 30, in <module>
    from .screener.screener import Screener
  File "/home/runner/work/.../venv/lib/python3.10/site-packages/yfinance/screener/__init__.py", line 1, in <module>
    from .screener import Screener
  File "/home/runner/work/.../venv/lib/python3.10/site-packages/yfinance/screener/screener.py", line 101
    logger.error(f"Failed to get screener data for '{self._body.get('query', "query not set")}' reason: {e}")
                                                                              ^^^^^
SyntaxError: f-string: unmatched '('
Error: Process completed with exit code 1.

Bad data proof

No response

yfinance version

0.2.45

Python version

3.10

Operating system

No response

sing-tam commented 1 month ago

same issue here, need to install previous version to resolve the issue

mrimahajan commented 1 month ago

Can we take some action on this asap. This is impacting the daily production jobs for us.

FX196 commented 1 month ago

Can we take some action on this asap. This is impacting the daily production jobs for us.

@mrimahajan you can pin your version to the previous release by changing your requirements.txt to say yfinance==0.2.44. That's what I did to fix mine

ValueRaider commented 1 month ago

I'm confused how from .screener import Screener is causing Screener._fetch_and_parse() to execute. It shouldn't be executing on import. I can't reproduce (Linux + Python 3.12).

@ericpien

fled-dev commented 1 month ago

Same issue

System Details

mm3509 commented 1 month ago

Same problem here, and this bug arises during import.

ericpien commented 1 month ago

I was able to reproduce by testing on Python 3.11, while it was not reproducible in my dev environment (Mac + Python 3.12). It must be related to https://docs.python.org/3/whatsnew/3.12.html#pep-701-syntactic-formalization-of-f-strings in which Quote reuse was enabled for f-strings in 3.12.

But it's bad code anyway - sorry for the inconvenience. Thanks @FX196 for the fix!

srepollock commented 1 month ago

The fix has been merged in. Is a new release being created?

ValueRaider commented 1 month ago

Fix merged and released.

Is there a simple action/workflow we can add to avoid a repeat? Ideally not running all the unit tests because that involves dozens of fetches.

vwbusguy commented 1 month ago

The updated release fixed this for our builds. Many thanks to everyone for the quick report, PR, testing, and merge! This was a textbook example of open source community awesomeness.