question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect detection of self-documenting f-strings

See original GitHub issue

Describe the bug

False-positives are returned for self-documenting f-strings.

To Reproduce

$ cat /tmp/test.py
a = 1
print(f"Hello world={a}")
$ vermin /tmp/test.py
Minimum required versions: 3.8
Incompatible versions:     2

Expected behavior

Expected the minimum required version for this code to be 3.6. A self-documenting f-string has the equals sign on the other side of the variable (i.e. {a=}).

Environment (please complete the following information):

  • Vermin version 0.9.2

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bulletmarkcommented, May 26, 2020

There are still trivial cases tripping this so please re-open. E.g:

$ cat tmp.py
a = 0
b = 0
print(f'a={a} b={b}')

$ vermin -vv --no-tips tmp.py
Detecting python files..
Analyzing using 4 processes..
!2, 3.8      /home/mark/tmp.py
  f-strings require 3.6+
  print(expr) requires 2+ or 3+
  self-documenting fstrings require 3.8+

Minimum required versions: 3.8
Incompatible versions:     2
1reaction
gousaiyangcommented, Jan 16, 2020

Actually there are more cases (tested on Python 3.8 on your patch just now):

Case 1 f'{ a = }' Expected: detected as 3.8+ Actual: detected as 3.6+ Notes: ASCII whitespaces ([ \t\n\r\f\v]) are allowed before and after the =, and are preserved in the output.

Case 2 f'{a+b=}', f'{a+1=}' Expected: detected as 3.8+ Actual: detected as 3.6+ Notes: However f'{1+a=}' and f'{1+1=}' are detected correctly.

Case 3 f'{(x:=1)}' Expected: detected as 3.8+ Actual: detected as 3.6+ Notes: This is not a “self-documenting f-string”, this is an f-string containing an assignment expression (which is new in 3.8).

Unfortunately, “self-documenting f-string” or “f-string debugging” is poorly documented in the official documentation (I can only find it in whatsnew and changelog). The PR introducing this change contains some useful information (especially the test cases), along with its corresponding issue (contains relevant discussion when introducing this feature, might be a bit noisy because some previous proposals mentioned were rejected).

Read more comments on GitHub >

github_iconTop Results From Across the Web

consider-using-f-string / C0209 - Pylint
Description: Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use...
Read more >
Issue 45086: f-string unmatched ']' - Python tracker
I think the error is short for "I found a ']' without a matching '['". msg400930 - (view), Author: Greg Kuhn (Greg Kuhn),...
Read more >
What does = (equal) do in f-strings inside the expression curly ...
An f-string such as f'{expr=}' will expand to the text of the expression, an equal sign, then the representation of the evaluated expression....
Read more >
Why have I not been using f-strings... : r/Python - Reddit
The problem is that Guido is trying to redefine what pythonic is right in the middle of a major release cycle. That's just...
Read more >
PythonTA Checks
This error occurs when we call strip , lstrip , or rstrip , but pass an argument string which contains duplicate characters. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found