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

Invalid __str__ method from makepy #2162

Open
gswifort opened this issue Dec 27, 2023 · 0 comments
Open

Invalid __str__ method from makepy #2162

gswifort opened this issue Dec 27, 2023 · 0 comments

Comments

@gswifort
Copy link

makepy generates a __str__ method, which internally calls the __call__ method. The __call__ method can take arguments, while the __str__ method does not take arguments by default - str(obj) ↔ obj.__str__().

print("\tdef __str__(self, *args):", file=stream)
print("\t\treturn str(self.__call__(*args))", file=stream)
print("\tdef __int__(self, *args):", file=stream)
print("\t\treturn int(self.__call__(*args))", file=stream)

This works incorrectly, e.g. for the COM interface of an Autocad application where __call__ requires an Index argument.

# Default method for this class is 'Item'
def __call__(self, Index=defaultNamedNotOptArg):
    'Gets the member object at a given index in a collection, group, or selection set'
    ret = self._oleobj_.InvokeTypes(0, LCID, 1, (9, 0), ((12, 1),),Index
        )
    if ret is not None:
        ret = Dispatch(ret, '__call__', '{AB9F53A4-BA00-499B-BE4C-D178EC67FFCC}')
    return ret

def __str__(self, *args):
    return str(self.__call__(*args))
def __int__(self, *args):
    return int(self.__call__(*args))

the same goes for __int__.

The __str__ and __int__ methods seem unnecessary for COM interfaces.

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

No branches or pull requests

1 participant