Skip to content

Prefer bool over Literal[0, 1, None] #247

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

Merged
merged 2 commits into from
Dec 25, 2022
Merged
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
8 changes: 4 additions & 4 deletions Xlib/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, *args, **keys):
protocol_display.Display.__init__(self, *args, **keys)
self._atom_cache = {}

def get_atom(self, atomname, only_if_exists=0):
def get_atom(self, atomname, only_if_exists=False):
if atomname in self._atom_cache:
return self._atom_cache[atomname]

Expand Down Expand Up @@ -473,7 +473,7 @@ def rebind_string(self, keysym, newstring):
### X requests
###

def intern_atom(self, name, only_if_exists = 0):
def intern_atom(self, name, only_if_exists = False):
"""Intern the string name, returning its atom number. If
only_if_exists is true and the atom does not already exist, it
will not be created and X.NONE is returned."""
Expand All @@ -482,7 +482,7 @@ def intern_atom(self, name, only_if_exists = 0):
only_if_exists = only_if_exists)
return r.atom

def get_atom(self, atom, only_if_exists = 0):
def get_atom(self, atom, only_if_exists = False):
"""Alias for intern_atom, using internal cache"""
return self.display.get_atom(atom, only_if_exists)

Expand All @@ -501,7 +501,7 @@ def get_selection_owner(self, selection):
selection = selection)
return r.owner

def send_event(self, destination, event, event_mask = 0, propagate = 0,
def send_event(self, destination, event, event_mask = 0, propagate = False,
onerror = None):
"""Send a synthetic event to the window destination which can be
a window object, or X.PointerWindow or X.InputFocus. event is the
Expand Down
2 changes: 1 addition & 1 deletion Xlib/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class XError(rq.GetAttrData, Exception):
)

def __init__(self, display, data):
self._data, data = self._fields.parse_binary(data, display, rawdict = 1)
self._data, _ = self._fields.parse_binary(data, display, rawdict = True)

def __str__(self):
s = []
Expand Down
30 changes: 15 additions & 15 deletions Xlib/protocol/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def next_event(self):

# Call send_and_recv, which will return when
# something has occured
self.send_and_recv(event = 1)
self.send_and_recv(event = True)

# Before looping around, lock the event queue against
# modifications.
Expand All @@ -240,7 +240,7 @@ def pending_events(self):

# Make a send_and_recv pass, receiving any events
self.send_recv_lock.acquire()
self.send_and_recv(recv = 1)
self.send_and_recv(recv = True)

# Lock the queue, get the event count, and unlock again.
self.event_queue_write_lock.acquire()
Expand All @@ -252,7 +252,7 @@ def pending_events(self):
def flush(self):
self.check_for_error()
self.send_recv_lock.acquire()
self.send_and_recv(flush = 1)
self.send_and_recv(flush = True)

def close(self):
self.flush()
Expand Down Expand Up @@ -384,7 +384,7 @@ def close_internal(self, whom):
self.socket_error_lock.release()


def send_and_recv(self, flush = None, event = None, request = None, recv = None):
def send_and_recv(self, flush = False, event = False, request = None, recv = False):
"""send_and_recv(flush = None, event = None, request = None, recv = None)

Perform I/O, or wait for some other thread to do it for us.
Expand All @@ -402,7 +402,7 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None)
To wait for an event to be received, event should be true.

To wait for a response to a certain request (either an error
or a response), request should be set the that request's
or a response), request should be set to that request's
serial number.

To just read any pending data from the server, recv should be true.
Expand Down Expand Up @@ -689,8 +689,8 @@ def parse_response(self, request):
return self.parse_connection_setup()

# Parse ordinary server response
gotreq = 0
while 1:
gotreq = False
while True:
if self.data_recv:
# Check the first byte to find out what kind of response it is
rtype = byte2int(self.data_recv)
Expand Down Expand Up @@ -772,7 +772,7 @@ def parse_error_response(self, request):
else:
self.default_error_handler(e)

return 0
return False


def default_error_handler(self, err):
Expand Down Expand Up @@ -937,7 +937,7 @@ def parse_connection_setup(self):
# Only the ConnectionSetupRequest has been sent so far
r = self.sent_requests[0]

while 1:
while True:
# print 'data_send:', repr(self.data_send)
# print 'data_recv:', repr(self.data_recv)

Expand All @@ -946,7 +946,7 @@ def parse_connection_setup(self):

# The full response haven't arrived yet
if len(self.data_recv) < alen:
return 0
return False

