Repository: MartinThoma/flake8-simplify (python)

Issue:
[Adjust rule] Drop SIM105 due to performance
## Desired change

* **Rule(s)**: SIM105
* **Adjustment**: It should be dropped! Or at least highlight performance impact in the documentation!

## Explanation

By conforming to this, the code will perform worse. Please check with `timeit`.

```python
In [1]: %%timeit 
   ...: try: 
   ...:     a = {'a': 1} 
   ...:     a['b'] 
   ...: except KeyError: 
   ...:     pass 
   ...:                                                                                                                                                                                                    
199 ns ± 1.16 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [5]: %%timeit 
   ...: with contextlib.suppress(KeyError): 
   ...:     a = {'a': 1} 
   ...:     a['b'] 
   ...:                                                                                                                                                                                                    
621 ns ± 6.38 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
```

Pull request:
SIM105: Add notice about speed impact in README
Closes #91

Patch:
diff --git a/README.md b/README.md
index d670117..b833707 100644
--- a/README.md
+++ b/README.md
@@ -93,8 +93,11 @@ Current experimental rules:
 
 * `SIM901`: Use comparisons directly instead of wrapping them in a `bool(...)` call ([example](#SIM901))
 
+## Disabling Rules
 
-You might have good reasons to ignore some rules. To do that, use the standard Flake8 configuration. For example, within the `setup.cfg` file:
+You might have good reasons to
+[ignore some flake8 rules](https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html).
+To do that, use the standard Flake8 configuration. For example, within the `setup.cfg` file:
 
 ```python
 [flake8]
@@ -127,6 +130,25 @@ if a and b:
     c
 ```
 
+### SIM105
+
+```python
+# Bad
+try:
+    foo()
+except ValueError:
+    pass
+
+# Good
+from contextlib import suppress
+
+with suppress(ValueError):
+    foo()
+```
+
+Please note that `contextlib.suppress` is roughly 3x slower than `try/except`
+([source](https://github.com/MartinThoma/flake8-simplify/issues/91)).
+
 ### SIM107
 
 ```python
diff --git a/flake8_simplify.py b/flake8_simplify.py
index c6487f3..c2da734 100644
--- a/flake8_simplify.py
+++ b/flake8_simplify.py
@@ -311,6 +311,8 @@ def _get_sim104(node: ast.For) -> List[Tuple[int, int, str]]:
         or node.orelse != []
     ):
         return errors
+    if isinstance(node.parent, ast.AsyncFunctionDef):  # type: ignore
+        return errors
     iterable = to_source(node.iter)
     errors.append(
         (node.lineno, node.col_offset, SIM104.format(iterable=iterable))


Test patch:
diff --git a/tests/test_simplify.py b/tests/test_simplify.py
index bc23a17..b429d04 100644
--- a/tests/test_simplify.py
+++ b/tests/test_simplify.py
@@ -153,6 +153,16 @@ def test_sim104():
     assert ret == {"1:0 SIM104 Use 'yield from iterable'"}
 
 
+def test_s104_async_generator_false_positive():
+    ret = _results(
+        """async def items():
+    for c in 'abc':
+        yield c"""
+    )
+    for el in ret:
+        assert "SIM104" not in el
+
+
 def test_sim105():
     ret = _results(
         """try: