Skip to content

Commit 67505b4

Browse files
authored
chore: reduce usage of global keyword (#295)
1 parent 6bf089b commit 67505b4

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

adbe/adb_helper.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dataclasses
12
import functools
23
import subprocess
34

@@ -10,6 +11,13 @@
1011
from output_helper import print_error, print_error_and_exit, print_verbose
1112

1213

14+
@dataclasses.dataclass
15+
class _Settings:
16+
adb_prefix: str = "adb"
17+
18+
19+
__settings = _Settings()
20+
1321
_adb_prefix = "adb"
1422
_IGNORED_LINES = [
1523
"WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.",
@@ -20,13 +28,11 @@
2028

2129

2230
def get_adb_prefix() -> str:
23-
return _adb_prefix
31+
return __settings.adb_prefix
2432

2533

2634
def set_adb_prefix(adb_prefix: str) -> None:
27-
# pylint: disable=global-statement
28-
global _adb_prefix
29-
_adb_prefix = adb_prefix
35+
__settings.adb_prefix = adb_prefix
3036

3137

3238
def get_adb_shell_property(property_name: str, device_serial=None) -> str | None:

adbe/output_helper.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
import dataclasses
2+
import functools
13
import sys
24

3-
__VERBOSE_MODE: bool = False
5+
6+
@dataclasses.dataclass
7+
class _Settings:
8+
"""Settings for the output helper."""
9+
verbose: bool = False
10+
11+
12+
__settings = _Settings()
413

514

615
def set_verbose(*, enabled: bool) -> None:
7-
global __VERBOSE_MODE
8-
__VERBOSE_MODE = enabled
16+
__settings.verbose = enabled
917

1018

1119
def print_message(message: str) -> None:
@@ -25,12 +33,13 @@ def print_error(error_string: str) -> None:
2533

2634

2735
def print_verbose(message: str) -> None:
28-
if __VERBOSE_MODE and _is_interactive_terminal():
36+
if __settings.verbose and _is_interactive_terminal():
2937
print(f"{BashColors.WARNING}{message}{BashColors.ENDC}")
3038
else:
3139
print(message)
3240

3341

42+
@functools.lru_cache
3443
def _is_interactive_terminal() -> bool:
3544
return sys.stdout.isatty()
3645

0 commit comments

Comments
 (0)