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

fix IPersist.GetClassID to TYPE_CHECKING only method from Callable annotation #450

Closed
junkmd opened this issue Jan 4, 2023 · 1 comment
Labels
drop_py2 dev based on supporting only Python3, see #392 good first issue Good for newcomers

Comments

@junkmd
Copy link
Collaborator

junkmd commented Jan 4, 2023

THIS IS FOR drop_py2 PLAN! Please see #392.

Since Callable cannot tell the IDE the docstring or argument names, it should be changed to use the normal method writing style.

class IPersist(IUnknown):
_iid_ = GUID("{0000010C-0000-0000-C000-000000000046}")
_idlflags_ = []
_methods_ = [
COMMETHOD([], HRESULT, "GetClassID", (["out"], POINTER(GUID), "pClassID")),
]
if TYPE_CHECKING:
# Returns the CLSID that uniquely represents an object class that
# defines the code that can manipulate the object's data.
GetClassID: Callable[[], GUID]

A specification of the derived classes of IUnknown is below;
If the names of attributes defined from _methods_ by _cominterface_meta(and _memberspec stuffs) are duplicated in the names of already defined attributes, the names of the methods defined by the metaclasses will be prefixed with _.

# We install the method in the class, except when it's a property.
# And we make sure we don't overwrite a property that's already present.
mthname = name if not hasattr(self, name) else ("_%s" % name)

# Again, we should not overwrite class attributes that are already present.
propname = name if not hasattr(self, name) else ("_%s" % name)

So the following could be implemented as a "normal" Python method;

class IPersist(IUnknown):
    ...
    def GetClassID(self) -> GUID:
        """Returns the CLSID that uniquely represents an object class that
        defines the code that can manipulate the object's data.
        """
        return self._GetClassID()

But the IPersist.GetClassID is currently untested, and I am not sure that changing it will not result in unexpected regressions.
I will define it once under the if TYPE_CHEKING bridge, knowing that inspect will not work well enough in runtime.

@junkmd junkmd added drop_py2 dev based on supporting only Python3, see #392 good first issue Good for newcomers labels Jan 4, 2023
@junkmd
Copy link
Collaborator Author

junkmd commented Jan 4, 2023

I created this issue to serve as a "model case" for future good first issue that I will submit.

I will work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drop_py2 dev based on supporting only Python3, see #392 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant