Skip to content

Commit 6e26ccc

Browse files
CopilotCopilot
authored andcommitted
Deploy preview for PR 1208 🛫
1 parent cb46954 commit 6e26ccc

File tree

841 files changed

+48077
-24917
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

841 files changed

+48077
-24917
lines changed

pr-preview/pr-1208/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: d6751eade72bed0b8f7a3e9e8373c012
3+
config: 429e5f11a7c447b979c1ef472ceffa09
44
tags: b5e2c454ba7771976391ed0cecdde553

pr-preview/pr-1208/_downloads/6dc1f3f4f0e6ca13cb42ddf4d6cbc8af/tzinfo_examples.py

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,70 @@
1-
from datetime import tzinfo, timedelta, datetime
2-
3-
ZERO = timedelta(0)
4-
HOUR = timedelta(hours=1)
5-
SECOND = timedelta(seconds=1)
1+
import datetime as dt
62

73
# A class capturing the platform's idea of local time.
84
# (May result in wrong values on historical times in
95
# timezones where UTC offset and/or the DST rules had
106
# changed in the past.)
11-
import time as _time
7+
import time
8+
9+
ZERO = dt.timedelta(0)
10+
HOUR = dt.timedelta(hours=1)
11+
SECOND = dt.timedelta(seconds=1)
1212

13-
STDOFFSET = timedelta(seconds = -_time.timezone)
14-
if _time.daylight:
15-
DSTOFFSET = timedelta(seconds = -_time.altzone)
13+
STDOFFSET = dt.timedelta(seconds=-time.timezone)
14+
if time.daylight:
15+
DSTOFFSET = dt.timedelta(seconds=-time.altzone)
1616
else:
1717
DSTOFFSET = STDOFFSET
1818

1919
DSTDIFF = DSTOFFSET - STDOFFSET
2020

21-
class LocalTimezone(tzinfo):
2221

23-
def fromutc(self, dt):
24-
assert dt.tzinfo is self
25-
stamp = (dt - datetime(1970, 1, 1, tzinfo=self)) // SECOND
26-
args = _time.localtime(stamp)[:6]
22+
class LocalTimezone(dt.tzinfo):
23+
24+
def fromutc(self, when):
25+
assert when.tzinfo is self
26+
stamp = (when - dt.datetime(1970, 1, 1, tzinfo=self)) // SECOND
27+
args = time.localtime(stamp)[:6]
2728
dst_diff = DSTDIFF // SECOND
2829
# Detect fold
29-
fold = (args == _time.localtime(stamp - dst_diff))
30-
return datetime(*args, microsecond=dt.microsecond,
31-
tzinfo=self, fold=fold)
30+
fold = (args == time.localtime(stamp - dst_diff))
31+
return dt.datetime(*args, microsecond=when.microsecond,
32+
tzinfo=self, fold=fold)
3233

33-
def utcoffset(self, dt):
34-
if self._isdst(dt):
34+
def utcoffset(self, when):
35+
if self._isdst(when):
3536
return DSTOFFSET
3637
else:
3738
return STDOFFSET
3839

39-
def dst(self, dt):
40-
if self._isdst(dt):
40+
def dst(self, when):
41+
if self._isdst(when):
4142
return DSTDIFF
4243
else:
4344
return ZERO
4445

45-
def tzname(self, dt):
46-
return _time.tzname[self._isdst(dt)]
46+
def tzname(self, when):
47+
return time.tzname[self._isdst(when)]
4748

48-
def _isdst(self, dt):
49-
tt = (dt.year, dt.month, dt.day,
50-
dt.hour, dt.minute, dt.second,
51-
dt.weekday(), 0, 0)
52-
stamp = _time.mktime(tt)
53-
tt = _time.localtime(stamp)
49+
def _isdst(self, when):
50+
tt = (when.year, when.month, when.day,
51+
when.hour, when.minute, when.second,
52+
when.weekday(), 0, 0)
53+
stamp = time.mktime(tt)
54+
tt = time.localtime(stamp)
5455
return tt.tm_isdst > 0
5556

