Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for named arguments and default argument values #371

Open
junkmd opened this issue Nov 7, 2022 · 0 comments
Open

support for named arguments and default argument values #371

junkmd opened this issue Nov 7, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@junkmd
Copy link
Collaborator

junkmd commented Nov 7, 2022

'named arguments' feature is 'should be added' since 16 years ago, according to commented(938fbd5) by Thomas Heller, the originator of this package.

# a first attempt to make use of the restype. Still, support
# for named arguments and default argument values should be
# added.

Also, bound_named_property.__call__ should support them.

class bound_named_property(object):
def __init__(self, name, fget, fset, instance):
self.name = name
self.instance = instance
self.fget = fget
self.fset = fset
def __getitem__(self, index):
if self.fget is None:
raise TypeError("unsubscriptable object")
if isinstance(index, tuple):
return self.fget(self.instance, *index)
elif index == _all_slice:
return self.fget(self.instance)
else:
return self.fget(self.instance, index)
def __call__(self, *args):
if self.fget is None:
raise TypeError("object is not callable")
return self.fget(self.instance, *args)

If this functionality is added, this code snippet will work!

xl = CreateObject("Excel.Application")
wb = xl.Workbooks.Add()
assert xl.Range["A1:C3"].Address() == "$A$1:$C$3"   # it is possible before the functionality is added
assert xl.Range["A1:C3"].Address(None, None) == "$A$1:$C$3"  # it is possible before the functionality is added
assert xl.Range["A1:C3"].Address(ColumnAbsolute=False) == "A$1:C$3"  # not wroking currently, I want THIS
assert xl.Range["A1:C3"].Address(None, False) == "A$1:C$3"   # it is possible before the functionality is added
assert xl.Range["A1:C3"].Address(None, ColumnAbsolute=False) == "A$1:C$3"  # not wroking currently, I want THIS
assert xl.Range["A1:C3"].Address(RowAbsolute=False) == "$A1:$C3"  # not wroking currently, I want THIS
assert xl.Range["A1:C3"].Address(ReferenceStyle=xlR1C1) == "R1C1:R3C3"  # not wroking currently, I want THIS

_DispMemberSpec has argspec, so I think it may be easy to get names and default values.

comtypes/comtypes/__init__.py

Lines 1131 to 1138 in dbe4fa1

class _DispMemberSpec(_MemberSpec):
"""Specifier for a slot of dispinterface method or property."""
__slots__ = ("what", "argspec")
def __init__(self, what, name, idlflags, restype, argspec):
self.what = what # type: str
self.argspec = argspec # type: Tuple[ArgSpecElmType, ...]
super(_DispMemberSpec, self).__init__(name, idlflags, restype)

comtypes/comtypes/__init__.py

Lines 1155 to 1161 in dbe4fa1

def DISPMETHOD(idlflags, restype, name, *argspec):
"Specifies a method of a dispinterface"
return _DispMemberSpec("DISPMETHOD", name, tuple(idlflags), restype, argspec)
def DISPPROPERTY(idlflags, proptype, name):
"Specifies a property of a dispinterface"
return _DispMemberSpec("DISPPROPERTY", name, tuple(idlflags), proptype, ())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants