From 340f0a718be7a228db6ebaa3fdd729c31c857b01 Mon Sep 17 00:00:00 2001 From: "Christopher L. Farrow" Date: Sun, 17 Aug 2014 17:30:51 -0500 Subject: [PATCH] Do not convert empty string to NULL VARIANT. --- comtypes/automation.py | 3 ++- comtypes/test/test_variant.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/comtypes/automation.py b/comtypes/automation.py index 695a2aa0..2bb54d2f 100644 --- a/comtypes/automation.py +++ b/comtypes/automation.py @@ -218,7 +218,8 @@ def _set_value(self, value): _VariantClear(self) if value is None: self.vt = VT_NULL - elif hasattr(value, '__len__') and len(value) == 0: + elif (hasattr(value, '__len__') and len(value) == 0 + and not isinstance(value, basestring)): self.vt = VT_NULL # since bool is a subclass of int, this check must come before # the check for int diff --git a/comtypes/test/test_variant.py b/comtypes/test/test_variant.py index 3a825da1..2fd2b536 100644 --- a/comtypes/test/test_variant.py +++ b/comtypes/test/test_variant.py @@ -176,6 +176,11 @@ def test_BSTR(self): v.vt = VT_BSTR self.failUnless(v.value in ("", None)) + def test_empty_BSTR(self): + v = VARIANT() + v.value = "" + self.assertEqual(v.vt, VT_BSTR) + def test_UDT(self): from comtypes.gen.TestComServerLib import MYCOLOR v = VARIANT(MYCOLOR(red=1.0, green=2.0, blue=3.0))