Skip to content

Commit 5d71935

Browse files
[3.13] Docs: replace all datetime imports with import datetime as dt (GH-145640) (#146259)
Docs: replace all `datetime` imports with `import datetime as dt` (GH-145640) (cherry picked from commit 83360b5) Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 29303db commit 5d71935

25 files changed

+158
-160
lines changed

Doc/howto/enum.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ The complete :class:`!Weekday` enum now looks like this::
105105

106106
Now we can find out what today is! Observe::
107107

108-
>>> from datetime import date
109-
>>> Weekday.from_date(date.today()) # doctest: +SKIP
108+
>>> import datetime as dt
109+
>>> Weekday.from_date(dt.date.today()) # doctest: +SKIP
110110
<Weekday.TUESDAY: 2>
111111

112112
Of course, if you're reading this on some other day, you'll see that day instead.
@@ -1538,8 +1538,8 @@ TimePeriod
15381538

15391539
An example to show the :attr:`~Enum._ignore_` attribute in use::
15401540

1541-
>>> from datetime import timedelta
1542-
>>> class Period(timedelta, Enum):
1541+
>>> import datetime as dt
1542+
>>> class Period(dt.timedelta, Enum):
15431543
... "different lengths of time"
15441544
... _ignore_ = 'Period i'
15451545
... Period = vars()

Doc/howto/logging-cookbook.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,10 +1536,10 @@ to this (remembering to first import :mod:`concurrent.futures`)::
15361536
for i in range(10):
15371537
executor.submit(worker_process, queue, worker_configurer)
15381538

1539-
Deploying Web applications using Gunicorn and uWSGI
1539+
Deploying web applications using Gunicorn and uWSGI
15401540
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15411541

1542-
When deploying Web applications using `Gunicorn <https://gunicorn.org/>`_ or `uWSGI
1542+
When deploying web applications using `Gunicorn <https://gunicorn.org/>`_ or `uWSGI
15431543
<https://uwsgi-docs.readthedocs.io/en/latest/>`_ (or similar), multiple worker
15441544
processes are created to handle client requests. In such environments, avoid creating
15451545
file-based handlers directly in your web application. Instead, use a
@@ -3606,7 +3606,6 @@ detailed information.
36063606

36073607
.. code-block:: python3
36083608
3609-
import datetime
36103609
import logging
36113610
import random
36123611
import sys
@@ -3841,15 +3840,15 @@ Logging to syslog with RFC5424 support
38413840
Although :rfc:`5424` dates from 2009, most syslog servers are configured by default to
38423841
use the older :rfc:`3164`, which hails from 2001. When ``logging`` was added to Python
38433842
in 2003, it supported the earlier (and only existing) protocol at the time. Since
3844-
RFC5424 came out, as there has not been widespread deployment of it in syslog
3843+
RFC 5424 came out, as there has not been widespread deployment of it in syslog
38453844
servers, the :class:`~logging.handlers.SysLogHandler` functionality has not been
38463845
updated.
38473846

38483847
RFC 5424 contains some useful features such as support for structured data, and if you
38493848
need to be able to log to a syslog server with support for it, you can do so with a
38503849
subclassed handler which looks something like this::
38513850

3852-
import datetime
3851+
import datetime as dt
38533852
import logging.handlers
38543853
import re
38553854
import socket
@@ -3867,7 +3866,7 @@ subclassed handler which looks something like this::
38673866

38683867
def format(self, record):
38693868
version = 1
3870-
asctime = datetime.datetime.fromtimestamp(record.created).isoformat()
3869+
asctime = dt.datetime.fromtimestamp(record.created).isoformat()
38713870
m = self.tz_offset.match(time.strftime('%z'))
38723871
has_offset = False
38733872
if m and time.timezone:

Doc/includes/diff.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Command line interface to difflib.py providing diffs in four formats:
1+
""" Command-line interface to difflib.py providing diffs in four formats:
22
33
* ndiff: lists every line and highlights interline changes.
44
* context: highlights clusters of changes in a before/after format.
@@ -8,11 +8,11 @@
88
"""
99

1010
import sys, os, difflib, argparse
11-
from datetime import datetime, timezone
11+
import datetime as dt
1212

1313
def file_mtime(path):
14-
t = datetime.fromtimestamp(os.stat(path).st_mtime,
15-
timezone.utc)
14+
t = dt.datetime.fromtimestamp(os.stat(path).st_mtime,
15+
dt.timezone.utc)
1616
return t.astimezone().isoformat()
1717

1818
def main():

Doc/library/asyncio-eventloop.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.. _asyncio-event-loop:
55

66
==========
7-
Event Loop
7+
Event loop
88
==========
99

1010
**Source code:** :source:`Lib/asyncio/events.py`,
@@ -99,7 +99,7 @@ This documentation page contains the following sections:
9999

100100
.. _asyncio-event-loop-methods:
101101

102-
Event Loop Methods
102+
Event loop methods
103103
==================
104104

105105
Event loops have **low-level** APIs for the following:
@@ -355,7 +355,7 @@ clocks to track time.
355355
The :func:`asyncio.sleep` function.
356356

357357

358-
Creating Futures and Tasks
358+
Creating futures and tasks
359359
^^^^^^^^^^^^^^^^^^^^^^^^^^
360360

361361
.. method:: loop.create_future()
@@ -946,7 +946,7 @@ Transferring files
946946
.. versionadded:: 3.7
947947

948948

949-
TLS Upgrade
949+
TLS upgrade
950950
^^^^^^^^^^^
951951

952952
.. method:: loop.start_tls(transport, protocol, \
@@ -1408,7 +1408,7 @@ Executing code in thread or process pools
14081408
:class:`~concurrent.futures.ThreadPoolExecutor`.
14091409

14101410

1411-
Error Handling API
1411+
Error handling API
14121412
^^^^^^^^^^^^^^^^^^
14131413

14141414
Allows customizing how exceptions are handled in the event loop.
@@ -1511,7 +1511,7 @@ Enabling debug mode
15111511
The :ref:`debug mode of asyncio <asyncio-debug-mode>`.
15121512

15131513

1514-
Running Subprocesses
1514+
Running subprocesses
15151515
^^^^^^^^^^^^^^^^^^^^
15161516

15171517
Methods described in this subsections are low-level. In regular
@@ -1649,7 +1649,7 @@ async/await code consider using the high-level
16491649
are going to be used to construct shell commands.
16501650

16511651

1652-
Callback Handles
1652+
Callback handles
16531653
================
16541654

16551655
.. class:: Handle
@@ -1692,7 +1692,7 @@ Callback Handles
16921692
.. versionadded:: 3.7
16931693

16941694

1695-
Server Objects
1695+
Server objects
16961696
==============
16971697

16981698
Server objects are created by :meth:`loop.create_server`,
@@ -1835,7 +1835,7 @@ Do not instantiate the :class:`Server` class directly.
18351835
.. _asyncio-event-loops:
18361836
.. _asyncio-event-loop-implementations:
18371837

1838-
Event Loop Implementations
1838+
Event loop implementations
18391839
==========================
18401840

18411841
asyncio ships with two different event loop implementations:
@@ -1949,10 +1949,10 @@ callback uses the :meth:`loop.call_later` method to reschedule itself
19491949
after 5 seconds, and then stops the event loop::
19501950

19511951
import asyncio
1952-
import datetime
1952+
import datetime as dt
19531953

19541954
def display_date(end_time, loop):
1955-
print(datetime.datetime.now())
1955+
print(dt.datetime.now())
19561956
if (loop.time() + 1.0) < end_time:
19571957
loop.call_later(1, display_date, end_time, loop)
19581958
else:

Doc/library/asyncio-protocol.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ The subprocess is created by the :meth:`loop.subprocess_exec` method::
10371037
# low-level APIs.
10381038
loop = asyncio.get_running_loop()
10391039

1040-
code = 'import datetime; print(datetime.datetime.now())'
1040+
code = 'import datetime as dt; print(dt.datetime.now())'
10411041
exit_future = asyncio.Future(loop=loop)
10421042

10431043
# Create the subprocess controlled by DateProtocol;

Doc/library/asyncio-subprocess.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ function::
371371
import sys
372372

373373
async def get_date():
374-
code = 'import datetime; print(datetime.datetime.now())'
374+
code = 'import datetime as dt; print(dt.datetime.now())'
375375

376376
# Create the subprocess; redirect the standard output
377377
# into a pipe.

Doc/library/asyncio-task.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
====================
5-
Coroutines and Tasks
5+
Coroutines and tasks
66
====================
77

88
This section outlines high-level asyncio APIs to work with coroutines
@@ -231,7 +231,7 @@ A good example of a low-level function that returns a Future object
231231
is :meth:`loop.run_in_executor`.
232232

233233

234-
Creating Tasks
234+
Creating tasks
235235
==============
236236

237237
**Source code:** :source:`Lib/asyncio/tasks.py`
@@ -291,7 +291,7 @@ Creating Tasks
291291
Added the *context* parameter.
292292

293293

294-
Task Cancellation
294+
Task cancellation
295295
=================
296296

297297
Tasks can easily and safely be cancelled.
@@ -315,7 +315,7 @@ remove the cancellation state.
315315

316316
.. _taskgroups:
317317

318-
Task Groups
318+
Task groups
319319
===========
320320

321321
Task groups combine a task creation API with a convenient
@@ -414,7 +414,7 @@ reported by :meth:`asyncio.Task.cancelling`.
414414
Improved handling of simultaneous internal and external cancellations
415415
and correct preservation of cancellation counts.
416416

417-
Terminating a Task Group
417+
Terminating a task group
418418
------------------------
419419

420420
While terminating a task group is not natively supported by the standard
@@ -485,13 +485,13 @@ Sleeping
485485
for 5 seconds::
486486

487487
import asyncio
488-
import datetime
488+
import datetime as dt
489489

490490
async def display_date():
491491
loop = asyncio.get_running_loop()
492492
end_time = loop.time() + 5.0
493493
while True:
494-
print(datetime.datetime.now())
494+
print(dt.datetime.now())
495495
if (loop.time() + 1.0) >= end_time:
496496
break
497497
await asyncio.sleep(1)
@@ -506,7 +506,7 @@ Sleeping
506506
Raises :exc:`ValueError` if *delay* is :data:`~math.nan`.
507507

508508

509-
Running Tasks Concurrently
509+
Running tasks concurrently
510510
==========================
511511

512512
.. awaitablefunction:: gather(*aws, return_exceptions=False)
@@ -608,7 +608,7 @@ Running Tasks Concurrently
608608

609609
.. _eager-task-factory:
610610

611-
Eager Task Factory
611+
Eager task factory
612612
==================
613613

614614
.. function:: eager_task_factory(loop, coro, *, name=None, context=None)
@@ -651,7 +651,7 @@ Eager Task Factory
651651
.. versionadded:: 3.12
652652

653653

654-
Shielding From Cancellation
654+
Shielding from cancellation
655655
===========================
656656

657657
.. awaitablefunction:: shield(aw)
@@ -881,7 +881,7 @@ Timeouts
881881
Raises :exc:`TimeoutError` instead of :exc:`asyncio.TimeoutError`.
882882

883883

884-
Waiting Primitives
884+
Waiting primitives
885885
==================
886886

887887
.. function:: wait(aws, *, timeout=None, return_when=ALL_COMPLETED)
@@ -1001,7 +1001,7 @@ Waiting Primitives
10011001
or as a plain :term:`iterator` (previously it was only a plain iterator).
10021002

10031003

1004-
Running in Threads
1004+
Running in threads
10051005
==================
10061006

10071007
.. function:: to_thread(func, /, *args, **kwargs)
@@ -1061,7 +1061,7 @@ Running in Threads
10611061
.. versionadded:: 3.9
10621062

10631063

1064-
Scheduling From Other Threads
1064+
Scheduling from other threads
10651065
=============================
10661066

10671067
.. function:: run_coroutine_threadsafe(coro, loop)
@@ -1140,7 +1140,7 @@ Introspection
11401140

11411141
.. _asyncio-task-obj:
11421142

1143-
Task Object
1143+
Task object
11441144
===========
11451145

11461146
.. class:: Task(coro, *, loop=None, name=None, context=None, eager_start=False)

Doc/library/difflib.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
358358

359359
.. _sequence-matcher:
360360

361-
SequenceMatcher Objects
361+
SequenceMatcher objects
362362
-----------------------
363363

364364
The :class:`SequenceMatcher` class has this constructor:
@@ -586,7 +586,7 @@ are always at least as large as :meth:`~SequenceMatcher.ratio`:
586586

587587
.. _sequencematcher-examples:
588588

589-
SequenceMatcher Examples
589+
SequenceMatcher examples
590590
------------------------
591591

592592
This example compares two strings, considering blanks to be "junk":
@@ -637,7 +637,7 @@ If you want to know how to change the first sequence into the second, use
637637

638638
.. _differ-objects:
639639

640-
Differ Objects
640+
Differ objects
641641
--------------
642642

643643
Note that :class:`Differ`\ -generated deltas make no claim to be **minimal**
@@ -686,7 +686,7 @@ The :class:`Differ` class has this constructor:
686686

687687
.. _differ-examples:
688688

689-
Differ Example
689+
Differ example
690690
--------------
691691

692692
This example compares two texts. First we set up the texts, sequences of

0 commit comments

Comments
 (0)