1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-12 15:27:14 +03:00

Handover a number of Lists to Tuples

Tuples are (slightly) more efficient for comparing if x in y. Not that it'll really matter at this scale, but it's technically better and simple to implement.

Applying to all files except theme.py, because theme.py is scary.
This commit is contained in:
David Sangrey 2023-12-27 00:29:35 -05:00
parent 1976ddb0cf
commit b7633fa6e3
No known key found for this signature in database
GPG Key ID: 6A95067A0EF46336
8 changed files with 22 additions and 22 deletions

View File

@ -1547,7 +1547,7 @@ class AppWindow:
self.w.update_idletasks()
# Companion login
if entry['event'] in [None, 'StartUp', 'NewCommander', 'LoadGame'] and monitor.cmdr:
if entry['event'] in (None, 'StartUp', 'NewCommander', 'LoadGame') and monitor.cmdr:
if not config.get_list('cmdrs') or monitor.cmdr not in config.get_list('cmdrs'):
config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr])
self.login()
@ -1565,7 +1565,7 @@ class AppWindow:
logger.trace_if('journal.queue', 'Startup, returning')
return # Startup
if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
if entry['event'] in ('StartUp', 'LoadGame') and monitor.started:
logger.info('StartUp or LoadGame event')
# Disable WinSparkle automatic update checks, IFF configured to do so when in-game

View File

@ -211,12 +211,12 @@ class MacHotkeyMgr(AbstractHotkeyMgr):
return False
# BkSp, Del, Clear = clear hotkey
if keycode in [0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)]:
if keycode in (0x7f, ord(NSDeleteFunctionKey), ord(NSClearLineFunctionKey)):
self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE
return None
# don't allow keys needed for typing in System Map
if keycode in [0x13, 0x20, 0x2d] or 0x61 <= keycode <= 0x7a:
if keycode in (0x13, 0x20, 0x2d) or 0x61 <= keycode <= 0x7a:
NSBeep()
self.acquire_state = MacHotkeyMgr.ACQUIRE_INACTIVE
return None

View File

