We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ENH: use stdlib tomllib when available (Python 3.11)
### Bug report

**Bug summary**

`tomli` is currently a hard dependency third party, but it's been integrated to the standard library as `tomllib` and will be available in Python 3.11
Because it's the same underlying implementation, this means we should be able to use `tomli` as a "backport" of `tomllib` in Python 3.10 and older as

```python
import sys

if sys.version_info >= (3, 11):
    import tomllib
else:
    import tomli as tomllib
```

However I'd rather not implement this just now, because Python 3.11 isn't testable yet: we depend on numpy for this. Here's the upstream PR to keep track of https://github.com/numpy/numpy/pull/21308

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `yt/utilities/configure.py`
Content:
```
1 import os
2 import warnings
3 from typing import Callable, List
4 
5 # TODO: import tomllib from the standard library instead in Python >= 3.11
6 import tomli as tomllib
7 import tomli_w
8 from more_itertools import always_iterable
9 
10 from yt.utilities.configuration_tree import ConfigLeaf, ConfigNode
11 
12 configuration_callbacks: List[Callable[["YTConfig"], None]] = []
13 
14 
15 def config_dir():
16     config_root = os.environ.get(
17         "XDG_CONFIG_HOME", os.path.join(os.path.expanduser("~"), ".config")
18     )
19     conf_dir = os.path.join(config_root, "yt")
20     return conf_dir
21 
22 
23 class YTConfig:
24     def __init__(self, defaults=None):
25         if defaults is None:
26             defaults = {}
27         self.config_root = ConfigNode(None)
28 
29     def get(self, section, *keys, callback=None):
30         node_or_leaf = self.config_root.get(section, *keys)
31         if isinstance(node_or_leaf, ConfigLeaf):
32             if callback is not None:
33                 return callback(node_or_leaf)
34             return node_or_leaf.value
35         return node_or_leaf
36 
37     def get_most_specific(self, section, *keys, **kwargs):
38         use_fallback = "fallback" in kwargs
39         fallback = kwargs.pop("fallback", None)
40         try:
41             return self.config_root.get_deepest_leaf(section, *keys)
42         except KeyError as err:
43             if use_fallback:
44                 return fallback
45             else:
46                 raise err
47 
48     def update(self, new_values, metadata=None):
49         if metadata is None:
50             metadata = {}
51         self.config_root.update(new_values, metadata)
52 
53     def has_section(self, section):
54         try:
55             self.config_root.get_child(section)
56             return True
57         except KeyError:
58             return False
59 
60     def add_section(self, section):
61         self.config_root.add_child(section)
62 
63     def remove_section(self, section):
64         if self.has_section(section):
65             self.config_root.remove_child(section)
66             return True
67         else:
68             return False
69 
70     def set(self, *args, metadata=None):
71         section, *keys, value = args
72         if metadata is None:
73             metadata = {"source": "runtime"}
74         self.config_root.upsert_from_list(
75             [section] + list(keys), value, extra_data=metadata
76         )
77 
78     def remove(self, *args):
79         self.config_root.pop_leaf(args)
80 
81     def read(self, file_names):
82         file_names_read = []
83         for fname in always_iterable(file_names):
84             if not os.path.exists(fname):
85                 continue
86             metadata = {"source": f"file: {fname}"}
87             try:
88                 with open(fname, "rb") as fh:
89                     data = tomllib.load(fh)
90             except tomllib.TOMLDecodeError as exc:
91                 warnings.warn(
92                     f"Could not load configuration file {fname} (invalid TOML: {exc})"
93                 )
94             else:
95                 self.update(data, metadata=metadata)
96                 file_names_read.append(fname)
97 
98         return file_names_read
99 
100     def write(self, file_handler):
101         value = self.config_root.as_dict()
102         config_as_str = tomli_w.dumps(value)
103 
104         try:
105             # Assuming file_handler has a write attribute
106             file_handler.write(config_as_str)
107         except AttributeError:
108             # Otherwise we expect a path to a file
109             with open(file_handler, mode="w") as fh:
110                 fh.write(config_as_str)
111 
112     @staticmethod
113     def get_global_config_file():
114         return os.path.join(config_dir(), "yt.toml")
115 
116     @staticmethod
117     def get_local_config_file():
118         return os.path.join(os.path.abspath(os.curdir), "yt.toml")
119 
120     def __setitem__(self, args, value):
121         section, *keys = always_iterable(args)
122         self.set(section, *keys, value, metadata=None)
123 
124     def __getitem__(self, key):
125         section, *keys = always_iterable(key)
126         return self.get(section, *keys)
127 
128     def __contains__(self, item):
129         return item in self.config_root
130 
131     # Add support for IPython rich display
132     # see https://ipython.readthedocs.io/en/stable/config/integrating.html
133     def _repr_json_(self):
134         return self.config_root._repr_json_()
135 
136 
137 CONFIG = YTConfig()
138 
139 
140 def _cast_bool_helper(value):
141     if value == "True":
142         return True
143     elif value == "False":
144         return False
145     else:
146         raise ValueError("Cannot safely cast to bool")
147 
148 
149 def _expand_all(s):
150     return os.path.expandvars(os.path.expanduser(s))
151 
152 
153 def _cast_value_helper(value, types=(_cast_bool_helper, int, float, _expand_all)):
154     for t in types:
155         try:
156             retval = t(value)
157             return retval
158         except ValueError:
159             pass
160 
161 
162 def get_config(section, option):
163     *option_path, option_name = option.split(".")
164     return CONFIG.get(section, *option_path, option_name)
165 
166 
167 def set_config(section, option, value, config_file):
168     if not CONFIG.has_section(section):
169         CONFIG.add_section(section)
170 
171     option_path = option.split(".")
172     CONFIG.set(section, *option_path, _cast_value_helper(value))
173     write_config(config_file)
174 
175 
176 def write_config(config_file):
177     CONFIG.write(config_file)
178 
179 
180 def rm_config(section, option, config_file):
181     option_path = option.split(".")
182     CONFIG.remove(section, *option_path)
183     write_config(config_file)
184
```
--- 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/yt/utilities/configure.py b/yt/utilities/configure.py
--- a/yt/utilities/configure.py
+++ b/yt/utilities/configure.py
@@ -1,14 +1,18 @@
 import os
