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

Pep8 #403

Closed
wants to merge 28 commits into from
Closed

Pep8 #403

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions comtypes/GUID.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ def binary(obj):
return bytes(obj)
else:
def binary(obj):
return buffer(obj)
return buffer(obj) # NOQA

if sys.version_info >= (3, 0):
text_type = str
base_text_type = str
else:
text_type = unicode
base_text_type = basestring
text_type = unicode # NOQA
base_text_type = basestring # NOQA

BYTE = c_byte
WORD = c_ushort
Expand All @@ -28,16 +28,19 @@ def binary(obj):
_CLSIDFromProgID = _ole32.CLSIDFromProgID
_CoCreateGuid = _ole32.CoCreateGuid


# Note: Comparing GUID instances by comparing their buffers
# is slightly faster than using ole32.IsEqualGUID.

class GUID(Structure):
_fields_ = [("Data1", DWORD),
("Data2", WORD),
("Data3", WORD),
("Data4", BYTE * 8)]

def __init__(self, name=None):
_fields_ = [
("Data1", DWORD),
("Data2", WORD),
("Data3", WORD),
("Data4", BYTE * 8)
]

def __init__(self, name=None): # NOQA
if name is not None:
_CLSIDFromString(text_type(name), byref(self))

Expand All @@ -50,19 +53,23 @@ def __unicode__(self):
result = p.value
_CoTaskMemFree(p)
return result

__str__ = __unicode__

def __cmp__(self, other):
if isinstance(other, GUID):
return cmp(binary(self), binary(other))
return cmp(binary(self), binary(other)) # NOQA

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this blank line pep8-compliant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again code blocks as defined by pep8. a return can be considered the end of a logical section of code and thus a separation should be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically that whole method is incorrect as it should read

    def __cmp__(self, other):
        if isinstance(other, GUID):
            res = cmp(binary(self), binary(other))  # NOQA
        else:
            res = -1
        return res

but seeing as how the method is slated for removal anyhow it becomes a moot point. I wasn't paying attention when I added the blank line and I should have left it alone because it is going to be removed anyhow.

return -1

def __bool__(self):
return self != GUID_null

def __eq__(self, other):
return isinstance(other, GUID) and \
binary(self) == binary(other)
return (
isinstance(other, GUID) and
binary(self) == binary(other)
)

def __hash__(self):
# We make GUID instances hashable, although they are mutable.
Expand All @@ -73,10 +80,9 @@ def copy(self):

@classmethod
def from_progid(cls, progid):
"""Get guid from progid, ...
"""
"""Get guid from progid, ..."""
if hasattr(progid, "_reg_clsid_"):
progid = progid._reg_clsid_
progid = progid._reg_clsid_ # NOQA
if isinstance(progid, cls):
return progid
elif isinstance(progid, base_text_type):
Expand All @@ -89,7 +95,7 @@ def from_progid(cls, progid):
raise TypeError("Cannot construct guid from %r" % progid)

def as_progid(self):
"Convert a GUID into a progid"
"""Convert a GUID into a progid"""
progid = c_wchar_p()
_ProgIDFromCLSID(byref(self), byref(progid))
result = progid.value
Expand All @@ -98,7 +104,7 @@ def as_progid(self):

@classmethod
def create_new(cls):
"Create a brand new guid"
"""Create a brand new guid"""
guid = cls()
_CoCreateGuid(byref(guid))
return guid
Expand Down
Loading