We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Changes to files happing quickly after running `black` are not detected
**Describe the bug**

It seems `black` does not detect that a file has been changed and needs to be re-checked, if the change happens quickly after `black` has been run on the file.

I'm talking about this feature: [Ignoring unmodified files](https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#ignoring-unmodified-files)

**To Reproduce**

I'm using the following shell script to reproduce the issue:

```bash
#! /usr/bin/env bash

set -eux

echo 'print (1)' > file.py
black file.py
echo 'print ()' > file.py
black file.py
cat file.py
```

The script writes overwrites the file and then runs `black`, doing this twice in a row. In the second run, `black` should reformat `print ()` to `print()`, but this does not happen:

```
$ ./bug.sh 
+ echo 'print (1)'
+ black file.py
reformatted file.py

All done! ✨ 🍰 ✨
1 file reformatted.
+ echo 'print ()'
+ black file.py
All done! ✨ 🍰 ✨
1 file left unchanged.
+ cat file.py
print ()
```

Even running it manually after a few seconds does not fix the issue, but removing the cache directory does:

```
$ black file.py
All done! ✨ 🍰 ✨
1 file left unchanged.
$ cat file.py
print ()
$ rm -r ~/Library/Caches/black/
$ black file.py
reformatted file.py

All done! ✨ 🍰 ✨
1 file reformatted.
$ cat file.py
print()
```

**Expected behavior**

I think black should not get confused by changes to files that happen quickly after it has formatted a file. The file should be checked again if it is possible that its content has changed without also changing its timestamp.

**Environment**

- Black's version:

    ```
    $ black --version
    black, 23.12.0 (compiled: yes)
    Python (CPython) 3.11.6
    ```

