Repository: yt-project/yt

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


Discussion:

Resolving patch:
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]] = []
 
 


Test patch:
diff --git a/yt/visualization/volume_rendering/tests/test_composite.py b/yt/visualization/volume_rendering/tests/test_composite.py
--- a/yt/visualization/volume_rendering/tests/test_composite.py
+++ b/yt/visualization/volume_rendering/tests/test_composite.py
@@ -81,4 +81,3 @@ def test_composite_vr(self):
         im = sc.render()
         im = ImageArray(im.d)
         im.write_png("composite.png")
-        return im
diff --git a/yt/visualization/volume_rendering/tests/test_points.py b/yt/visualization/volume_rendering/tests/test_points.py
--- a/yt/visualization/volume_rendering/tests/test_points.py
+++ b/yt/visualization/volume_rendering/tests/test_points.py
@@ -66,4 +66,3 @@ def test_points_vr(self):
         sc.add_source(points_source)
         im = sc.render()
         im.write_png("points.png")
-        return im
diff --git a/yt/visualization/volume_rendering/tests/test_save_render.py b/yt/visualization/volume_rendering/tests/test_save_render.py
--- a/yt/visualization/volume_rendering/tests/test_save_render.py
+++ b/yt/visualization/volume_rendering/tests/test_save_render.py
@@ -43,5 +43,3 @@ def test_save_render(self):
         # save a different format with/without sigma clips
         sc.save(os.path.join(self.tmpdir, "no_clip.jpg"), render=False)
         sc.save(os.path.join(self.tmpdir, "clip_2.jpg"), sigma_clip=2, render=False)
-
-        return sc
diff --git a/yt/visualization/volume_rendering/tests/test_simple_vr.py b/yt/visualization/volume_rendering/tests/test_simple_vr.py
--- a/yt/visualization/volume_rendering/tests/test_simple_vr.py
+++ b/yt/visualization/volume_rendering/tests/test_simple_vr.py
@@ -34,5 +34,4 @@ def tearDown(self):
 
     def test_simple_vr(self):
         ds = fake_random_ds(32)
-        im, sc = yt.volume_render(ds, fname="test.png", sigma_clip=4.0)
-        return im, sc
+        _im, _sc = yt.volume_render(ds, fname="test.png", sigma_clip=4.0)