Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitddf2033

Browse files
ovvingydotnet
authored andcommitted
constructor.timezone: __copy_ & __deepcopy__
close#387
1 parentfc914d5 commitddf2033

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

‎lib/yaml/constructor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def utcoffset(self, dt=None):
3838
defdst(self,dt=None):
3939
returndatetime.timedelta(0)
4040

41+
def__copy__(self):
42+
returnself.__deepcopy__()
43+
44+
def__deepcopy__(self,memodict={}):
45+
returnself.__class__(self.utcoffset())
46+
4147
__repr__=__str__=tzname
4248

4349

‎tests/lib/test_constructor.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,18 @@ def test_subclass_blacklist_types(data_filename, verbose=False):
305305

306306
test_subclass_blacklist_types.unittest= ['.subclass_blacklist']
307307

308+
deftest_timezone_copy(verbose=False):
309+
importcopy
310+
tzinfo=yaml.constructor.timezone(datetime.timedelta(0))
311+
312+
tz_copy=copy.copy(tzinfo)
313+
tz_deepcopy=copy.deepcopy(tzinfo)
314+
315+
iftzinfo.tzname()!=tz_copy.tzname()!=tz_deepcopy.tzname():
316+
raiseAssertionError("Timezones should be equal")
317+
318+
test_timezone_copy.unittest= []
319+
308320
if__name__=='__main__':
309321
importsys,test_constructor
310322
sys.modules['test_constructor']=sys.modules['__main__']

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp