Skip to content

Commit dfc3b9c

Browse files
BoboTiGmdomke
andauthored
Fix sphinx warnings (#35)
* chore(docs): clean-up conf.py * fix(docs): note unproperly used It also fixes this warning: Explicit markup ends without a blank line; unexpected unindent. * fix(docs): remove invalid refs (deleted methods) * fix(docs): intersphinx mapping * fix(docs): ref to `datetime` redirects to `ULID.datetime` instead of `datetime.datetime` from the Python stdlib --------- Co-authored-by: Martin Domke <mail@martindomke.net>
1 parent 59cd43d commit dfc3b9c

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Versions follow `Semantic Versioning <http://www.semver.org>`_
99
---------------------
1010
Changed
1111
~~~~~~~
12-
* Raise `TypeError` instead of `ValueError` if constructor is called with value of wrong type.
12+
* Raise ``TypeError`` instead of ``ValueError`` if constructor is called with value of wrong type.
1313
* Update ``ruff`` linter rules and switch to ``hatch fmt``.
1414

1515
Added
@@ -71,7 +71,7 @@ Added
7171
~~~~~
7272
* Added a new flag ``--uuid4`` to the CLI ``show`` command, that converts the provided ``ULID``
7373
into an RFC 4122 compliant ``UUID``.
74-
* The `ulid build` command allows the use of the special value ``-`` for all options to read its
74+
* The ``ulid build`` command allows the use of the special value ``-`` for all options to read its
7575
inputs from ``stdin``. E.g.
7676

7777
.. code-block:: bash
@@ -128,7 +128,7 @@ Changed
128128
Added
129129
~~~~~
130130
* Added support for Python 3.10.
131-
* Added :attr:`__version__` variable to package.
131+
* Added ``__version__`` variable to package.
132132

133133

134134
`1.0.3`_ - 2021-07-14
@@ -153,7 +153,7 @@ Added
153153
Changed
154154
~~~~~~~
155155
* Dropped support for Python 2. Only Python 3.6+ is supported.
156-
* The named constructor :meth:`.ULID.new` has been removed. Use one of the specifc named
156+
* The named constructor ``ULID.new`` has been removed. Use one of the specifc named
157157
constructors instead. For a new :class:`.ULID` created from the current timestamp use the
158158
standard constructor.
159159

@@ -169,8 +169,8 @@ Changed
169169
ulid = ULID.from_timestamp(time.time())
170170
ulid = ULID.from_datetime(datetime.now())
171171
172-
* The :meth:`.ULID.str` and :meth:`.ULID.int` methods have been removed in favour of the more
173-
Pythonic special dunder-methods. Use `str(ulid)` and `int(ulid)` instead.
172+
* The ``ULID.str`` and ``ULID.int`` methods have been removed in favour of the more
173+
Pythonic special dunder-methods. Use ``str(ulid)`` and ``int(ulid)`` instead.
174174
* Added the property :meth:`.ULID.hex` that returns a hex representation of the :class:`.ULID`.
175175

176176
.. code-block:: python

docs/source/conf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
copyright = f"{datetime.now(timezone.utc).year}, Martin Domke"
1313
author = "Martin Domke"
1414
master_doc = "index"
15-
source_suffix = [".rst", ".md"]
15+
source_suffix = {".rst": "restructuredtext", ".md": "restructuredtext"}
1616

1717
# The full version, including alpha/beta/rc tags
1818
release = ulid.__version__
@@ -23,6 +23,7 @@
2323
# ones.
2424
extensions = [
2525
"sphinx.ext.autodoc",
26+
"sphinx.ext.intersphinx",
2627
"sphinx.ext.napoleon",
2728
"sphinx.ext.viewcode",
2829
"sphinx_copybutton",
@@ -31,11 +32,6 @@
3132
# Add any paths that contain templates here, relative to this directory.
3233
templates_path = ["_templates"]
3334

34-
# List of patterns, relative to source directory, that match files and
35-
# directories to ignore when looking for source files.
36-
# This pattern also affects html_static_path and html_extra_path.
37-
exclude_patterns = []
38-
3935

4036
# -- Options for HTML output -------------------------------------------------
4137

@@ -76,7 +72,10 @@
7672
# Add any paths that contain custom static files (such as style sheets) here,
7773
# relative to this directory. They are copied after the builtin static files,
7874
# so a file named "default.css" will overwrite the builtin "default.css".
79-
html_static_path = ["_static"]
8075
pygments_style = "sphinx"
8176

8277
autodoc_member_order = "groupwise"
78+
# ----------------------------------------------
79+
80+
# Example configuration for intersphinx: refer to the Python standard library.
81+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}

ulid/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from __future__ import annotations
22

3+
import datetime
34
import functools
45
import os
56
import time
67
import uuid
7-
from datetime import datetime
8-
from datetime import timezone
98
from typing import Any
109
from typing import cast
1110
from typing import Generic
@@ -87,8 +86,8 @@ def __init__(self, value: bytes | None = None) -> None:
8786
)
8887

8988
@classmethod
90-
@validate_type(datetime)
91-
def from_datetime(cls, value: datetime) -> Self:
89+
@validate_type(datetime.datetime)
90+
def from_datetime(cls, value: datetime.datetime) -> Self:
9291
"""Create a new :class:`ULID`-object from a :class:`datetime`. The timestamp part of the
9392
`ULID` will be set to the corresponding timestamp of the datetime.
9493
@@ -161,8 +160,9 @@ def from_int(cls, value: int) -> Self:
161160
def parse(cls, value: Any) -> Self:
162161
"""Create a new :class:`ULID`-object from a given value.
163162
164-
.. note:: This method should only be used when the caller is trying to parse a ULID from
165-
a value when they're unsure what format/primitive type it will be given in.
163+
.. note::
164+
This method should only be used when the caller is trying to parse a ULID from
165+
a value when they're unsure what format/primitive type it will be given in.
166166
"""
167167
if isinstance(value, ULID):
168168
return cast(Self, value)
@@ -183,7 +183,7 @@ def parse(cls, value: Any) -> Self:
183183
return cls.from_timestamp(value)
184184
if isinstance(value, float):
185185
return cls.from_timestamp(value)
186-
if isinstance(value, datetime):
186+
if isinstance(value, datetime.datetime):
187187
return cls.from_datetime(value)
188188
if isinstance(value, bytes):
189189
return cls.from_bytes(value)
@@ -211,16 +211,17 @@ def timestamp(self) -> float:
211211
"""
212212
return self.milliseconds / constants.MILLISECS_IN_SECS
213213

214+
214215
@functools.cached_property
215-
def datetime(self) -> datetime:
216+
def datetime(self) -> datetime.datetime:
216217
"""Return the timestamp part as timezone-aware :class:`datetime` in UTC.
217218
218219
Examples:
219220
220221
>>> ulid.datetime
221222
datetime.datetime(2020, 4, 30, 14, 33, 27, 560000, tzinfo=datetime.timezone.utc)
222223
"""
223-
return datetime.fromtimestamp(self.timestamp, timezone.utc)
224+
return datetime.datetime.fromtimestamp(self.timestamp, datetime.timezone.utc)
224225

225226
@functools.cached_property
226227
def hex(self) -> str:

0 commit comments

Comments
 (0)