Comments (7)
@Pierre-Sassoulas I would call useless-f-string
from pylint.
+1 from me. It also seems relatively immune to false positive and simple without looking too much into it. How would you name it ? useless-string
, useless-fstring-formatting
useless-format-string
?
from pylint.
class SneakyString(str):
def __str__(self) -> str:
return "Different string"
x = SneakyString("A")
print(f"{x}" + "B")
print(f"{x:.2}" + "B")
print(x + "B")
I think there is a actually a pretty high chance for false positives as the logic for f-strings is quite difficult to statically imitate.
from pylint.
Not sure what the false positive is in this case @DanielNoord ? Isn't print(f"{x}" + "B")
an actual issue ? As it should be print(str(x) + "B")
to be equivalent (well, print(f"{x}B")
, but this would become hard). I imagine the message raised should be something like Useless f-string, use 'x' or str(x)' instead of 'f"{x}"'.
from pylint.
The false positive is that f"{x}"
isn't the same as x
. f"{x}"
is probably quicker than str(x)
as there is no lookup for the str()
function and thus suggesting str(x)
instead of f"{x}"
is actually not in line with some of our other checks 😅
from pylint.
In [1]: timeit f'{42}'
70 ns ± 1.14 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [2]: timeit str(42)
71.9 ns ± 0.856 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
from pylint.
Right. Still + 0.5 on this, but it's less useful if it become consider-f-string-uselessness
and a convention check, for sure.
from pylint.
Related Issues (20)
- Regression(3.2): matplotlib.widgets.CheckButtons.get_status() is no longer recognized as a list HOT 1
- Crash running pylint from the command line HOT 2
- undefined-variable/possibly-used-before-assignment/used-before-assignment false positives for global
- Fix `possibly-used-before-assignment` issues in our own codebase
- used-before-assignment when variable possibly defined in try, and used in finally HOT 3
- False positive: unused-variable + undefined-variable when using := operator in stacked decorators
- [used-before-assignment] False negative for name defined inside loop that never runs
- `possibly-used-before-assignment` does not understand `assert_never`
- False positive: possibly-used-before-assignment doesn't understand and-ed contions HOT 7
- False positive for *used-before-assignment checkers HOT 2
- False positive: possibly-used-before-assignment and sys.exit() HOT 2
- pylint: disable=invalid-name pragma gets ignored when using ctypes Structure
- `possibly-used-before-assignment` does not handle `match` in nested `if` HOT 1
- False negatives for `duplicate-argument-name`
- False positive `redefined-outer-name` for variables bound to the exception in except clauses HOT 2
- Pylint raises error saying "default" isn't valid for TypeVar
- line-too-long false positive on long comment in function with disable=line-too-long if comment is after all statements
- False positive: `possibly-used-before-assignment` and `pytest.skip` (and other `NoReturn` functions) HOT 10
- Example code in "too-many-ancestors /R0901" documentation incorrectly has platypus as non-egg laying mammals. HOT 1
- Unnecessary cell-var-from-loop HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylint.