Repository: asottile/pyupgrade

Issue:
`str()` native literal should be just `''`
https://github.com/asottile/pyupgrade#forced-strnative-literals

```python
str()  # ''
```

Discussion:

Patch:
diff --git a/README.md b/README.md
index cada007..ec67866 100644
--- a/README.md
+++ b/README.md
@@ -181,6 +181,7 @@ Availability:
 - `--py3-plus` is passed on the commandline.
 
 ```python
+str()       # "''"
 str("foo")  # "foo"
 ```
 
diff --git a/pyupgrade.py b/pyupgrade.py
index a51cb50..9bbe886 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -1271,10 +1271,15 @@ class FindPy3Plus(ast.NodeVisitor):
         elif (
                 isinstance(node.func, ast.Name) and
                 node.func.id == 'str' and
-                len(node.args) == 1 and
-                isinstance(node.args[0], ast.Str) and
                 not node.keywords and
-                not _starargs(node)
+                not _starargs(node) and
+                (
+                    len(node.args) == 0 or
+                    (
+                        len(node.args) == 1 and
+                        isinstance(node.args[0], ast.Str)
+                    )
+                )
         ):
             self.native_literals.add(_ast_to_offset(node))
         elif (
@@ -1788,7 +1793,10 @@ def _fix_py3_plus(contents_text):  # type: (str) -> str
             func_args, end = _parse_call_args(tokens, j)
             if any(tok.name == 'NL' for tok in tokens[i:end]):
                 continue
-            _replace_call(tokens, i, end, func_args, '{args[0]}')
+            if func_args:
+                _replace_call(tokens, i, end, func_args, '{args[0]}')
+            else:
+                tokens[i:end] = [token._replace(name='STRING', src="''")]
         elif token.offset in visitor.simple_ids:
             tokens[i] = Token(
                 token.name,


Test patch:
diff --git a/tests/native_literals_test.py b/tests/native_literals_test.py
index a894e2d..a82820a 100644
--- a/tests/native_literals_test.py
+++ b/tests/native_literals_test.py
@@ -24,6 +24,7 @@ def test_fix_native_literals_noop(s):
 @pytest.mark.parametrize(
     ('s', 'expected'),
     (
+        ('str()', "''"),
         ('str("foo")', '"foo"'),
         ('str("""\nfoo""")', '"""\nfoo"""'),
     ),