Skip to content

Commit d65e8d9

Browse files
[3.14] Docs: replace all datetime imports with import datetime as dt (GH-145640) (#146258)
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 9737ce2 commit d65e8d9

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
@@ -1549,10 +1549,10 @@ to this (remembering to first import :mod:`concurrent.futures`)::
15491549
for i in range(10):
15501550
executor.submit(worker_process, queue, worker_configurer)
15511551

1552-
Deploying Web applications using Gunicorn and uWSGI
1552+
Deploying web applications using Gunicorn and uWSGI
15531553
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15541554

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

36203620
.. code-block:: python3
36213621
3622-
import datetime
36233622
import logging
36243623
import random
36253624
import sys
@@ -3854,15 +3853,15 @@ Logging to syslog with RFC5424 support
38543853
Although :rfc:`5424` dates from 2009, most syslog servers are configured by default to
38553854
use the older :rfc:`3164`, which hails from 2001. When ``logging`` was added to Python
38563855
in 2003, it supported the earlier (and only existing) protocol at the time. Since
3857-
RFC5424 came out, as there has not been widespread deployment of it in syslog
3856+
RFC 5424 came out, as there has not been widespread deployment of it in syslog
38583857
servers, the :class:`~logging.handlers.SysLogHandler` functionality has not been
38593858
updated.
38603859

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

3865-
import datetime
3864+
import datetime as dt
38663865
import logging.handlers
38673866
import re
38683867
import socket
@@ -3880,7 +3879,7 @@ subclassed handler which looks something like this::
38803879

38813880
def format(self, record):
38823881
version = 1
3883-
asctime = datetime.datetime.fromtimestamp(record.created).isoformat()
3882+
asctime = dt.datetime.fromtimestamp(record.created).isoformat()
38843883
m = self.tz_offset.match(time.strftime('%z'))
38853884
has_offset = False
38863885
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`,
@@ -105,7 +105,7 @@ This documentation page contains the following sections:
105105

106106
.. _asyncio-event-loop-methods:
107107

108-
Event Loop Methods
108+
Event loop methods
109109
==================
110110

111111
Event loops have **low-level** APIs for the following:
@@ -361,7 +361,7 @@ clocks to track time.
361361
The :func:`asyncio.sleep` function.
362362

363363

364-
Creating Futures and Tasks
364+
Creating futures and tasks
365365
^^^^^^^^^^^^^^^^^^^^^^^^^^
366366

367367
.. method:: loop.create_future()
@@ -962,7 +962,7 @@ Transferring files
962962
.. versionadded:: 3.7
963963

964964

965-
TLS Upgrade
965+
TLS upgrade
966966
^^^^^^^^^^^
967967

968968
.. method:: loop.start_tls(transport, protocol, \
@@ -1431,7 +1431,7 @@ Executing code in thread or process pools
14311431
:class:`~concurrent.futures.ThreadPoolExecutor`.
14321432

14331433

1434-
Error Handling API
1434+
Error handling API
14351435
^^^^^^^^^^^^^^^^^^
14361436

14371437
Allows customizing how exceptions are handled in the event loop.
@@ -1534,7 +1534,7 @@ Enabling debug mode
15341534
The :ref:`debug mode of asyncio <asyncio-debug-mode>`.
15351535

15361536

1537-
Running Subprocesses
1537+
Running subprocesses
15381538
^^^^^^^^^^^^^^^^^^^^
15391539

15401540
Methods described in this subsections are low-level. In regular
@@ -1672,7 +1672,7 @@ async/await code consider using the high-level
16721672
are going to be used to construct shell commands.
16731673

16741674

1675-
Callback Handles
1675+
Callback handles
16761676
================
16771677

16781678
.. class:: Handle
@@ -1715,7 +1715,7 @@ Callback Handles
17151715
.. versionadded:: 3.7
17161716

17171717

1718-
Server Objects
1718+
Server objects
17191719
==============
17201720

17211721
Server objects are created by :meth:`loop.create_server`,
@@ -1858,7 +1858,7 @@ Do not instantiate the :class:`Server` class directly.
18581858
.. _asyncio-event-loops:
18591859
.. _asyncio-event-loop-implementations:
18601860

1861-
Event Loop Implementations
1861+
Event loop implementations
18621862
==========================
18631863

18641864
asyncio ships with two different event loop implementations:
@@ -1971,10 +1971,10 @@ callback uses the :meth:`loop.call_later` method to reschedule itself
19711971
after 5 seconds, and then stops the event loop::
19721972

19731973
import asyncio
1974-
import datetime
1974+
import datetime as dt
19751975

19761976
def display_date(end_time, loop):
1977-
print(datetime.datetime.now())
1977+
print(dt.datetime.now())
19781978
if (loop.time() + 1.0) < end_time:
19791979
loop.call_later(1, display_date, end_time, loop)
19801980
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
@@ -359,7 +359,7 @@ function::
359359
import sys
360360

361361
async def get_date():
362-
code = 'import datetime; print(datetime.datetime.now())'
362+
code = 'import datetime as dt; print(dt.datetime.now())'
363363

364364
# Create the subprocess; redirect the standard output
365365
# 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`
@@ -300,7 +300,7 @@ Creating Tasks
300300
Added the *eager_start* parameter by passing on all *kwargs*.
301301

302302

303-
Task Cancellation
303+
Task cancellation
304304
=================
305305

306306
Tasks can easily and safely be cancelled.
@@ -324,7 +324,7 @@ remove the cancellation state.
324324

325325
.. _taskgroups:
326326

327-
Task Groups
327+
Task groups
328328
===========
329329

330330
Task groups combine a task creation API with a convenient
@@ -427,7 +427,7 @@ reported by :meth:`asyncio.Task.cancelling`.
427427
Improved handling of simultaneous internal and external cancellations
428428
and correct preservation of cancellation counts.
429429

430-
Terminating a Task Group
430+
Terminating a task group
431431
------------------------
432432

433433
While terminating a task group is not natively supported by the standard
@@ -498,13 +498,13 @@ Sleeping
498498
for 5 seconds::
499499

500500
import asyncio
501-
import datetime
501+
import datetime as dt
502502

503503
async def display_date():
504504
loop = asyncio.get_running_loop()
505505
end_time = loop.time() + 5.0
506506
while True:
507-
print(datetime.datetime.now())
507+
print(dt.datetime.now())
508508
if (loop.time() + 1.0) >= end_time:
509509
break
510510
await asyncio.sleep(1)
@@ -519,7 +519,7 @@ Sleeping
519519
Raises :exc:`ValueError` if *delay* is :data:`~math.nan`.
520520

521521

522-
Running Tasks Concurrently
522+
Running tasks concurrently
523523
==========================
524524

525525
.. awaitablefunction:: gather(*aws, return_exceptions=False)
@@ -621,7 +621,7 @@ Running Tasks Concurrently
621621

622622
.. _eager-task-factory:
623623

624-
Eager Task Factory
624+
Eager task factory
625625
==================
626626

627627
.. function:: eager_task_factory(loop, coro, *, name=None, context=None)
@@ -664,7 +664,7 @@ Eager Task Factory
664664
.. versionadded:: 3.12
665665

666666

667-
Shielding From Cancellation
667+
Shielding from cancellation
668668
===========================
669669

670670
.. awaitablefunction:: shield(aw)
@@ -894,7 +894,7 @@ Timeouts
894894
Raises :exc:`TimeoutError` instead of :exc:`asyncio.TimeoutError`.
895895

896896

897-
Waiting Primitives
897+
Waiting primitives
898898
==================
899899

900900
.. function:: wait(aws, *, timeout=None, return_when=ALL_COMPLETED)
@@ -1014,7 +1014,7 @@ Waiting Primitives
10141014
or as a plain :term:`iterator` (previously it was only a plain iterator).
10151015

10161016

1017-
Running in Threads
1017+
Running in threads
10181018
==================
10191019

10201020
.. function:: to_thread(func, /, *args, **kwargs)
@@ -1074,7 +1074,7 @@ Running in Threads
10741074
.. versionadded:: 3.9
10751075

10761076

1077-
Scheduling From Other Threads
1077+
Scheduling from other threads
10781078
=============================
10791079

10801080
.. function:: run_coroutine_threadsafe(coro, loop)
@@ -1198,7 +1198,7 @@ Introspection
11981198

11991199
.. _asyncio-task-obj:
12001200

1201-
Task Object
1201+
Task object
12021202
===========
12031203

12041204
.. 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)