# Connection failed or further authentication is needed.
# Set reason to the reason string
Expand All @@ -956,22 +956,22 @@ def parse_connection_setup(self):
# Else connection succeeded, parse the reply
else:
x, d = r._success_reply.parse_binary(self.data_recv[:alen],
self, rawdict = 1)
self, rawdict = True)
r._data.update(x)

del self.sent_requests[0]

self.data_recv = self.data_recv[alen:]

return 1
return True

else:
# The base reply is 8 bytes long
if len(self.data_recv) < 8:
return 0
return False

r._data, d = r._reply.parse_binary(self.data_recv[:8],
self, rawdict = 1)
self, rawdict = True)
self.data_recv = self.data_recv[8:]

# Loop around to see if we have got the additional data
Expand Down Expand Up @@ -1066,7 +1066,7 @@ def __init__(self, display, *args, **keys):
# Don't bother about locking, since no other threads have
# access to the display yet

display.request_queue.append((self, 1))
display.request_queue.append((self, True))

# However, we must lock send_and_recv, but we don't have
# to loop.
Expand Down
18 changes: 9 additions & 9 deletions Xlib/protocol/rq.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Field(object):
check_value = None
parse_value = None

keyword_args = 0
keyword_args = False

def __init__(self):
pass
Expand Down Expand Up @@ -724,7 +724,7 @@ def pack_value(self, value):

class ValueList(Field):
structcode = None
keyword_args = 1
keyword_args = True
default = 'usekeywords'

def __init__(self, name, mask, pad, *fields):
Expand Down Expand Up @@ -1089,7 +1089,7 @@ def pack_value(self, value):
raise BadDataError('%s is not a tuple or a list' % (value))


def parse_value(self, val, display, rawdict = 0):
def parse_value(self, val, display, rawdict = False):

"""This function is used by List and Object fields to convert
Struct objects with no var_fields into Python values.
Expand Down Expand Up @@ -1132,9 +1132,9 @@ def parse_value(self, val, display, rawdict = 0):
return DictWrapper(ret)
return ret

def parse_binary(self, data, display, rawdict = 0):
def parse_binary(self, data, display, rawdict = False):

"""values, remdata = s.parse_binary(data, display, rawdict = 0)
"""values, remdata = s.parse_binary(data, display, rawdict = False)

Convert a binary representation of the structure into Python values.

Expand Down Expand Up @@ -1355,7 +1355,7 @@ def _set_error(self, error):
return 0

class ReplyRequest(GetAttrData):
def __init__(self, display, defer = 0, *args, **keys):
def __init__(self, display, defer = False, *args, **keys):
self._display = display
self._binary = self._request.to_binary(*args, **keys)
self._serial = None
Expand All @@ -1364,7 +1364,7 @@ def __init__(self, display, defer = 0, *args, **keys):

self._response_lock = lock.allocate_lock()

self._display.send_request(self, 1)
self._display.send_request(self, True)
if not defer:
self.reply()

Expand All @@ -1390,7 +1390,7 @@ def reply(self):

def _parse_response(self, data):
self._response_lock.acquire()
self._data, d = self._reply.parse_binary(data, self._display, rawdict = 1)
self._data, d = self._reply.parse_binary(data, self._display, rawdict = True)
self._response_lock.release()

def _set_error(self, error):
Expand All @@ -1409,7 +1409,7 @@ def __init__(self, binarydata = None, display = None,
if binarydata:
self._binary = binarydata
self._data, data = self._fields.parse_binary(binarydata, display,
rawdict = 1)
rawdict = True)
# split event type into type and send_event bit
self._data['send_event'] = not not self._data['type'] & 0x80
self._data['type'] = self._data['type'] & 0x7f
Expand Down
6 changes: 3 additions & 3 deletions Xlib/xobject/drawable.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def delete_property(self, property, onerror = None):
window = self.id,
property = property)

def get_property(self, property, property_type, offset, length, delete = 0):
def get_property(self, property, property_type, offset, length, delete = False):
r = request.GetProperty(display = self.display,
delete = delete,
window = self.id,
Expand Down Expand Up @@ -516,7 +516,7 @@ def convert_selection(self, selection, target, property, time, onerror = None):
property = property,
time = time)

def send_event(self, event, event_mask = 0, propagate = 0, onerror = None):
def send_event(self, event, event_mask = 0, propagate = False, onerror = None):
request.SendEvent(display = self.display,
onerror = onerror,
propagate = propagate,
Expand Down Expand Up @@ -629,7 +629,7 @@ def set_input_focus(self, revert_to, time, onerror = None):
focus = self.id,
time = time)

def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = 0, onerror = None):
def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = False, onerror = None):
request.ClearArea(display = self.display,
onerror = onerror,
exposures = exposures,
Expand Down