summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rw-r--r--doc/extdev/deprecated.rst10
-rw-r--r--sphinx/testing/path.py19
3 files changed, 31 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index a3f88000b..226421776 100644
--- a/CHANGES
+++ b/CHANGES
@@ -27,6 +27,8 @@ Deprecated
----------
* ``sphinx.domains.std.StandardDomain.add_object()``
+* ``sphinx.testing.path.Path.text()``
+* ``sphinx.testing.path.Path.bytes()``
Features added
--------------
diff --git a/doc/extdev/deprecated.rst b/doc/extdev/deprecated.rst
index 50b683d09..a1528b763 100644
--- a/doc/extdev/deprecated.rst
+++ b/doc/extdev/deprecated.rst
@@ -31,6 +31,16 @@ The following is a list of deprecated interfaces.
- 5.0
- ``sphinx.domains.std.StandardDomain.note_object()``
+ * - ``sphinx.testing.path.Path.text()``
+ - 3.0
+ - 5.0
+ - ``sphinx.testing.path.Path.read_text()``
+
+ * - ``sphinx.testing.path.Path.bytes()``
+ - 3.0
+ - 5.0
+ - ``sphinx.testing.path.Path.read_bytes()``
+
* - ``decode`` argument of ``sphinx.pycode.ModuleAnalyzer()``
- 2.4
- 4.0
diff --git a/sphinx/testing/path.py b/sphinx/testing/path.py
index 1c883af2f..4c3702e3d 100644
--- a/sphinx/testing/path.py
+++ b/sphinx/testing/path.py
@@ -10,8 +10,11 @@ import builtins
import os
import shutil
import sys
+import warnings
from typing import Any, Callable, IO, List
+from sphinx.deprecation import RemovedInSphinx50Warning
+
FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding()
@@ -138,6 +141,14 @@ class path(str):
"""
Returns the text in the file.
"""
+ warnings.warn('Path.text() is deprecated. Please use read_text() instead.',
+ RemovedInSphinx50Warning, stacklevel=2)
+ return self.read_text(encoding, **kwargs)
+
+ def read_text(self, encoding: str = 'utf-8', **kwargs: Any) -> str:
+ """
+ Returns the text in the file.
+ """
with open(self, encoding=encoding, **kwargs) as f:
return f.read()
@@ -145,6 +156,14 @@ class path(str):
"""
Returns the bytes in the file.
"""
+ warnings.warn('Path.bytes() is deprecated. Please use read_bytes() instead.',
+ RemovedInSphinx50Warning, stacklevel=2)
+ return self.read_bytes()
+
+ def read_bytes(self) -> builtins.bytes:
+ """
+ Returns the bytes in the file.
+ """
with open(self, mode='rb') as f:
return f.read()