We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Consider updating `DirectoryTree` so that it takes `Path` as well as a `str` as the path to browse
Some people tend to favour using `Path` over `str` for paths and the like, so I feel it would be an idea to accept a `Path` as the path.

--- 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/textual/widgets/_directory_tree.py`
Content:
```
1 from __future__ import annotations
2 
3 from dataclasses import dataclass
4 from pathlib import Path
5 from typing import ClassVar
6 
7 from rich.style import Style
8 from rich.text import Text, TextType
9 
10 from .._types import MessageTarget
11 from ..message import Message
12 from ._tree import TOGGLE_STYLE, Tree, TreeNode
13 
14 
15 @dataclass
16 class DirEntry:
17     """Attaches directory information ot a node."""
18 
19     path: str
20     is_dir: bool
21     loaded: bool = False
22 
23 
24 class DirectoryTree(Tree[DirEntry]):
25     """A Tree widget that presents files and directories.
26 
27     Args:
28         path: Path to directory.
29         name: The name of the widget, or None for no name. Defaults to None.
30         id: The ID of the widget in the DOM, or None for no ID. Defaults to None.
31         classes: A space-separated list of classes, or None for no classes. Defaults to None.
32         disabled: Whether the directory tree is disabled or not.
33     """
34 
35     COMPONENT_CLASSES: ClassVar[set[str]] = {
36         "directory-tree--folder",
37         "directory-tree--file",
38         "directory-tree--extension",
39         "directory-tree--hidden",
40     }
41     """
42     | Class | Description |
43     | :- | :- |
44     | `directory-tree--extension` | Target the extension of a file name. |
45     | `directory-tree--file` | Target files in the directory structure. |
46     | `directory-tree--folder` | Target folders in the directory structure. |
47     | `directory-tree--hidden` | Target hidden items in the directory structure. |
48 
49     See also the [component classes for `Tree`][textual.widgets.Tree.COMPONENT_CLASSES].
50     """
51 
52     DEFAULT_CSS = """
53     DirectoryTree > .directory-tree--folder {
54         text-style: bold;
55     }
56 
57     DirectoryTree > .directory-tree--file {
58 
59     }
60 
61     DirectoryTree > .directory-tree--extension {
62         text-style: italic;
63     }
64 
65     DirectoryTree > .directory-tree--hidden {
66         color: $text 50%;
67     }
68     """
69 
70     class FileSelected(Message, bubble=True):
71         """Posted when a file is selected.
72 
73         Can be handled using `on_directory_tree_file_selected` in a subclass of
74         `DirectoryTree` or in a parent widget in the DOM.
75 
76         Attributes:
77             path: The path of the file that was selected.
78         """
79 
80         def __init__(self, path: str) -> None:
81             self.path: str = path
82             super().__init__()
83 
84     def __init__(
85         self,
86         path: str,
87         *,
88         name: str | None = None,
89         id: str | None = None,
90         classes: str | None = None,
91         disabled: bool = False,
92     ) -> None:
93         self.path = path
94         super().__init__(
95             path,
96             data=DirEntry(path, True),
97             name=name,
98             id=id,
99             classes=classes,
100             disabled=disabled,
101         )
102 
103     def process_label(self, label: TextType):
104         """Process a str or Text into a label. Maybe overridden in a subclass to modify how labels are rendered.
105 
106         Args:
107             label: Label.
108 
109         Returns:
110             A Rich Text object.
111         """
112         if isinstance(label, str):
113             text_label = Text(label)
114         else:
115             text_label = label
116         first_line = text_label.split()[0]
117         return first_line
118 
119     def render_label(self, node: TreeNode[DirEntry], base_style: Style, style: Style):
120         node_label = node._label.copy()
121         node_label.stylize(style)
122 
123         if node._allow_expand:
124             prefix = ("📂 " if node.is_expanded else "📁 ", base_style + TOGGLE_STYLE)
125             node_label.stylize_before(
126                 self.get_component_rich_style("directory-tree--folder", partial=True)
127             )
128         else:
129             prefix = (
130                 "📄 ",
131                 base_style,
132             )
133             node_label.stylize_before(
134                 self.get_component_rich_style("directory-tree--file", partial=True),
135             )
136             node_label.highlight_regex(
137                 r"\..+$",
138                 self.get_component_rich_style(
139                     "directory-tree--extension", partial=True
140                 ),
141             )
142 
143         if node_label.plain.startswith("."):
144             node_label.stylize_before(
145                 self.get_component_rich_style("directory-tree--hidden")
146             )
147 
148         text = Text.assemble(prefix, node_label)
149         return text
150 
151     def load_directory(self, node: TreeNode[DirEntry]) -> None:
152         assert node.data is not None
153         dir_path = Path(node.data.path)
154         node.data.loaded = True
155         directory = sorted(
156             list(dir_path.iterdir()),
157             key=lambda path: (not path.is_dir(), path.name.lower()),
158         )
159         for path in directory:
160             node.add(
161                 path.name,
162                 data=DirEntry(str(path), path.is_dir()),
163                 allow_expand=path.is_dir(),
164             )
165         node.expand()
166 
167     def on_mount(self) -> None:
168         self.load_directory(self.root)
169 
170     def on_tree_node_expanded(self, event: Tree.NodeSelected) -> None:
171         event.stop()
172         dir_entry = event.node.data
173         if dir_entry is None:
174             return
175         if dir_entry.is_dir:
176             if not dir_entry.loaded:
177                 self.load_directory(event.node)
178         else:
179             self.post_message(self.FileSelected(dir_entry.path))
180 
181     def on_tree_node_selected(self, event: Tree.NodeSelected) -> None:
182         event.stop()
183         dir_entry = event.node.data
184         if dir_entry is None:
185             return
186         if not dir_entry.is_dir:
187             self.post_message(self.FileSelected(dir_entry.path))
188
```
--- 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/textual/widgets/_directory_tree.py b/src/textual/widgets/_directory_tree.py
--- a/src/textual/widgets/_directory_tree.py
+++ b/src/textual/widgets/_directory_tree.py
@@ -1,5 +1,6 @@
 from __future__ import annotations
 
+import os
 from dataclasses import dataclass
 from pathlib import Path
 from typing import ClassVar
@@ -7,14 +8,13 @@
 from rich.style import Style
 from rich.text import Text, TextType
 
-from .._types import MessageTarget
 from ..message import Message
 from ._tree import TOGGLE_STYLE, Tree, TreeNode
 
 
 @dataclass
 class DirEntry:
-    """Attaches directory information ot a node."""
+    """Attaches directory information to a node."""
 
     path: str
     is_dir: bool
@@ -26,9 +26,9 @@
 
     Args:
         path: Path to directory.
-        name: The name of the widget, or None for no name. Defaults to None.
-        id: The ID of the widget in the DOM, or None for no ID. Defaults to None.
-        classes: A space-separated list of classes, or None for no classes. Defaults to None.
+        name: The name of the widget, or None for no name.
+        id: The ID of the widget in the DOM, or None for no ID.
+        classes: A space-separated list of classes, or None for no classes.
         disabled: Whether the directory tree is disabled or not.
     """
 
@@ -83,17 +83,18 @@
 
     def __init__(
         self,
-        path: str,
+        path: str | Path,
         *,
         name: str | None = None,
         id: str | None = None,
         classes: str | None = None,
         disabled: bool = False,
     ) -> None:
-        self.path = path
+        str_path = os.fspath(path)
+        self.path = str_path
         super().__init__(
-            path,
-            data=DirEntry(path, True),
+            str_path,
+            data=DirEntry(str_path, True),
             name=name,
             id=id,
             classes=classes,

{"golden_diff": "diff --git a/src/textual/widgets/_directory_tree.py b/src/textual/widgets/_directory_tree.py\n--- a/src/textual/widgets/_directory_tree.py\n+++ b/src/textual/widgets/_directory_tree.py\n@@ -1,5 +1,6 @@\n from __future__ import annotations\n \n+import os\n from dataclasses import dataclass\n from pathlib import Path\n from typing import ClassVar\n@@ -7,14 +8,13 @@\n from rich.style import Style\n from rich.text import Text, TextType\n \n-from .._types import MessageTarget\n from ..message import Message\n from ._tree import TOGGLE_STYLE, Tree, TreeNode\n \n \n @dataclass\n class DirEntry:\n-    \"\"\"Attaches directory information ot a node.\"\"\"\n+    \"\"\"Attaches directory information to a node.\"\"\"\n \n     path: str\n     is_dir: bool\n@@ -26,9 +26,9 @@\n \n     Args:\n         path: Path to directory.\n-        name: The name of the widget, or None for no name. Defaults to None.\n-        id: The ID of the widget in the DOM, or None for no ID. Defaults to None.\n-        classes: A space-separated list of classes, or None for no classes. Defaults to None.\n+        name: The name of the widget, or None for no name.\n+        id: The ID of the widget in the DOM, or None for no ID.\n+        classes: A space-separated list of classes, or None for no classes.\n         disabled: Whether the directory tree is disabled or not.\n     \"\"\"\n \n@@ -83,17 +83,18 @@\n \n     def __init__(\n         self,\n-        path: str,\n+        path: str | Path,\n         *,\n         name: str | None = None,\n         id: str | None = None,\n         classes: str | None = None,\n         disabled: bool = False,\n     ) -> None:\n-        self.path = path\n+        str_path = os.fspath(path)\n+        self.path = str_path\n         super().__init__(\n-            path,\n-            data=DirEntry(path, True),\n+            str_path,\n+            data=DirEntry(str_path, True),\n             name=name,\n             id=id,\n             classes=classes,\n", "issue": "Consider updating `DirectoryTree` so that it takes `Path` as well as a `str` as the path to browse\nSome people tend to favour using `Path` over `str` for paths and the like, so I feel it would be an idea to accept a `Path` as the path.\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom dataclasses import dataclass\nfrom pathlib import Path\nfrom typing import ClassVar\n\nfrom rich.style import Style\nfrom rich.text import Text, TextType\n\nfrom .._types import MessageTarget\nfrom ..message import Message\nfrom ._tree import TOGGLE_STYLE, Tree, TreeNode\n\n\n@dataclass\nclass DirEntry:\n    \"\"\"Attaches directory information ot a node.\"\"\"\n\n    path: str\n    is_dir: bool\n    loaded: bool = False\n\n\nclass DirectoryTree(Tree[DirEntry]):\n    \"\"\"A Tree widget that presents files and directories.\n\n    Args:\n        path: Path to directory.\n        name: The name of the widget, or None for no name. Defaults to None.\n        id: The ID of the widget in the DOM, or None for no ID. Defaults to None.\n        classes: A space-separated list of classes, or None for no classes. Defaults to None.\n        disabled: Whether the directory tree is disabled or not.\n    \"\"\"\n\n    COMPONENT_CLASSES: ClassVar[set[str]] = {\n        \"directory-tree--folder\",\n        \"directory-tree--file\",\n        \"directory-tree--extension\",\n        \"directory-tree--hidden\",\n    }\n    \"\"\"\n    | Class | Description |\n    | :- | :- |\n    | `directory-tree--extension` | Target the extension of a file name. |\n    | `directory-tree--file` | Target files in the directory structure. |\n    | `directory-tree--folder` | Target folders in the directory structure. |\n    | `directory-tree--hidden` | Target hidden items in the directory structure. |\n\n    See also the [component classes for `Tree`][textual.widgets.Tree.COMPONENT_CLASSES].\n    \"\"\"\n\n    DEFAULT_CSS = \"\"\"\n    DirectoryTree > .directory-tree--folder {\n        text-style: bold;\n    }\n\n    DirectoryTree > .directory-tree--file {\n\n    }\n\n    DirectoryTree > .directory-tree--extension {\n        text-style: italic;\n    }\n\n    DirectoryTree > .directory-tree--hidden {\n        color: $text 50%;\n    }\n    \"\"\"\n\n    class FileSelected(Message, bubble=True):\n        \"\"\"Posted when a file is selected.\n\n        Can be handled using `on_directory_tree_file_selected` in a subclass of\n        `DirectoryTree` or in a parent widget in the DOM.\n\n        Attributes:\n            path: The path of the file that was selected.\n        \"\"\"\n\n        def __init__(self, path: str) -> None:\n            self.path: str = path\n            super().__init__()\n\n    def __init__(\n        self,\n        path: str,\n        *,\n        name: str | None = None,\n        id: str | None = None,\n        classes: str | None = None,\n        disabled: bool = False,\n    ) -> None:\n        self.path = path\n        super().__init__(\n            path,\n            data=DirEntry(path, True),\n            name=name,\n            id=id,\n            classes=classes,\n            disabled=disabled,\n        )\n\n    def process_label(self, label: TextType):\n        \"\"\"Process a str or Text into a label. Maybe overridden in a subclass to modify how labels are rendered.\n\n        Args:\n            label: Label.\n\n        Returns:\n            A Rich Text object.\n        \"\"\"\n        if isinstance(label, str):\n            text_label = Text(label)\n        else:\n            text_label = label\n        first_line = text_label.split()[0]\n        return first_line\n\n    def render_label(self, node: TreeNode[DirEntry], base_style: Style, style: Style):\n        node_label = node._label.copy()\n        node_label.stylize(style)\n\n        if node._allow_expand:\n            prefix = (\"\ud83d\udcc2 \" if node.is_expanded else \"\ud83d\udcc1 \", base_style + TOGGLE_STYLE)\n            node_label.stylize_before(\n                self.get_component_rich_style(\"directory-tree--folder\", partial=True)\n            )\n        else:\n            prefix = (\n                \"\ud83d\udcc4 \",\n                base_style,\n            )\n            node_label.stylize_before(\n                self.get_component_rich_style(\"directory-tree--file\", partial=True),\n            )\n            node_label.highlight_regex(\n                r\"\\..+$\",\n                self.get_component_rich_style(\n                    \"directory-tree--extension\", partial=True\n                ),\n            )\n\n        if node_label.plain.startswith(\".\"):\n            node_label.stylize_before(\n                self.get_component_rich_style(\"directory-tree--hidden\")\n            )\n\n        text = Text.assemble(prefix, node_label)\n        return text\n\n    def load_directory(self, node: TreeNode[DirEntry]) -> None:\n        assert node.data is not None\n        dir_path = Path(node.data.path)\n        node.data.loaded = True\n        directory = sorted(\n            list(dir_path.iterdir()),\n            key=lambda path: (not path.is_dir(), path.name.lower()),\n        )\n        for path in directory:\n            node.add(\n                path.name,\n                data=DirEntry(str(path), path.is_dir()),\n                allow_expand=path.is_dir(),\n            )\n        node.expand()\n\n    def on_mount(self) -> None:\n        self.load_directory(self.root)\n\n    def on_tree_node_expanded(self, event: Tree.NodeSelected) -> None:\n        event.stop()\n        dir_entry = event.node.data\n        if dir_entry is None:\n            return\n        if dir_entry.is_dir:\n            if not dir_entry.loaded:\n                self.load_directory(event.node)\n        else:\n            self.post_message(self.FileSelected(dir_entry.path))\n\n    def on_tree_node_selected(self, event: Tree.NodeSelected) -> None:\n        event.stop()\n        dir_entry = event.node.data\n        if dir_entry is None:\n            return\n        if not dir_entry.is_dir:\n            self.post_message(self.FileSelected(dir_entry.path))\n", "path": "src/textual/widgets/_directory_tree.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport os\nfrom dataclasses import dataclass\nfrom pathlib import Path\nfrom typing import ClassVar\n\nfrom rich.style import Style\nfrom rich.text import Text, TextType\n\nfrom ..message import Message\nfrom ._tree import TOGGLE_STYLE, Tree, TreeNode\n\n\n@dataclass\nclass DirEntry:\n    \"\"\"Attaches directory information to a node.\"\"\"\n\n    path: str\n    is_dir: bool\n    loaded: bool = False\n\n\nclass DirectoryTree(Tree[DirEntry]):\n    \"\"\"A Tree widget that presents files and directories.\n\n    Args:\n        path: Path to directory.\n        name: The name of the widget, or None for no name.\n        id: The ID of the widget in the DOM, or None for no ID.\n        classes: A space-separated list of classes, or None for no classes.\n        disabled: Whether the directory tree is disabled or not.\n    \"\"\"\n\n    COMPONENT_CLASSES: ClassVar[set[str]] = {\n        \"directory-tree--folder\",\n        \"directory-tree--file\",\n        \"directory-tree--extension\",\n        \"directory-tree--hidden\",\n    }\n    \"\"\"\n    | Class | Description |\n    | :- | :- |\n    | `directory-tree--extension` | Target the extension of a file name. |\n    | `directory-tree--file` | Target files in the directory structure. |\n    | `directory-tree--folder` | Target folders in the directory structure. |\n    | `directory-tree--hidden` | Target hidden items in the directory structure. |\n\n    See also the [component classes for `Tree`][textual.widgets.Tree.COMPONENT_CLASSES].\n    \"\"\"\n\n    DEFAULT_CSS = \"\"\"\n    DirectoryTree > .directory-tree--folder {\n        text-style: bold;\n    }\n\n    DirectoryTree > .directory-tree--file {\n\n    }\n\n    DirectoryTree > .directory-tree--extension {\n        text-style: italic;\n    }\n\n    DirectoryTree > .directory-tree--hidden {\n        color: $text 50%;\n    }\n    \"\"\"\n\n    class FileSelected(Message, bubble=True):\n        \"\"\"Posted when a file is selected.\n\n        Can be handled using `on_directory_tree_file_selected` in a subclass of\n        `DirectoryTree` or in a parent widget in the DOM.\n\n        Attributes:\n            path: The path of the file that was selected.\n        \"\"\"\n\n        def __init__(self, path: str) -> None:\n            self.path: str = path\n            super().__init__()\n\n    def __init__(\n        self,\n        path: str | Path,\n        *,\n        name: str | None = None,\n        id: str | None = None,\n        classes: str | None = None,\n        disabled: bool = False,\n    ) -> None:\n        str_path = os.fspath(path)\n        self.path = str_path\n        super().__init__(\n            str_path,\n            data=DirEntry(str_path, True),\n            name=name,\n            id=id,\n            classes=classes,\n            disabled=disabled,\n        )\n\n    def process_label(self, label: TextType):\n        \"\"\"Process a str or Text into a label. Maybe overridden in a subclass to modify how labels are rendered.\n\n        Args:\n            label: Label.\n\n        Returns:\n            A Rich Text object.\n        \"\"\"\n        if isinstance(label, str):\n            text_label = Text(label)\n        else:\n            text_label = label\n        first_line = text_label.split()[0]\n        return first_line\n\n    def render_label(self, node: TreeNode[DirEntry], base_style: Style, style: Style):\n        node_label = node._label.copy()\n        node_label.stylize(style)\n\n        if node._allow_expand:\n            prefix = (\"\ud83d\udcc2 \" if node.is_expanded else \"\ud83d\udcc1 \", base_style + TOGGLE_STYLE)\n            node_label.stylize_before(\n                self.get_component_rich_style(\"directory-tree--folder\", partial=True)\n            )\n        else:\n            prefix = (\n                \"\ud83d\udcc4 \",\n                base_style,\n            )\n            node_label.stylize_before(\n                self.get_component_rich_style(\"directory-tree--file\", partial=True),\n            )\n            node_label.highlight_regex(\n                r\"\\..+$\",\n                self.get_component_rich_style(\n                    \"directory-tree--extension\", partial=True\n                ),\n            )\n\n        if node_label.plain.startswith(\".\"):\n            node_label.stylize_before(\n                self.get_component_rich_style(\"directory-tree--hidden\")\n            )\n\n        text = Text.assemble(prefix, node_label)\n        return text\n\n    def load_directory(self, node: TreeNode[DirEntry]) -> None:\n        assert node.data is not None\n        dir_path = Path(node.data.path)\n        node.data.loaded = True\n        directory = sorted(\n            list(dir_path.iterdir()),\n            key=lambda path: (not path.is_dir(), path.name.lower()),\n        )\n        for path in directory:\n            node.add(\n                path.name,\n                data=DirEntry(str(path), path.is_dir()),\n                allow_expand=path.is_dir(),\n            )\n        node.expand()\n\n    def on_mount(self) -> None:\n        self.load_directory(self.root)\n\n    def on_tree_node_expanded(self, event: Tree.NodeSelected) -> None:\n        event.stop()\n        dir_entry = event.node.data\n        if dir_entry is None:\n            return\n        if dir_entry.is_dir:\n            if not dir_entry.loaded:\n                self.load_directory(event.node)\n        else:\n            self.post_message(self.FileSelected(dir_entry.path))\n\n    def on_tree_node_selected(self, event: Tree.NodeSelected) -> None:\n        event.stop()\n        dir_entry = event.node.data\n        if dir_entry is None:\n            return\n        if not dir_entry.is_dir:\n            self.post_message(self.FileSelected(dir_entry.path))\n", "path": "src/textual/widgets/_directory_tree.py"}]}