Repository: ambv/black
Pull request #663 (2019-01-08 16:36:08)

show how to exclude individual files in the exclude example
It took me about a half hour this morning to puzzle out how to exclude individual files because I didn't realize the example regex excludes only directories. It perhaps took me longer than others since I'm not terribly comfortable with regular expressions but I think this is a common enough desire (to exclude an enumerated list of files along with whole directories) that it should be in the example. Hope you agree :smile:.

coveralls: ## Pull Request Test Coverage Report for [Build 861](https://coveralls.io/builds/20963924)

* **0** of **0**   changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **91.658%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/20963924/badge)](https://coveralls.io/builds/20963924) |
| :-- | --: |
| Change from base [Build 858](https://coveralls.io/builds/20921530): |  0.0% |
| Covered Lines: | 2791 |
| Relevant Lines: | 3045 |

---
##### 💛  - [Coveralls](https://coveralls.io)

coveralls: ## Pull Request Test Coverage Report for [Build 861](https://coveralls.io/builds/20963924)

* **0** of **0**   changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **91.658%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/20963924/badge)](https://coveralls.io/builds/20963924) |
| :-- | --: |
| Change from base [Build 858](https://coveralls.io/builds/20921530): |  0.0% |
| Covered Lines: | 2791 |
| Relevant Lines: | 3045 |

---
##### 💛  - [Coveralls](https://coveralls.io)

coveralls: ## Pull Request Test Coverage Report for [Build 861](https://coveralls.io/builds/20963924)

* **0** of **0**   changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **91.658%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/20963924/badge)](https://coveralls.io/builds/20963924) |
| :-- | --: |
| Change from base [Build 858](https://coveralls.io/builds/20921530): |  0.0% |
| Covered Lines: | 2791 |
| Relevant Lines: | 3045 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml
index 0d43112..c8a8ff0 100644
--- a/.pre-commit-hooks.yaml
+++ b/.pre-commit-hooks.yaml
@@ -4,4 +4,5 @@
     entry: black
     language: python
     language_version: python3
+    require_serial: true
     types: [python]
diff --git a/README.md b/README.md
index c548ce4..9fe9203 100644
--- a/README.md
+++ b/README.md
@@ -572,24 +572,24 @@ line-length = 88
 py36 = true
 include = '\.pyi?$'
 exclude = '''
-/(
-    \.eggs
-  | \.git
-  | \.hg
-  | \.mypy_cache
-  | \.tox
-  | \.venv
-  | _build
-  | buck-out
-  | build
-  | dist
-
-  # The following are specific to Black, you probably don't want those.
-  | blib2to3
-  | tests/data
-)/
+
+(
+  /(
+      \.eggs         # exclude a few common directories in the
+    | \.git          # root of the project
+    | \.hg
+    | \.mypy_cache
+    | \.tox
+    | \.venv
+    | _build
+    | buck-out
+    | build
+    | dist
+  )/
+  | foo.py           # also separately exclude a file named foo.py in
+                     # the root of the project
+)
 '''
-```
 
 </details>
 
diff --git a/black.py b/black.py
index fb8e474..c4b9132 100644
--- a/black.py
+++ b/black.py
@@ -6,7 +6,6 @@
 from functools import lru_cache, partial, wraps
 import io
 import itertools
-import keyword
 import logging
 from multiprocessing import Manager, freeze_support
 import os
@@ -15,6 +14,7 @@
 import re
 import signal
 import sys
+import tempfile
 import tokenize
 from typing import (
     Any,
@@ -777,9 +777,7 @@ def show(cls, code: Union[str, Leaf, Node]) -> None:
         list(v.visit(code))
 
 
-KEYWORDS = set(keyword.kwlist)
 WHITESPACE = {token.DEDENT, token.INDENT, token.NEWLINE}
-FLOW_CONTROL = {"return", "raise", "break", "continue"}
 STATEMENT = {
     syms.if_stmt,
     syms.while_stmt,
@@ -1608,7 +1606,7 @@ def __attrs_post_init__(self) -> None:
 ALWAYS_NO_SPACE = CLOSING_BRACKETS | {token.COMMA, STANDALONE_COMMENT}
 
 
-def whitespace(leaf: Leaf, *, complex_subscript: bool) -> str:  # noqa C901
+def whitespace(leaf: Leaf, *, complex_subscript: bool) -> str:  # noqa: C901
     """Return whitespace prefix if needed for the given `leaf`.
 
     `complex_subscript` signals whether the given leaf is part of a subscription
@@ -3650,11 +3648,11 @@ def write_cache(
     """Update the cache file."""
     cache_file = get_cache_file(line_length, mode)
     try:
-        if not CACHE_DIR.exists():
-            CACHE_DIR.mkdir(parents=True)
+        CACHE_DIR.mkdir(parents=True, exist_ok=True)
         new_cache = {**cache, **{src.resolve(): get_cache_info(src) for src in sources}}
-        with cache_file.open("wb") as fobj:
-            pickle.dump(new_cache, fobj, protocol=pickle.HIGHEST_PROTOCOL)
+        with tempfile.NamedTemporaryFile(dir=str(cache_file.parent), delete=False) as f:
+            pickle.dump(new_cache, f, protocol=pickle.HIGHEST_PROTOCOL)
+        os.replace(f.name, cache_file)
     except OSError:
         pass
 
diff --git a/blib2to3/pgen2/driver.py b/blib2to3/pgen2/driver.py
index 72d9f47..6626c05 100644
--- a/blib2to3/pgen2/driver.py
+++ b/blib2to3/pgen2/driver.py
@@ -131,10 +131,8 @@ def _partially_consume_prefix(self, prefix, column):
                     current_line = ""
                     current_column = 0
                     wait_for_nl = False
-            elif char == ' ':
+            elif char in ' \t':
                 current_column += 1
-            elif char == '\t':
-                current_column += 4
             elif char == '\n':
                 # unexpected empty line
                 current_column = 0
diff --git a/blib2to3/pgen2/grammar.py b/blib2to3/pgen2/grammar.py
index a1da546..b20b923 100644
--- a/blib2to3/pgen2/grammar.py
+++ b/blib2to3/pgen2/grammar.py
@@ -13,7 +13,9 @@
 """
 
 # Python imports
+import os.path
 import pickle
+import tempfile
 
 # Local imports
 from . import token
@@ -86,8 +88,9 @@ def __init__(self):
 
     def dump(self, filename):
         """Dump the grammar tables to a pickle file."""
-        with open(filename, "wb") as f:
+        with tempfile.NamedTemporaryFile(dir=os.path.dirname(filename), delete=False) as f:
             pickle.dump(self.__dict__, f, pickle.HIGHEST_PROTOCOL)
+        os.replace(f.name, filename)
 
     def load(self, filename):
         """Load the grammar tables from a pickle file."""
diff --git a/plugin/black.vim b/plugin/black.vim
index 0a26aa0..34f30c5 100644
--- a/plugin/black.vim
+++ b/plugin/black.vim
@@ -102,6 +102,8 @@ def Black():
   mode = black.FileMode.AUTO_DETECT
   if bool(int(vim.eval("g:black_skip_string_normalization"))):
     mode |= black.FileMode.NO_STRING_NORMALIZATION
+  if vim.current.buffer.name.endswith('.pyi'):
+    mode |= black.FileMode.PYI
   buffer_str = '\n'.join(vim.current.buffer) + '\n'
   try:
     new_buffer_str = black.format_file_contents(buffer_str, line_length=line_length, fast=fast, mode=mode)
diff --git a/readthedocs.yml b/readthedocs.yml
index bd33c28..6f7a677 100644
--- a/readthedocs.yml
+++ b/readthedocs.yml
@@ -1,4 +1,4 @@
-name: jupyterhub
+name: black
 type: sphinx
 conda:
     file: docs/environment.yml


Test patch:
diff --git a/tests/test_black.py b/tests/test_black.py
index 078e8d8..92031ca 100644
--- a/tests/test_black.py
+++ b/tests/test_black.py
@@ -289,7 +289,7 @@ def test_expression_diff(self) -> None:
             msg = (
                 f"Expected diff isn't equal to the actual. If you made changes "
                 f"to expression.py and this is an anticipated difference, "
-                f"overwrite tests/expression.diff with {dump}"
+                f"overwrite tests/data/expression.diff with {dump}"
             )
             self.assertEqual(expected, actual, msg)
 
@@ -509,6 +509,19 @@ def test_bracket_match(self) -> None:
         black.assert_equivalent(source, actual)
         black.assert_stable(source, actual, line_length=ll)
 
+    def test_comment_indentation(self) -> None:
+        contents_tab = "if 1:\n\tif 2:\n\t\tpass\n\t# comment\n\tpass\n"
+        contents_spc = "if 1:\n    if 2:\n        pass\n    # comment\n    pass\n"
+
+        self.assertFormatEqual(fs(contents_spc), contents_spc)
+        self.assertFormatEqual(fs(contents_tab), contents_spc)
+
+        contents_tab = "if 1:\n\tif 2:\n\t\tpass\n\t\t# comment\n\tpass\n"
+        contents_spc = "if 1:\n    if 2:\n        pass\n        # comment\n    pass\n"
+
+        self.assertFormatEqual(fs(contents_tab), contents_spc)
+        self.assertFormatEqual(fs(contents_spc), contents_spc)
+
     def test_report_verbose(self) -> None:
         report = black.Report(verbose=True)
         out_lines = []