Skip to content

Commit 0427f74

Browse files
committed
Docs: 'import datetime as dt' in examples
1 parent 149c465 commit 0427f74

25 files changed

+96
-98
lines changed

Doc/faq/programming.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,9 +1956,9 @@ parent class:
19561956

19571957
.. testcode::
19581958

1959-
from datetime import date
1959+
import datetime as dt
19601960

1961-
class FirstOfMonthDate(date):
1961+
class FirstOfMonthDate(dt.date):
19621962
"Always choose the first day of the month"
19631963
def __new__(cls, year, month, day):
19641964
return super().__new__(cls, year, month, 1)

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.
@@ -1480,8 +1480,8 @@ TimePeriod
14801480

14811481
An example to show the :attr:`~Enum._ignore_` attribute in use::
14821482

1483-
>>> from datetime import timedelta
1484-
>>> class Period(timedelta, Enum):
1483+
>>> import datetime as dt
1484+
>>> class Period(dt.timedelta, Enum):
14851485
... "different lengths of time"
14861486
... _ignore_ = 'Period i'
14871487
... Period = vars()

Doc/howto/logging-cookbook.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,7 +3616,6 @@ detailed information.
36163616

36173617
.. code-block:: python3
36183618
3619-
import datetime
36203619
import logging
36213620
import random
36223621
import sys
@@ -3851,15 +3850,15 @@ Logging to syslog with RFC5424 support
38513850
Although :rfc:`5424` dates from 2009, most syslog servers are configured by default to
38523851
use the older :rfc:`3164`, which hails from 2001. When ``logging`` was added to Python
38533852
in 2003, it supported the earlier (and only existing) protocol at the time. Since
3854-
RFC5424 came out, as there has not been widespread deployment of it in syslog
3853+
RFC 5424 came out, as there has not been widespread deployment of it in syslog
38553854
servers, the :class:`~logging.handlers.SysLogHandler` functionality has not been
38563855
updated.
38573856

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

3862-
import datetime
3861+
import datetime as dt
38633862
import logging.handlers
38643863
import re
38653864
import socket
@@ -3877,7 +3876,7 @@ subclassed handler which looks something like this::
38773876

38783877
def format(self, record):
38793878
version = 1
3880-
asctime = datetime.datetime.fromtimestamp(record.created).isoformat()
3879+
asctime = dt.datetime.fromtimestamp(record.created).isoformat()
38813880
m = self.tz_offset.match(time.strftime('%z'))
38823881
has_offset = False
38833882
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -351,7 +351,7 @@ function::
351351
import sys
352352

353353
async def get_date():
354-
code = 'import datetime; print(datetime.datetime.now())'
354+
code = 'import datetime as dt; print(dt.datetime.now())'
355355

356356
# Create the subprocess; redirect the standard output
357357
# into a pipe.

Doc/library/asyncio-task.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

Doc/library/enum.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Data Types
341341
any public methods defined on *self.__class__*::
342342

343343
>>> from enum import Enum
344-
>>> from datetime import date
344+
>>> import datetime as dt
345345
>>> class Weekday(Enum):
346346
... MONDAY = 1
347347
... TUESDAY = 2
@@ -352,7 +352,7 @@ Data Types
352352
... SUNDAY = 7
353353
... @classmethod
354354
... def today(cls):
355-
... print('today is %s' % cls(date.today().isoweekday()).name)
355+
... print(f'today is {cls(dt.date.today().isoweekday()).name}')
356356
...
357357
>>> dir(Weekday.SATURDAY)
358358
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']

Doc/library/plistlib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Examples
180180

181181
Generating a plist::
182182

183-
import datetime
183+
import datetime as dt
184184
import plistlib
185185

186186
pl = dict(
@@ -196,7 +196,7 @@ Generating a plist::
196196
),
197197
someData = b"<binary gunk>",
198198
someMoreData = b"<lots of binary gunk>" * 10,
199-
aDate = datetime.datetime.now()
199+
aDate = dt.datetime.now()
200200
)
201201
print(plistlib.dumps(pl).decode())
202202

0 commit comments

Comments
 (0)