Comments (2)
If(
test=Compare(
left=Name(id='a', ctx=Load()),
ops=[Eq()],
comparators=[Constant(value='foo', kind=None)],
),
body=[
Return(
value=Constant(value='bar', kind=None),
),
],
orelse=[
If(
test=Compare(
left=Name(id='a', ctx=Load()),
ops=[Eq()],
comparators=[Constant(value='bar', kind=None)],
),
body=[
Return(
value=Constant(value='baz', kind=None),
),
],
orelse=[
If(
test=Compare(
left=Name(id='a', ctx=Load()),
ops=[Eq()],
comparators=[Constant(value='boo', kind=None)],
),
body=[
Return(
value=Constant(value='ooh', kind=None),
),
],
orelse=[
Return(
value=Constant(value=42, kind=None),
),
],
),
],
),
],
from flake8-simplify.
This style guideline may result in better looking code, but it is inefficient and can even create errors. Each dict value is interpreted whenever the dict is evaluated.
For example:
some_array = [0,1] if x else [0,1,2]
mapping = {
"foo": "bar",
"foo2": long_expensive_function()
"foo3": three_arg_func(some_array[0], some_array[1], some_array[2])
}
return mapping.get("foo",42) # This will still evaluate "foo2", and if x is True, completely crash when evaluating "foo3"
Edit: I created a new issue and referenced this.
from flake8-simplify.
Related Issues (20)
- SIM401 should not apply to non-constant default values
- [Adjust Rule] SIM901 case where bool could be useful
- [New Rule] Merge duplicate startswith / endswith calls HOT 1
- [Adjust Rule] Only emit SIM208 in boolean contexts
- [New Rule]: rewrite dict.get(key, None) as dict.get(key) HOT 2
- [New Rule] Suggest `exist_ok` for `Path.mkdir` and `os.makedirs`
- [Adjust Rule] loosen SIM115 when just opening a file without reference
- SIM118 false positive when using awsglue.dynamicframe.DynamicFrameCollection HOT 1
- [Adjust Rule] missing case with SIM108
- [Adjust Rule] SIM401 False positive, rule too greedy
- Add new release 0.20 with changes at GitHub
- [New Rule] Replace `hasattr` if else with `getattr` when appropiate HOT 1
- [New Rule] AnySequence(dict.keys()) to AnySequence(dict)
- [New Rule] Use set_default in Python dictionaries
- [Adjust Rule] SIM118 - possible issue with objects having a method "keys()"
- [New Rule] Preferring in-place operators
- Usage of deprecated ast nodes
- [Error] Not working with flake8==7.0.0 and Python 3.11.7
- [New Rule] Duplicate blocks in if/else
- [Adjust Rule] SIM 108 and SIM 118 don't cover enough cases as Ruff
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 flake8-simplify.