+import sys
 import warnings
 from typing import Callable, List
 
-# TODO: import tomllib from the standard library instead in Python >= 3.11
-import tomli as tomllib
 import tomli_w
 from more_itertools import always_iterable
 
 from yt.utilities.configuration_tree import ConfigLeaf, ConfigNode
 
+if sys.version_info >= (3, 11):
+    import tomllib
+else:
+    import tomli as tomllib
+
 configuration_callbacks: List[Callable[["YTConfig"], None]] = []

{"golden_diff": "diff --git a/yt/utilities/configure.py b/yt/utilities/configure.py\n--- a/yt/utilities/configure.py\n+++ b/yt/utilities/configure.py\n@@ -1,14 +1,18 @@\n import os\n+import sys\n import warnings\n from typing import Callable, List\n \n-# TODO: import tomllib from the standard library instead in Python >= 3.11\n-import tomli as tomllib\n import tomli_w\n from more_itertools import always_iterable\n \n from yt.utilities.configuration_tree import ConfigLeaf, ConfigNode\n \n+if sys.version_info >= (3, 11):\n+    import tomllib\n+else:\n+    import tomli as tomllib\n+\n configuration_callbacks: List[Callable[[\"YTConfig\"], None]] = []\n", "issue": "ENH: use stdlib tomllib when available (Python 3.11)\n### Bug report\r\n\r\n**Bug summary**\r\n\r\n`tomli` is currently a hard dependency third party, but it's been integrated to the standard library as `tomllib` and will be available in Python 3.11\r\nBecause it's the same underlying implementation, this means we should be able to use `tomli` as a \"backport\" of `tomllib` in Python 3.10 and older as\r\n\r\n```python\r\nimport sys\r\n\r\nif sys.version_info >= (3, 11):\r\n    import tomllib\r\nelse:\r\n    import tomli as tomllib\r\n```\r\n\r\nHowever I'd rather not implement this just now, because Python 3.11 isn't testable yet: we depend on numpy for this. Here's the upstream PR to keep track of https://github.com/numpy/numpy/pull/21308\n", "before_files": [{"content": "import os\nimport warnings\nfrom typing import Callable, List\n\n# TODO: import tomllib from the standard library instead in Python >= 3.11\nimport tomli as tomllib\nimport tomli_w\nfrom more_itertools import always_iterable\n\nfrom yt.utilities.configuration_tree import ConfigLeaf, ConfigNode\n\nconfiguration_callbacks: List[Callable[[\"YTConfig\"], None]] = []\n\n\ndef config_dir():\n    config_root = os.environ.get(\n        \"XDG_CONFIG_HOME\", os.path.join(os.path.expanduser(\"~\"), \".config\")\n    )\n    conf_dir = os.path.join(config_root, \"yt\")\n    return conf_dir\n\n\nclass YTConfig:\n    def __init__(self, defaults=None):\n        if defaults is None:\n            defaults = {}\n        self.config_root = ConfigNode(None)\n\n    def get(self, section, *keys, callback=None):\n        node_or_leaf = self.config_root.get(section, *keys)\n        if isinstance(node_or_leaf, ConfigLeaf):\n            if callback is not None:\n                return callback(node_or_leaf)\n            return node_or_leaf.value\n        return node_or_leaf\n\n    def get_most_specific(self, section, *keys, **kwargs):\n        use_fallback = \"fallback\" in kwargs\n        fallback = kwargs.pop(\"fallback\", None)\n        try:\n            return self.config_root.get_deepest_leaf(section, *keys)\n        except KeyError as err:\n            if use_fallback:\n                return fallback\n            else:\n                raise err\n\n    def update(self, new_values, metadata=None):\n        if metadata is None:\n            metadata = {}\n        self.config_root.update(new_values, metadata)\n\n    def has_section(self, section):\n        try:\n            self.config_root.get_child(section)\n            return True\n        except KeyError:\n            return False\n\n    def add_section(self, section):\n        self.config_root.add_child(section)\n\n    def remove_section(self, section):\n        if self.has_section(section):\n            self.config_root.remove_child(section)\n            return True\n        else:\n            return False\n\n    def set(self, *args, metadata=None):\n        section, *keys, value = args\n        if metadata is None:\n            metadata = {\"source\": \"runtime\"}\n        self.config_root.upsert_from_list(\n            [section] + list(keys), value, extra_data=metadata\n        )\n\n    def remove(self, *args):\n        self.config_root.pop_leaf(args)\n\n    def read(self, file_names):\n        file_names_read = []\n        for fname in always_iterable(file_names):\n            if not os.path.exists(fname):\n                continue\n            metadata = {\"source\": f\"file: {fname}\"}\n            try:\n                with open(fname, \"rb\") as fh:\n                    data = tomllib.load(fh)\n            except tomllib.TOMLDecodeError as exc:\n                warnings.warn(\n                    f\"Could not load configuration file {fname} (invalid TOML: {exc})\"\n                )\n            else:\n                self.update(data, metadata=metadata)\n                file_names_read.append(fname)\n\n        return file_names_read\n\n    def write(self, file_handler):\n        value = self.config_root.as_dict()\n        config_as_str = tomli_w.dumps(value)\n\n        try:\n            # Assuming file_handler has a write attribute\n            file_handler.write(config_as_str)\n        except AttributeError:\n            # Otherwise we expect a path to a file\n            with open(file_handler, mode=\"w\") as fh:\n                fh.write(config_as_str)\n\n    @staticmethod\n    def get_global_config_file():\n        return os.path.join(config_dir(), \"yt.toml\")\n\n    @staticmethod\n    def get_local_config_file():\n        return os.path.join(os.path.abspath(os.curdir), \"yt.toml\")\n\n    def __setitem__(self, args, value):\n        section, *keys = always_iterable(args)\n        self.set(section, *keys, value, metadata=None)\n\n    def __getitem__(self, key):\n        section, *keys = always_iterable(key)\n        return self.get(section, *keys)\n\n    def __contains__(self, item):\n        return item in self.config_root\n\n    # Add support for IPython rich display\n    # see https://ipython.readthedocs.io/en/stable/config/integrating.html\n    def _repr_json_(self):\n        return self.config_root._repr_json_()\n\n\nCONFIG = YTConfig()\n\n\ndef _cast_bool_helper(value):\n    if value == \"True\":\n        return True\n    elif value == \"False\":\n        return False\n    else:\n        raise ValueError(\"Cannot safely cast to bool\")\n\n\ndef _expand_all(s):\n    return os.path.expandvars(os.path.expanduser(s))\n\n\ndef _cast_value_helper(value, types=(_cast_bool_helper, int, float, _expand_all)):\n    for t in types:\n        try:\n            retval = t(value)\n            return retval\n        except ValueError:\n            pass\n\n\ndef get_config(section, option):\n    *option_path, option_name = option.split(\".\")\n    return CONFIG.get(section, *option_path, option_name)\n\n\ndef set_config(section, option, value, config_file):\n    if not CONFIG.has_section(section):\n        CONFIG.add_section(section)\n\n    option_path = option.split(\".\")\n    CONFIG.set(section, *option_path, _cast_value_helper(value))\n    write_config(config_file)\n\n\ndef write_config(config_file):\n    CONFIG.write(config_file)\n\n\ndef rm_config(section, option, config_file):\n    option_path = option.split(\".\")\n    CONFIG.remove(section, *option_path)\n    write_config(config_file)\n", "path": "yt/utilities/configure.py"}], "after_files": [{"content": "import os\nimport sys\nimport warnings\nfrom typing import Callable, List\n\nimport tomli_w\nfrom more_itertools import always_iterable\n\nfrom yt.utilities.configuration_tree import ConfigLeaf, ConfigNode\n\nif sys.version_info >= (3, 11):\n    import tomllib\nelse:\n    import tomli as tomllib\n\nconfiguration_callbacks: List[Callable[[\"YTConfig\"], None]] = []\n\n\ndef config_dir():\n    config_root = os.environ.get(\n        \"XDG_CONFIG_HOME\", os.path.join(os.path.expanduser(\"~\"), \".config\")\n    )\n    conf_dir = os.path.join(config_root, \"yt\")\n    return conf_dir\n\n\nclass YTConfig:\n    def __init__(self, defaults=None):\n        if defaults is None:\n            defaults = {}\n        self.config_root = ConfigNode(None)\n\n    def get(self, section, *keys, callback=None):\n        node_or_leaf = self.config_root.get(section, *keys)\n        if isinstance(node_or_leaf, ConfigLeaf):\n            if callback is not None:\n                return callback(node_or_leaf)\n            return node_or_leaf.value\n        return node_or_leaf\n\n    def get_most_specific(self, section, *keys, **kwargs):\n        use_fallback = \"fallback\" in kwargs\n        fallback = kwargs.pop(\"fallback\", None)\n        try:\n            return self.config_root.get_deepest_leaf(section, *keys)\n        except KeyError as err:\n            if use_fallback:\n                return fallback\n            else:\n                raise err\n\n    def update(self, new_values, metadata=None):\n        if metadata is None:\n            metadata = {}\n        self.config_root.update(new_values, metadata)\n\n    def has_section(self, section):\n        try:\n            self.config_root.get_child(section)\n            return True\n        except KeyError:\n            return False\n\n    def add_section(self, section):\n        self.config_root.add_child(section)\n\n    def remove_section(self, section):\n        if self.has_section(section):\n            self.config_root.remove_child(section)\n            return True\n        else:\n            return False\n\n    def set(self, *args, metadata=None):\n        section, *keys, value = args\n        if metadata is None:\n            metadata = {\"source\": \"runtime\"}\n        self.config_root.upsert_from_list(\n            [section] + list(keys), value, extra_data=metadata\n        )\n\n    def remove(self, *args):\n        self.config_root.pop_leaf(args)\n\n    def read(self, file_names):\n        file_names_read = []\n        for fname in always_iterable(file_names):\n            if not os.path.exists(fname):\n                continue\n            metadata = {\"source\": f\"file: {fname}\"}\n            try:\n                with open(fname, \"rb\") as fh:\n                    data = tomllib.load(fh)\n            except tomllib.TOMLDecodeError as exc:\n                warnings.warn(\n                    f\"Could not load configuration file {fname} (invalid TOML: {exc})\"\n                )\n            else:\n                self.update(data, metadata=metadata)\n                file_names_read.append(fname)\n\n        return file_names_read\n\n    def write(self, file_handler):\n        value = self.config_root.as_dict()\n        config_as_str = tomli_w.dumps(value)\n\n        try:\n            # Assuming file_handler has a write attribute\n            file_handler.write(config_as_str)\n        except AttributeError:\n            # Otherwise we expect a path to a file\n            with open(file_handler, mode=\"w\") as fh:\n                fh.write(config_as_str)\n\n    @staticmethod\n    def get_global_config_file():\n        return os.path.join(config_dir(), \"yt.toml\")\n\n    @staticmethod\n    def get_local_config_file():\n        return os.path.join(os.path.abspath(os.curdir), \"yt.toml\")\n\n    def __setitem__(self, args, value):\n        section, *keys = always_iterable(args)\n        self.set(section, *keys, value, metadata=None)\n\n    def __getitem__(self, key):\n        section, *keys = always_iterable(key)\n        return self.get(section, *keys)\n\n    def __contains__(self, item):\n        return item in self.config_root\n\n    # Add support for IPython rich display\n    # see https://ipython.readthedocs.io/en/stable/config/integrating.html\n    def _repr_json_(self):\n        return self.config_root._repr_json_()\n\n\nCONFIG = YTConfig()\n\n\ndef _cast_bool_helper(value):\n    if value == \"True\":\n        return True\n    elif value == \"False\":\n        return False\n    else:\n        raise ValueError(\"Cannot safely cast to bool\")\n\n\ndef _expand_all(s):\n    return os.path.expandvars(os.path.expanduser(s))\n\n\ndef _cast_value_helper(value, types=(_cast_bool_helper, int, float, _expand_all)):\n    for t in types:\n        try:\n            retval = t(value)\n            return retval\n        except ValueError:\n            pass\n\n\ndef get_config(section, option):\n    *option_path, option_name = option.split(\".\")\n    return CONFIG.get(section, *option_path, option_name)\n\n\ndef set_config(section, option, value, config_file):\n    if not CONFIG.has_section(section):\n        CONFIG.add_section(section)\n\n    option_path = option.split(\".\")\n    CONFIG.set(section, *option_path, _cast_value_helper(value))\n    write_config(config_file)\n\n\ndef write_config(config_file):\n    CONFIG.write(config_file)\n\n\ndef rm_config(section, option, config_file):\n    option_path = option.split(\".\")\n    CONFIG.remove(section, *option_path)\n    write_config(config_file)\n", "path": "yt/utilities/configure.py"}]}