From edc6885b3f6967df017be18a9b935f5599f10e19 Mon Sep 17 00:00:00 2001 From: Alexander Belopolsky Date: Sun, 27 Sep 2015 22:31:45 -0400 Subject: Closes issue #23600: Wrong results from tzinfo.fromutc(). --- Lib/test/datetimetester.py | 23 +++++++++++++++++++++++ Misc/NEWS | 3 +++ Modules/_datetimemodule.c | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index a942d4d..3d50fc1 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -180,6 +180,29 @@ class TestTZInfo(unittest.TestCase): self.assertEqual(derived.utcoffset(None), offset) self.assertEqual(derived.tzname(None), oname) + def test_issue23600(self): + DSTDIFF = DSTOFFSET = timedelta(hours=1) + + class UKSummerTime(tzinfo): + """Simple time zone which pretends to always be in summer time, since + that's what shows the failure. + """ + + def utcoffset(self, dt): + return DSTOFFSET + + def dst(self, dt): + return DSTDIFF + + def tzname(self, dt): + return 'UKSummerTime' + + tz = UKSummerTime() + u = datetime(2014, 4, 26, 12, 1, tzinfo=tz) + t = tz.fromutc(u) + self.assertEqual(t - t.utcoffset(), u) + + class TestTimeZone(unittest.TestCase): def setUp(self): diff --git a/Misc/NEWS b/Misc/NEWS index 6793215..63730fa 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -81,6 +81,9 @@ Core and Builtins Library ------- +- Issue #23600: Default implementation of tzinfo.fromutc() was returning + wrong results in some cases. + - Issue #25203: Failed readline.set_completer_delims() no longer left the module in inconsistent state. diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index cabe4ed..6084ffa 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -3040,7 +3040,7 @@ tzinfo_fromutc(PyDateTime_TZInfo *self, PyObject *dt) goto Fail; if (dst == Py_None) goto Inconsistent; - if (delta_bool(delta) != 0) { + if (delta_bool((PyDateTime_Delta *)dst) != 0) { PyObject *temp = result; result = add_datetime_timedelta((PyDateTime_DateTime *)result, (PyDateTime_Delta *)dst, 1); -- cgit v0.12 From 7082cbce64818f66ae9b493a0cbeb2c5d0c25e32 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 27 Sep 2015 22:46:17 -0400 Subject: Issue #24972: Inactive selection background now matches active selection background, as selected by user, on all systems. This also fixes a problem with found items not highlighted on Windows. Initial patch by Mark Roseman. Fix replaces workaround with obscure but proper configuration option. --- Lib/idlelib/EditorWindow.py | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index 74a4749..d742dd6 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -317,36 +317,6 @@ class EditorWindow(object): self.askinteger = tkSimpleDialog.askinteger self.showerror = tkMessageBox.showerror - self._highlight_workaround() # Fix selection tags on Windows - - def _highlight_workaround(self): - # On Windows, Tk removes painting of the selection - # tags which is different behavior than on Linux and Mac. - # See issue14146 for more information. - if not sys.platform.startswith('win'): - return - - text = self.text - text.event_add("<>", "") - text.event_add("<>", "") - def highlight_fix(focus): - sel_range = text.tag_ranges("sel") - if sel_range: - if focus == 'out': - HILITE_CONFIG = idleConf.GetHighlight( - idleConf.CurrentTheme(), 'hilite') - text.tag_config("sel_fix", HILITE_CONFIG) - text.tag_raise("sel_fix") - text.tag_add("sel_fix", *sel_range) - elif focus == 'in': - text.tag_remove("sel_fix", "1.0", "end") - - text.bind("<>", - lambda ev: highlight_fix("out")) - text.bind("<>", - lambda ev: highlight_fix("in")) - - def _filename_to_unicode(self, filename): """Return filename as BMP unicode so diplayable in Tk.""" # Decode bytes to unicode. @@ -785,6 +755,7 @@ class EditorWindow(object): insertbackground=cursor_color, selectforeground=select_colors['foreground'], selectbackground=select_colors['background'], + inactiveselectbackground=select_colors['background'], ) IDENTCHARS = string.ascii_letters + string.digits + "_" -- cgit v0.12 From 2122b62c2aa69886b76bb0c68fbce48afae59d0f Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 27 Sep 2015 22:50:54 -0400 Subject: Backed out changeset: 70c01dd35100 --- Lib/idlelib/EditorWindow.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index d742dd6..74a4749 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -317,6 +317,36 @@ class EditorWindow(object): self.askinteger = tkSimpleDialog.askinteger self.showerror = tkMessageBox.showerror + self._highlight_workaround() # Fix selection tags on Windows + + def _highlight_workaround(self): + # On Windows, Tk removes painting of the selection + # tags which is different behavior than on Linux and Mac. + # See issue14146 for more information. + if not sys.platform.startswith('win'): + return + + text = self.text + text.event_add("<>", "") + text.event_add("<>", "") + def highlight_fix(focus): + sel_range = text.tag_ranges("sel") + if sel_range: + if focus == 'out': + HILITE_CONFIG = idleConf.GetHighlight( + idleConf.CurrentTheme(), 'hilite') + text.tag_config("sel_fix", HILITE_CONFIG) + text.tag_raise("sel_fix") + text.tag_add("sel_fix", *sel_range) + elif focus == 'in': + text.tag_remove("sel_fix", "1.0", "end") + + text.bind("<>", + lambda ev: highlight_fix("out")) + text.bind("<>", + lambda ev: highlight_fix("in")) + + def _filename_to_unicode(self, filename): """Return filename as BMP unicode so diplayable in Tk.""" # Decode bytes to unicode. @@ -755,7 +785,6 @@ class EditorWindow(object): insertbackground=cursor_color, selectforeground=select_colors['foreground'], selectbackground=select_colors['background'], - inactiveselectbackground=select_colors['background'], ) IDENTCHARS = string.ascii_letters + string.digits + "_" -- cgit v0.12