@ -284,23 +284,23 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr):
| ((GetKeyState(VK_RWIN) & 0x8000) and MOD_WIN)
keycode = event.keycode
if keycode in [VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN]:
if keycode in (VK_SHIFT, VK_CONTROL, VK_MENU, VK_LWIN, VK_RWIN):
return 0, modifiers
if not modifiers:
if keycode == VK_ESCAPE: # Esc = retain previous
return False
if keycode in [VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR]: # BkSp, Del, Clear = clear hotkey
if keycode in (VK_BACK, VK_DELETE, VK_CLEAR, VK_OEM_CLEAR): # BkSp, Del, Clear = clear hotkey
return None
if (
keycode in [VK_RETURN, VK_SPACE, VK_OEM_MINUS] or ord('A') <= keycode <= ord('Z')
keycode in (VK_RETURN, VK_SPACE, VK_OEM_MINUS) or ord('A') <= keycode <= ord('Z')
): # don't allow keys needed for typing in System Map
winsound.MessageBeep()
return None
if (keycode in [VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY]
if (keycode in (VK_NUMLOCK, VK_SCROLL, VK_PROCESSKEY)
or VK_CAPITAL <= keycode <= VK_MODECHANGE): # ignore unmodified mode switch keys
return 0, modifiers

View File

@ -79,7 +79,7 @@ def lookup(module, ship_map, entitled=False) -> dict | None: # noqa: C901, CCR0
new['rating'] = 'I'
# Skip uninteresting stuff - some no longer present in ED 3.1 cAPI data
elif (name[0] in [
elif (name[0] in (
'bobble',
'decal',
'nameplate',
@ -87,7 +87,7 @@ def lookup(module, ship_map, entitled=False) -> dict | None: # noqa: C901, CCR0
'enginecustomisation',
'voicepack',
'weaponcustomisation'
]
)
or name[1].startswith('shipkit')):
return None
@ -205,10 +205,10 @@ def lookup(module, ship_map, entitled=False) -> dict | None: # noqa: C901, CCR0
elif len(name) < 4 and name[1] == 'resourcesiphon': # Hack! 128066402 has no size or class.
(new['class'], new['rating']) = ('1', 'I')
elif len(name) < 4 and name[1] in ['guardianpowerdistributor', 'guardianpowerplant']: # Hack! No class.
elif len(name) < 4 and name[1] in ('guardianpowerdistributor', 'guardianpowerplant'): # Hack! No class.
(new['class'], new['rating']) = (str(name[2][4:]), 'A')
elif len(name) < 4 and name[1] in ['guardianfsdbooster']: # Hack! No class.
elif len(name) < 4 and name[1] == 'guardianfsdbooster': # Hack! No class.
(new['class'], new['rating']) = (str(name[2][4:]), 'H')
else:

View File

@ -165,7 +165,7 @@ def load_plugins(master: tk.Tk) -> None:
def _load_internal_plugins():
internal = []
for name in sorted(os.listdir(config.internal_plugin_dir_path)):
if name.endswith('.py') and name[0] not in ['.', '_']:
if name.endswith('.py') and name[0] not in ('.', '_'):
try:
plugin = Plugin(name[:-3], os.path.join(config.internal_plugin_dir_path, name), logger)
plugin.folder = None
@ -184,7 +184,7 @@ def _load_found_plugins():
for name in sorted(os.listdir(config.plugin_dir_path), key=lambda n: (
not os.path.isfile(os.path.join(config.plugin_dir_path, n, '__init__.py')), n.lower())):
if not os.path.isdir(os.path.join(config.plugin_dir_path, name)) or name[0] in ['.', '_']:
if not os.path.isdir(os.path.join(config.plugin_dir_path, name)) or name[0] in ('.', '_'):
pass
elif name.endswith('.disabled'):
name, discard = name.rsplit('.', 1)

View File

@ -918,7 +918,7 @@ def journal_entry( # noqa: C901, CCR001
])
# optional mission-specific properties
for (iprop, prop) in [
for (iprop, prop) in (
('missionExpiry', 'Expiry'), # Listed as optional in the docs, but always seems to be present
('starsystemNameTarget', 'DestinationSystem'),
('stationNameTarget', 'DestinationStation'),
@ -932,7 +932,7 @@ def journal_entry( # noqa: C901, CCR001
('passengerCount', 'PassengerCount'),
('passengerIsVIP', 'PassengerVIPs'),
('passengerIsWanted', 'PassengerWanted'),
]:
):
if prop in entry:
data[iprop] = entry[prop]
@ -1295,7 +1295,7 @@ def journal_entry( # noqa: C901, CCR001
# Friends
if event_name == 'Friends':
if entry['Status'] in ['Added', 'Online']:
if entry['Status'] in ('Added', 'Online'):
new_add_event(
'addCommanderFriend',
entry['timestamp'],
@ -1305,7 +1305,7 @@ def journal_entry( # noqa: C901, CCR001
}
)
elif entry['Status'] in ['Declined', 'Lost']:
elif entry['Status'] in ('Declined', 'Lost'):
new_add_event(
'delCommanderFriend',
entry['timestamp'],
@ -1666,7 +1666,7 @@ def handle_special_events(data_event: dict[str, Any], reply_event: dict[str, Any
this.lastlocation = reply_event.get('eventData', {})
if not config.shutting_down:
this.system_link.event_generate('<<InaraLocation>>', when="tail")
elif data_event['eventName'] in ['addCommanderShip', 'setCommanderShip']:
elif data_event['eventName'] in ('addCommanderShip', 'setCommanderShip'):
this.lastship = reply_event.get('eventData', {})
if not config.shutting_down:
this.system_link.event_generate('<<InaraShip>>', when="tail")

View File

@ -296,7 +296,7 @@ class OldConfig:
None,
ctypes.byref(key_size)
)
or key_type.value not in [REG_SZ, REG_MULTI_SZ]
or key_type.value not in (REG_SZ, REG_MULTI_SZ)
):
return default

View File

@ -80,10 +80,10 @@ class HyperlinkLabel(sys.platform == 'darwin' and tk.Label or ttk.Label): # typ
) -> dict[str, tuple[str, str, str, Any, Any]] | None:
"""Change cursor and appearance depending on state and text."""
# This class' state
for thing in ['url', 'popup_copy', 'underline']:
for thing in ('url', 'popup_copy', 'underline'):
if thing in kw:
setattr(self, thing, kw.pop(thing))
for thing in ['foreground', 'disabledforeground']:
for thing in ('foreground', 'disabledforeground'):
if thing in kw:
setattr(self, thing, kw[thing])