- OS and Python version: macOS 12.7.1, Python 3.11.6 installed via Homebrew.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/black/cache.py`
Content:
```
1 """Caching of formatted files with feature-based invalidation."""
2 
3 import hashlib
4 import os
5 import pickle
6 import sys
7 import tempfile
8 from dataclasses import dataclass, field
9 from pathlib import Path
10 from typing import Dict, Iterable, NamedTuple, Set, Tuple
11 
12 from platformdirs import user_cache_dir
13 
14 from _black_version import version as __version__
15 from black.mode import Mode
16 
17 if sys.version_info >= (3, 11):
18     from typing import Self
19 else:
20     from typing_extensions import Self
21 
22 
23 class FileData(NamedTuple):
24     st_mtime: float
25     st_size: int
26     hash: str
27 
28 
29 def get_cache_dir() -> Path:
30     """Get the cache directory used by black.
31 
32     Users can customize this directory on all systems using `BLACK_CACHE_DIR`
33     environment variable. By default, the cache directory is the user cache directory
34     under the black application.
35 
36     This result is immediately set to a constant `black.cache.CACHE_DIR` as to avoid
37     repeated calls.
38     """
39     # NOTE: Function mostly exists as a clean way to test getting the cache directory.
40     default_cache_dir = user_cache_dir("black")
41     cache_dir = Path(os.environ.get("BLACK_CACHE_DIR", default_cache_dir))
42     cache_dir = cache_dir / __version__
43     return cache_dir
44 
45 
46 CACHE_DIR = get_cache_dir()
47 
48 
49 def get_cache_file(mode: Mode) -> Path:
50     return CACHE_DIR / f"cache.{mode.get_cache_key()}.pickle"
51 
52 
53 @dataclass
54 class Cache:
55     mode: Mode
56     cache_file: Path
57     file_data: Dict[str, FileData] = field(default_factory=dict)
58 
59     @classmethod
60     def read(cls, mode: Mode) -> Self:
61         """Read the cache if it exists and is well formed.
62 
63         If it is not well formed, the call to write later should
64         resolve the issue.
65         """
66         cache_file = get_cache_file(mode)
67         if not cache_file.exists():
68             return cls(mode, cache_file)
69 
70         with cache_file.open("rb") as fobj:
71             try:
72                 data: Dict[str, Tuple[float, int, str]] = pickle.load(fobj)
73                 file_data = {k: FileData(*v) for k, v in data.items()}
74             except (pickle.UnpicklingError, ValueError, IndexError):
75                 return cls(mode, cache_file)
76 
77         return cls(mode, cache_file, file_data)
78 
79     @staticmethod
80     def hash_digest(path: Path) -> str:
81         """Return hash digest for path."""
82 
83         data = path.read_bytes()
84         return hashlib.sha256(data).hexdigest()
85 
86     @staticmethod
87     def get_file_data(path: Path) -> FileData:
88         """Return file data for path."""
89 
90         stat = path.stat()
91         hash = Cache.hash_digest(path)
92         return FileData(stat.st_mtime, stat.st_size, hash)
93 
94     def is_changed(self, source: Path) -> bool:
95         """Check if source has changed compared to cached version."""
96         res_src = source.resolve()
97         old = self.file_data.get(str(res_src))
98         if old is None:
99             return True
100 
101         st = res_src.stat()
102         if st.st_size != old.st_size:
103             return True
104         if int(st.st_mtime) != int(old.st_mtime):
105             new_hash = Cache.hash_digest(res_src)
106             if new_hash != old.hash:
107                 return True
108         return False
109 
110     def filtered_cached(self, sources: Iterable[Path]) -> Tuple[Set[Path], Set[Path]]:
111         """Split an iterable of paths in `sources` into two sets.
112 
113         The first contains paths of files that modified on disk or are not in the
114         cache. The other contains paths to non-modified files.
115         """
116         changed: Set[Path] = set()
117         done: Set[Path] = set()
118         for src in sources:
119             if self.is_changed(src):
120                 changed.add(src)
121             else:
122                 done.add(src)
123         return changed, done
124 
125     def write(self, sources: Iterable[Path]) -> None:
126         """Update the cache file data and write a new cache file."""
127         self.file_data.update(
128             **{str(src.resolve()): Cache.get_file_data(src) for src in sources}
129         )
130         try:
131             CACHE_DIR.mkdir(parents=True, exist_ok=True)
132             with tempfile.NamedTemporaryFile(
133                 dir=str(self.cache_file.parent), delete=False
134             ) as f:
135                 # We store raw tuples in the cache because pickling NamedTuples
136                 # doesn't work with mypyc on Python 3.8, and because it's faster.
137                 data: Dict[str, Tuple[float, int, str]] = {
138                     k: (*v,) for k, v in self.file_data.items()
139                 }
140                 pickle.dump(data, f, protocol=4)
141             os.replace(f.name, self.cache_file)
142         except OSError:
143             pass
144
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/black/cache.py b/src/black/cache.py
--- a/src/black/cache.py
+++ b/src/black/cache.py
@@ -101,7 +101,7 @@
         st = res_src.stat()
         if st.st_size != old.st_size:
             return True
-        if int(st.st_mtime) != int(old.st_mtime):
+        if st.st_mtime != old.st_mtime:
             new_hash = Cache.hash_digest(res_src)
             if new_hash != old.hash:
                 return True