57+
5658
Local = LocalTimezone()
5759

5860

5961
# A complete implementation of current DST rules for major US time zones.
6062

61-
def first_sunday_on_or_after(dt):
62-
days_to_go = 6 - dt.weekday()
63+
def first_sunday_on_or_after(when):
64+
days_to_go = 6 - when.weekday()
6365
if days_to_go:
64-
dt += timedelta(days_to_go)
65-
return dt
66+
when += dt.timedelta(days_to_go)
67+
return when
6668

6769

6870
# US DST Rules
@@ -75,21 +77,22 @@ def first_sunday_on_or_after(dt):
7577
#
7678
# In the US, since 2007, DST starts at 2am (standard time) on the second
7779
# Sunday in March, which is the first Sunday on or after Mar 8.
78-
DSTSTART_2007 = datetime(1, 3, 8, 2)
80+
DSTSTART_2007 = dt.datetime(1, 3, 8, 2)
7981
# and ends at 2am (DST time) on the first Sunday of Nov.
80-
DSTEND_2007 = datetime(1, 11, 1, 2)
82+
DSTEND_2007 = dt.datetime(1, 11, 1, 2)
8183
# From 1987 to 2006, DST used to start at 2am (standard time) on the first
8284
# Sunday in April and to end at 2am (DST time) on the last
8385
# Sunday of October, which is the first Sunday on or after Oct 25.
84-
DSTSTART_1987_2006 = datetime(1, 4, 1, 2)
85-
DSTEND_1987_2006 = datetime(1, 10, 25, 2)
86+
DSTSTART_1987_2006 = dt.datetime(1, 4, 1, 2)
87+
DSTEND_1987_2006 = dt.datetime(1, 10, 25, 2)
8688
# From 1967 to 1986, DST used to start at 2am (standard time) on the last
8789
# Sunday in April (the one on or after April 24) and to end at 2am (DST time)
8890
# on the last Sunday of October, which is the first Sunday
8991
# on or after Oct 25.
90-
DSTSTART_1967_1986 = datetime(1, 4, 24, 2)
92+
DSTSTART_1967_1986 = dt.datetime(1, 4, 24, 2)
9193
DSTEND_1967_1986 = DSTEND_1987_2006
9294

95+
9396
def us_dst_range(year):
9497
# Find start and end times for US DST. For years before 1967, return
9598
# start = end for no DST.
@@ -100,63 +103,63 @@ def us_dst_range(year):
100103
elif 1966 < year < 1987:
101104
dststart, dstend = DSTSTART_1967_1986, DSTEND_1967_1986
102105
else:
103-
return (datetime(year, 1, 1), ) * 2
106+
return (dt.datetime(year, 1, 1), ) * 2
104107

105108
start = first_sunday_on_or_after(dststart.replace(year=year))
106109
end = first_sunday_on_or_after(dstend.replace(year=year))
107110
return start, end
108111

109112

110-
class USTimeZone(tzinfo):
113+
class USTimeZone(dt.tzinfo):
111114

112115
def __init__(self, hours, reprname, stdname, dstname):
113-
self.stdoffset = timedelta(hours=hours)
116+
self.stdoffset = dt.timedelta(hours=hours)
114117
self.reprname = reprname
115118
self.stdname = stdname
116119
self.dstname = dstname
117120

118121
def __repr__(self):
119122
return self.reprname
120123

121-
def tzname(self, dt):
122-
if self.dst(dt):
124+
def tzname(self, when):
125+
if self.dst(when):
123126
return self.dstname
124127
else:
125128
return self.stdname
126129

127-
def utcoffset(self, dt):
128-
return self.stdoffset + self.dst(dt)
130+
def utcoffset(self, when):
131+
return self.stdoffset + self.dst(when)
129132

