Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-101100: Fix sphinx warnings in howto/* #127084

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
Simple example: A descriptor that returns a constant
----------------------------------------------------

The :class:`Ten` class is a descriptor whose :meth:`__get__` method always
The ``Ten`` class is a descriptor whose :meth:`__get__` method always

Check warning on line 45 in Doc/howto/descriptor.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: __get__ [ref.meth]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the class role but add an exclamation mark then we keep the formatting of a class but don't try to resolve the reference, and get no warning:

Suggested change
The ``Ten`` class is a descriptor whose :meth:`__get__` method always
The :class:`!Ten` class is a descriptor whose :meth:`!__get__` method always

Re: https://devguide.python.org/documentation/markup/#roles

Same applies to the others in this PR.

And we can also do it for the example __get__ method here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugovk Fixed class references by using ! prefix. __get__ is documented in https://docs.python.org/3/reference/datamodel.html#object.__get__ , so I think it is better to fix __get__ to ~object.__get__.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__get__ is documented in docs.python.org/3/reference/datamodel.html#object.get , so I think it is better to fix __get__ to ~object.__get__.

Yes, good idea.

returns the constant ``10``:

.. testcode::
Expand Down Expand Up @@ -215,8 +215,8 @@
When a class uses descriptors, it can inform each descriptor about which
variable name was used.

In this example, the :class:`Person` class has two descriptor instances,
*name* and *age*. When the :class:`Person` class is defined, it makes a
In this example, the ``Person`` class has two descriptor instances,

Check warning on line 218 in Doc/howto/descriptor.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: __set_name__ [ref.meth]
*name* and *age*. When the ``Person`` class is defined, it makes a
callback to :meth:`__set_name__` in *LoggedAccess* so that the field names can
be recorded, giving each descriptor its own *public_name* and *private_name*:

Expand Down Expand Up @@ -253,7 +253,7 @@
def birthday(self):
self.age += 1

An interactive session shows that the :class:`Person` class has called
An interactive session shows that the ``Person`` class has called

Check warning on line 256 in Doc/howto/descriptor.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: __set_name__ [ref.meth]
:meth:`__set_name__` so that the field names would be recorded. Here
we call :func:`vars` to look up the descriptor without triggering it:

Expand Down Expand Up @@ -337,7 +337,7 @@
restrictions. If those restrictions aren't met, it raises an exception to
prevent data corruption at its source.

This :class:`Validator` class is both an :term:`abstract base class` and a
This ``Validator`` class is both an :term:`abstract base class` and a
managed attribute descriptor:

.. testcode::
Expand All @@ -360,22 +360,22 @@
def validate(self, value):
pass

Custom validators need to inherit from :class:`Validator` and must supply a
:meth:`validate` method to test various restrictions as needed.
Custom validators need to inherit from ``Validator`` and must supply a
``validate`` method to test various restrictions as needed.


Custom validators
-----------------

Here are three practical data validation utilities:

1) :class:`OneOf` verifies that a value is one of a restricted set of options.
1) ``OneOf`` verifies that a value is one of a restricted set of options.

2) :class:`Number` verifies that a value is either an :class:`int` or
2) ``Number`` verifies that a value is either an :class:`int` or
:class:`float`. Optionally, it verifies that a value is between a given
minimum or maximum.

3) :class:`String` verifies that a value is a :class:`str`. Optionally, it
3) ``String`` verifies that a value is a :class:`str`. Optionally, it
validates a given minimum or maximum length. It can validate a
user-defined `predicate
<https://en.wikipedia.org/wiki/Predicate_(mathematical_logic)>`_ as well.
Expand Down Expand Up @@ -873,7 +873,7 @@
conn.execute(self.store, [value, obj.key])
conn.commit()

We can use the :class:`Field` class to define `models
We can use the ``Field`` class to define `models
<https://en.wikipedia.org/wiki/Database_model>`_ that describe the schema for
each table in a database:

Expand Down Expand Up @@ -1140,7 +1140,7 @@
self.recalc()
return self._value

Either the built-in :func:`property` or our :func:`Property` equivalent would
Either the built-in :func:`property` or our ``Property`` equivalent would
work in this example.


Expand Down Expand Up @@ -1722,7 +1722,7 @@
)
super().__delattr__(name)

To use the simulation in a real class, just inherit from :class:`Object` and
To use the simulation in a real class, just inherit from ``Object`` and
set the :term:`metaclass` to :class:`Type`:

.. testcode::
Expand Down
12 changes: 6 additions & 6 deletions Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@
>>> Weekday.WEDNESDAY.value
3

Unlike many languages that treat enumerations solely as name/value pairs,

Check warning on line 78 in Doc/howto/enum.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: weekday [ref.meth]

Check warning on line 78 in Doc/howto/enum.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:meth reference target not found: isoweekday [ref.meth]

Check warning on line 78 in Doc/howto/enum.rst

View workflow job for this annotation

GitHub Actions / Docs / Docs

py:class reference target not found: date [ref.class]
Python Enums can have behavior added. For example, :class:`datetime.date`
has two methods for returning the weekday: :meth:`weekday` and :meth:`isoweekday`.
The difference is that one of them counts from 0-6 and the other from 1-7.
Rather than keep track of that ourselves we can add a method to the :class:`Weekday`
Rather than keep track of that ourselves we can add a method to the ``Weekday``
enum to extract the day from the :class:`date` instance and return the matching
enum member::

@classmethod
def from_date(cls, date):
return cls(date.isoweekday())

The complete :class:`Weekday` enum now looks like this::
The complete ``Weekday`` enum now looks like this::

>>> class Weekday(Enum):
... MONDAY = 1
Expand All @@ -110,7 +110,7 @@

Of course, if you're reading this on some other day, you'll see that day instead.

This :class:`Weekday` enum is great if our variable only needs one day, but
This ``Weekday`` enum is great if our variable only needs one day, but
what if we need several? Maybe we're writing a function to plot chores during
a week, and don't want to use a :class:`list` -- we could use a different type
of :class:`Enum`::
Expand All @@ -128,7 +128,7 @@
We've changed two things: we're inherited from :class:`Flag`, and the values are
all powers of 2.

Just like the original :class:`Weekday` enum above, we can have a single selection::
Just like the original ``Weekday`` enum above, we can have a single selection::

>>> first_week_day = Weekday.MONDAY
>>> first_week_day
Expand Down Expand Up @@ -580,7 +580,7 @@
enumerations; the others auto-assign increasing integers starting with 1 (use
the ``start`` parameter to specify a different starting value). A
new class derived from :class:`Enum` is returned. In other words, the above
assignment to :class:`Animal` is equivalent to::
assignment to ``Animal`` is equivalent to::

>>> class Animal(Enum):
... ANT = 1
Expand Down Expand Up @@ -891,7 +891,7 @@
pass

This demonstrates how similar derived enumerations can be defined; for example
a :class:`FloatEnum` that mixes in :class:`float` instead of :class:`int`.
a ``FloatEnum`` that mixes in :class:`float` instead of :class:`int`.

Some rules:

Expand Down
Loading