Skip to content

Commit

Permalink
Merge pull request #68 from enthought/fix/empty-string-variant
Browse files Browse the repository at this point in the history
Do not convert empty string to NULL VARIANT.
  • Loading branch information
cfarrow committed Sep 3, 2014
2 parents 6287c9b + 340f0a7 commit 35a25a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion comtypes/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions comtypes/test/test_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 35a25a9

Please sign in to comment.