Python 3.10 improvements (#1139)

## Description

Follow-up PR for #1133 but purely esthetic, no functional changes

Cleans up the code to make it more in comformance with Python 3.10
capabilities.

Replaces:
 - type `Union` with `|`
 - type `Dict`/`Set`/`List`/`Tuple` with `dict`/`set`/`list`/`tuple`
 - `Optional` with ` | None`
 - `if:` ... `elif`... -> `match`

Fixes: 
 - `gdb.events.*Event` -> `gdb.*Event`
- `GefHeapManager.malloc_align_address` had its `ceil` lambda moved as a
proper (nested) function

Lint:
 - `except:` -> `except Exception:`
 - removed a bunch of unused f-strings
 - `if not .. in ..` -> `if .. not in ..`
 - some short named variables renamed
This commit is contained in:
crazy hugsy
2024-11-10 20:05:29 +01:00
committed by GitHub
parent 4dccd78686
commit 0f21eea18c
6 changed files with 433 additions and 431 deletions
+1
View File
@@ -14,3 +14,4 @@ debug.log
htmlcov
.benchmarks
site/
untracked/
+421 -424
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
[lint.per-file-ignores]
"gef.py" = ["E701"]
+7 -5
View File
@@ -5,7 +5,7 @@ import re
import subprocess
import tempfile
import time
from typing import Tuple
import unittest
import rpyc
@@ -109,7 +109,9 @@ pi start_rpyc_service({self._port})
return super().tearDown()
@property
def gdb_version(self) -> Tuple[int, int]:
res = [int(d) for d in re.search(r"(\d+)\D(\d+)", self._gdb.VERSION).groups()]
assert len(res) >= 2
return tuple(res)
def gdb_version(self) -> tuple[int, int]:
res = re.search(r"(\d+)\D(\d+)", self._gdb.VERSION)
assert res
groups = [int(d) for d in res.groups()]
assert len(groups) == 2
return groups[0], groups[1]
+1 -1
View File
@@ -71,5 +71,5 @@ class GefRemoteCommand(RemoteGefUnitTestGeneric):
with gdbserver_session(port=port) as _:
gdb.execute(f"target remote {GDBSERVER_DEFAULT_HOST}:{port}")
res: str = root.eval("str(gef.session.remote)")
assert res.startswith(f"RemoteSession(target=':0', local='/tmp/")
assert res.startswith("RemoteSession(target=':0', local='/tmp/")
assert res.endswith(f"pid={gef.session.pid}, mode={gdbserver_mode})")
+1 -1
View File
@@ -41,5 +41,5 @@ class ThemeCommand(RemoteGefUnitTestGeneric):
gdb.execute(f"theme {t} {v}")
res = gdb.execute(f"theme ___I_DONT_EXIST___", to_string=True)
res = gdb.execute("theme ___I_DONT_EXIST___", to_string=True)
self.assertIn("Invalid key", res)