SF.net SVN: docutils:[9804 ] trunk/docutils/docutils
aa-turner--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9804
http://sourceforge.net/p/docutils/code/9804
Author: aa-turner
Date: 2024-07-31 10:44:49 +0000 (Wed, 31 Jul 2024)
Log Message:
-----------
Add type hints to ``docutils.examples``
Modified Paths:
--------------
trunk/docutils/docutils/core.py
trunk/docutils/docutils/examples.py
Modified: trunk/docutils/docutils/core.py
===================================================================
--- trunk/docutils/docutils/core.py 2024-07-31 10:21:02 UTC (rev 9803)
+++ trunk/docutils/docutils/core.py 2024-07-31 10:44:49 UTC (rev 9804)
@@ -192,10 +192,15 @@
if self.destination is None:
self.set_destination(destination_path=destination_path)
- def set_source(self, source=None, source_path=None):
+ def set_source(
+ self,
+ source: str | None = None,
+ source_path: str | os.PathLike[str] | None = None,
+ ) -> None:
if source_path is None:
source_path = self.settings._source
else:
+ source_path = os.fspath(source_path)
self.settings._source = source_path
self.source = self.source_class(
source=source, source_path=source_path,
@@ -202,7 +207,11 @@
encoding=self.settings.input_encoding,
error_handler=self.settings.input_encoding_error_handler)
- def set_destination(self, destination=None, destination_path=None):
+ def set_destination(
+ self,
+ destination: str | None = None,
+ destination_path: str | os.PathLike[str] | None = None,
+ ) -> None:
if destination_path is None:
if (self.settings.output and self.settings._destination
and self.settings.output != self.settings._destination):
@@ -213,6 +222,8 @@
self.settings.output = None
destination_path = (self.settings.output
or self.settings._destination)
+ else:
+ destination_path = os.fspath(destination_path)
self.settings._destination = destination_path
self.destination = self.destination_class(
destination=destination,
Modified: trunk/docutils/docutils/examples.py
===================================================================
--- trunk/docutils/docutils/examples.py 2024-07-31 10:21:02 UTC (rev 9803)
+++ trunk/docutils/docutils/examples.py 2024-07-31 10:44:49 UTC (rev 9804)
@@ -11,12 +11,28 @@
necessary.
"""
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
+
from docutils import core, io
+if TYPE_CHECKING:
+ import os
+ from typing import Any, Literal
-def html_parts(input_string, source_path=None, destination_path=None,
- input_encoding='unicode', doctitle=True,
- initial_header_level=1):
+ from docutils import nodes
+ from docutils.core import Publisher
+
+
+def html_parts(
+ input_string: str | bytes,
+ source_path: str | os.PathLike[str] | None = None,
+ destination_path: str | os.PathLike[str] | None = None,
+ input_encoding: Literal['unicode'] | str = 'unicode',
+ doctitle: bool = True,
+ initial_header_level: int = 1,
+) -> dict[str, str]:
"""
Given an input string, returns a dictionary of HTML document parts.
@@ -50,9 +66,15 @@
return parts
-def html_body(input_string, source_path=None, destination_path=None,
- input_encoding='unicode', output_encoding='unicode',
- doctitle=True, initial_header_level=1):
+def html_body(
+ input_string: str | bytes,
+ source_path: str | os.PathLike[str] | None = None,
+ destination_path: str | os.PathLike[str] | None = None,
+ input_encoding: Literal['unicode'] | str = 'unicode',
+ output_encoding: Literal['unicode'] | str = 'unicode',
+ doctitle: bool = True,
+ initial_header_level: int = 1,
+) -> str | bytes:
"""
Given an input string, returns an HTML fragment as a string.
@@ -74,8 +96,12 @@
return fragment
-def internals(source, source_path=None, destination_path=None,
- input_encoding='unicode', settings_overrides=None):
+def internals(
+ source: str,
+ source_path: str | os.PathLike[str] | None = None,
+ input_encoding: Literal['unicode'] | str = 'unicode',
+ settings_overrides: dict[str, Any] | None = None,
+) -> tuple[nodes.document, Publisher]:
"""
Return the document tree and publisher, for exploring Docutils internals.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.