130-
def dst(self, dt):
131-
if dt is None or dt.tzinfo is None:
133+
def dst(self, when):
134+
if when is None or when.tzinfo is None:
132135
# An exception may be sensible here, in one or both cases.
133136
# It depends on how you want to treat them. The default
134137
# fromutc() implementation (called by the default astimezone()
135-
# implementation) passes a datetime with dt.tzinfo is self.
138+
# implementation) passes a datetime with when.tzinfo is self.
136139
return ZERO
137-
assert dt.tzinfo is self
138-
start, end = us_dst_range(dt.year)
140+
assert when.tzinfo is self
141+
start, end = us_dst_range(when.year)
139142
# Can't compare naive to aware objects, so strip the timezone from
140-
# dt first.
141-
dt = dt.replace(tzinfo=None)
142-
if start + HOUR <= dt < end - HOUR:
143+
# when first.
144+
when = when.replace(tzinfo=None)
145+
if start + HOUR <= when < end - HOUR:
143146
# DST is in effect.
144147
return HOUR
145-
if end - HOUR <= dt < end:
146-
# Fold (an ambiguous hour): use dt.fold to disambiguate.
147-
return ZERO if dt.fold else HOUR
148-
if start <= dt < start + HOUR:
148+
if end - HOUR <= when < end:
149+
# Fold (an ambiguous hour): use when.fold to disambiguate.
150+
return ZERO if when.fold else HOUR
151+
if start <= when < start + HOUR:
149152
# Gap (a non-existent hour): reverse the fold rule.
150-
return HOUR if dt.fold else ZERO
153+
return HOUR if when.fold else ZERO
151154
# DST is off.
152155
return ZERO
153156

154-
def fromutc(self, dt):
155-
assert dt.tzinfo is self
156-
start, end = us_dst_range(dt.year)
157+
def fromutc(self, when):
158+
assert when.tzinfo is self
159+
start, end = us_dst_range(when.year)
157160
start = start.replace(tzinfo=self)
158161
end = end.replace(tzinfo=self)
159-
std_time = dt + self.stdoffset
162+
std_time = when + self.stdoffset
160163
dst_time = std_time + HOUR
161164
if end <= dst_time < end + HOUR:
162165
# Repeated hour
Lines changed: 84 additions & 0 deletions
Loading

pr-preview/pr-1208/_sources/bugs.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ stability. In order to maintain this reputation, the developers would like to
99
know of any deficiencies you find in Python.
1010

1111
It can be sometimes faster to fix bugs yourself and contribute patches to
12-
Python as it streamlines the process and involves less people. Learn how to
12+
Python as it streamlines the process and involves fewer people. Learn how to
1313
:ref:`contribute <contributing-to-python>`.
1414

1515
Documentation bugs

pr-preview/pr-1208/_sources/c-api/bytearray.rst.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Direct API functions
4444
4545
On failure, return ``NULL`` with an exception set.
4646
47+
.. note::
48+
If the object implements the buffer protocol, then the buffer
49+
must not be mutated while the bytearray object is being created.
50+
4751
4852
.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
4953
@@ -58,6 +62,10 @@ Direct API functions
5862
5963
On failure, return ``NULL`` with an exception set.
6064
65+
.. note::
66+
If the object implements the buffer protocol, then the buffer
67+
must not be mutated while the bytearray object is being created.
68+
6169
6270
.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
6371
@@ -70,6 +78,9 @@ Direct API functions
7078
``NULL`` pointer. The returned array always has an extra
7179
null byte appended.
7280
81+
.. note::
82+
It is not thread-safe to mutate the bytearray object while using the returned char array.
83+
7384
7485
.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
7586
@@ -89,6 +100,9 @@ These macros trade safety for speed and they don't check pointers.
89100
90101
Similar to :c:func:`PyByteArray_AsString`, but without error checking.
91102
103+
.. note::
104+
It is not thread-safe to mutate the bytearray object while using the returned char array.
105+
92106
93107
.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
94108

0 commit comments

Comments
 (0)