{"golden_diff": "diff --git a/src/black/cache.py b/src/black/cache.py\n--- a/src/black/cache.py\n+++ b/src/black/cache.py\n@@ -101,7 +101,7 @@\n         st = res_src.stat()\n         if st.st_size != old.st_size:\n             return True\n-        if int(st.st_mtime) != int(old.st_mtime):\n+        if st.st_mtime != old.st_mtime:\n             new_hash = Cache.hash_digest(res_src)\n             if new_hash != old.hash:\n                 return True\n", "issue": "Changes to files happing quickly after running `black` are not detected\n**Describe the bug**\r\n\r\nIt seems `black` does not detect that a file has been changed and needs to be re-checked, if the change happens quickly after `black` has been run on the file.\r\n\r\nI'm talking about this feature: [Ignoring unmodified files](https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#ignoring-unmodified-files)\r\n\r\n**To Reproduce**\r\n\r\nI'm using the following shell script to reproduce the issue:\r\n\r\n```bash\r\n#! /usr/bin/env bash\r\n\r\nset -eux\r\n\r\necho 'print (1)' > file.py\r\nblack file.py\r\necho 'print ()' > file.py\r\nblack file.py\r\ncat file.py\r\n```\r\n\r\nThe script writes overwrites the file and then runs `black`, doing this twice in a row. In the second run, `black` should reformat `print ()` to `print()`, but this does not happen:\r\n\r\n```\r\n$ ./bug.sh \r\n+ echo 'print (1)'\r\n+ black file.py\r\nreformatted file.py\r\n\r\nAll done! \u2728 \ud83c\udf70 \u2728\r\n1 file reformatted.\r\n+ echo 'print ()'\r\n+ black file.py\r\nAll done! \u2728 \ud83c\udf70 \u2728\r\n1 file left unchanged.\r\n+ cat file.py\r\nprint ()\r\n```\r\n\r\nEven running it manually after a few seconds does not fix the issue, but removing the cache directory does:\r\n\r\n```\r\n$ black file.py\r\nAll done! \u2728 \ud83c\udf70 \u2728\r\n1 file left unchanged.\r\n$ cat file.py\r\nprint ()\r\n$ rm -r ~/Library/Caches/black/\r\n$ black file.py\r\nreformatted file.py\r\n\r\nAll done! \u2728 \ud83c\udf70 \u2728\r\n1 file reformatted.\r\n$ cat file.py\r\nprint()\r\n```\r\n\r\n**Expected behavior**\r\n\r\nI think black should not get confused by changes to files that happen quickly after it has formatted a file. The file should be checked again if it is possible that its content has changed without also changing its timestamp.\r\n\r\n**Environment**\r\n\r\n- Black's version:\r\n\r\n    ```\r\n    $ black --version\r\n    black, 23.12.0 (compiled: yes)\r\n    Python (CPython) 3.11.6\r\n    ```\r\n\r\n- OS and Python version: macOS 12.7.1, Python 3.11.6 installed via Homebrew.\n", "before_files": [{"content": "\"\"\"Caching of formatted files with feature-based invalidation.\"\"\"\n\nimport hashlib\nimport os\nimport pickle\nimport sys\nimport tempfile\nfrom dataclasses import dataclass, field\nfrom pathlib import Path\nfrom typing import Dict, Iterable, NamedTuple, Set, Tuple\n\nfrom platformdirs import user_cache_dir\n\nfrom _black_version import version as __version__\nfrom black.mode import Mode\n\nif sys.version_info >= (3, 11):\n    from typing import Self\nelse:\n    from typing_extensions import Self\n\n\nclass FileData(NamedTuple):\n    st_mtime: float\n    st_size: int\n    hash: str\n\n\ndef get_cache_dir() -> Path:\n    \"\"\"Get the cache directory used by black.\n\n    Users can customize this directory on all systems using `BLACK_CACHE_DIR`\n    environment variable. By default, the cache directory is the user cache directory\n    under the black application.\n\n    This result is immediately set to a constant `black.cache.CACHE_DIR` as to avoid\n    repeated calls.\n    \"\"\"\n    # NOTE: Function mostly exists as a clean way to test getting the cache directory.\n    default_cache_dir = user_cache_dir(\"black\")\n    cache_dir = Path(os.environ.get(\"BLACK_CACHE_DIR\", default_cache_dir))\n    cache_dir = cache_dir / __version__\n    return cache_dir\n\n\nCACHE_DIR = get_cache_dir()\n\n\ndef get_cache_file(mode: Mode) -> Path:\n    return CACHE_DIR / f\"cache.{mode.get_cache_key()}.pickle\"\n\n\n@dataclass\nclass Cache:\n    mode: Mode\n    cache_file: Path\n    file_data: Dict[str, FileData] = field(default_factory=dict)\n\n    @classmethod\n    def read(cls, mode: Mode) -> Self:\n        \"\"\"Read the cache if it exists and is well formed.\n\n        If it is not well formed, the call to write later should\n        resolve the issue.\n        \"\"\"\n        cache_file = get_cache_file(mode)\n        if not cache_file.exists():\n            return cls(mode, cache_file)\n\n        with cache_file.open(\"rb\") as fobj:\n            try:\n                data: Dict[str, Tuple[float, int, str]] = pickle.load(fobj)\n                file_data = {k: FileData(*v) for k, v in data.items()}\n            except (pickle.UnpicklingError, ValueError, IndexError):\n                return cls(mode, cache_file)\n\n        return cls(mode, cache_file, file_data)\n\n    @staticmethod\n    def hash_digest(path: Path) -> str:\n        \"\"\"Return hash digest for path.\"\"\"\n\n        data = path.read_bytes()\n        return hashlib.sha256(data).hexdigest()\n\n    @staticmethod\n    def get_file_data(path: Path) -> FileData:\n        \"\"\"Return file data for path.\"\"\"\n\n        stat = path.stat()\n        hash = Cache.hash_digest(path)\n        return FileData(stat.st_mtime, stat.st_size, hash)\n\n    def is_changed(self, source: Path) -> bool:\n        \"\"\"Check if source has changed compared to cached version.\"\"\"\n        res_src = source.resolve()\n        old = self.file_data.get(str(res_src))\n        if old is None:\n            return True\n\n        st = res_src.stat()\n        if st.st_size != old.st_size:\n            return True\n        if int(st.st_mtime) != int(old.st_mtime):\n            new_hash = Cache.hash_digest(res_src)\n            if new_hash != old.hash:\n                return True\n        return False\n\n    def filtered_cached(self, sources: Iterable[Path]) -> Tuple[Set[Path], Set[Path]]:\n        \"\"\"Split an iterable of paths in `sources` into two sets.\n\n        The first contains paths of files that modified on disk or are not in the\n        cache. The other contains paths to non-modified files.\n        \"\"\"\n        changed: Set[Path] = set()\n        done: Set[Path] = set()\n        for src in sources:\n            if self.is_changed(src):\n                changed.add(src)\n            else:\n                done.add(src)\n        return changed, done\n\n    def write(self, sources: Iterable[Path]) -> None:\n        \"\"\"Update the cache file data and write a new cache file.\"\"\"\n        self.file_data.update(\n            **{str(src.resolve()): Cache.get_file_data(src) for src in sources}\n        )\n        try:\n            CACHE_DIR.mkdir(parents=True, exist_ok=True)\n            with tempfile.NamedTemporaryFile(\n                dir=str(self.cache_file.parent), delete=False\n            ) as f:\n                # We store raw tuples in the cache because pickling NamedTuples\n                # doesn't work with mypyc on Python 3.8, and because it's faster.\n                data: Dict[str, Tuple[float, int, str]] = {\n                    k: (*v,) for k, v in self.file_data.items()\n                }\n                pickle.dump(data, f, protocol=4)\n            os.replace(f.name, self.cache_file)\n        except OSError:\n            pass\n", "path": "src/black/cache.py"}], "after_files": [{"content": "\"\"\"Caching of formatted files with feature-based invalidation.\"\"\"\n\nimport hashlib\nimport os\nimport pickle\nimport sys\nimport tempfile\nfrom dataclasses import dataclass, field\nfrom pathlib import Path\nfrom typing import Dict, Iterable, NamedTuple, Set, Tuple\n\nfrom platformdirs import user_cache_dir\n\nfrom _black_version import version as __version__\nfrom black.mode import Mode\n\nif sys.version_info >= (3, 11):\n    from typing import Self\nelse:\n    from typing_extensions import Self\n\n\nclass FileData(NamedTuple):\n    st_mtime: float\n    st_size: int\n    hash: str\n\n\ndef get_cache_dir() -> Path:\n    \"\"\"Get the cache directory used by black.\n\n    Users can customize this directory on all systems using `BLACK_CACHE_DIR`\n    environment variable. By default, the cache directory is the user cache directory\n    under the black application.\n\n    This result is immediately set to a constant `black.cache.CACHE_DIR` as to avoid\n    repeated calls.\n    \"\"\"\n    # NOTE: Function mostly exists as a clean way to test getting the cache directory.\n    default_cache_dir = user_cache_dir(\"black\")\n    cache_dir = Path(os.environ.get(\"BLACK_CACHE_DIR\", default_cache_dir))\n    cache_dir = cache_dir / __version__\n    return cache_dir\n\n\nCACHE_DIR = get_cache_dir()\n\n\ndef get_cache_file(mode: Mode) -> Path:\n    return CACHE_DIR / f\"cache.{mode.get_cache_key()}.pickle\"\n\n\n@dataclass\nclass Cache:\n    mode: Mode\n    cache_file: Path\n    file_data: Dict[str, FileData] = field(default_factory=dict)\n\n    @classmethod\n    def read(cls, mode: Mode) -> Self:\n        \"\"\"Read the cache if it exists and is well formed.\n\n        If it is not well formed, the call to write later should\n        resolve the issue.\n        \"\"\"\n        cache_file = get_cache_file(mode)\n        if not cache_file.exists():\n            return cls(mode, cache_file)\n\n        with cache_file.open(\"rb\") as fobj:\n            try:\n                data: Dict[str, Tuple[float, int, str]] = pickle.load(fobj)\n                file_data = {k: FileData(*v) for k, v in data.items()}\n            except (pickle.UnpicklingError, ValueError, IndexError):\n                return cls(mode, cache_file)\n\n        return cls(mode, cache_file, file_data)\n\n    @staticmethod\n    def hash_digest(path: Path) -> str:\n        \"\"\"Return hash digest for path.\"\"\"\n\n        data = path.read_bytes()\n        return hashlib.sha256(data).hexdigest()\n\n    @staticmethod\n    def get_file_data(path: Path) -> FileData:\n        \"\"\"Return file data for path.\"\"\"\n\n        stat = path.stat()\n        hash = Cache.hash_digest(path)\n        return FileData(stat.st_mtime, stat.st_size, hash)\n\n    def is_changed(self, source: Path) -> bool:\n        \"\"\"Check if source has changed compared to cached version.\"\"\"\n        res_src = source.resolve()\n        old = self.file_data.get(str(res_src))\n        if old is None:\n            return True\n\n        st = res_src.stat()\n        if st.st_size != old.st_size:\n            return True\n        if st.st_mtime != old.st_mtime:\n            new_hash = Cache.hash_digest(res_src)\n            if new_hash != old.hash:\n                return True\n        return False\n\n    def filtered_cached(self, sources: Iterable[Path]) -> Tuple[Set[Path], Set[Path]]:\n        \"\"\"Split an iterable of paths in `sources` into two sets.\n\n        The first contains paths of files that modified on disk or are not in the\n        cache. The other contains paths to non-modified files.\n        \"\"\"\n        changed: Set[Path] = set()\n        done: Set[Path] = set()\n        for src in sources:\n            if self.is_changed(src):\n                changed.add(src)\n            else:\n                done.add(src)\n        return changed, done\n\n    def write(self, sources: Iterable[Path]) -> None:\n        \"\"\"Update the cache file data and write a new cache file.\"\"\"\n        self.file_data.update(\n            **{str(src.resolve()): Cache.get_file_data(src) for src in sources}\n        )\n        try:\n            CACHE_DIR.mkdir(parents=True, exist_ok=True)\n            with tempfile.NamedTemporaryFile(\n                dir=str(self.cache_file.parent), delete=False\n            ) as f:\n                # We store raw tuples in the cache because pickling NamedTuples\n                # doesn't work with mypyc on Python 3.8, and because it's faster.\n                data: Dict[str, Tuple[float, int, str]] = {\n                    k: (*v,) for k, v in self.file_data.items()\n                }\n                pickle.dump(data, f, protocol=4)\n            os.replace(f.name, self.cache_file)\n        except OSError:\n            pass\n", "path": "src/black/cache.py"}]}