Skip to content

Commit 882f9aa

Browse files
committed
a few mypy/lint fixes
* we no longer support Python < 3.7 so importlib can be trusted * re-assigning to "dirs" confuses the typechecker * prefer "dir_" rather than redefining a builtin * fix xdg_config_home so that the value cannot be None (at least so that mypy can infer that) * use an array instead of a tuple for a value of varying length No functional change. There are other places where we try to support old Pythons which could now be cleaned up.
1 parent d38143f commit 882f9aa

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Internal
1010
--------
1111

1212
* Update sqlparse to <=0.6.0
13+
* Typing/lint fixes.
1314

1415

1516
1.30.0 (2025/04/19)

mycli/config.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from copy import copy
2+
from importlib import resources
23
from io import BytesIO, TextIOWrapper
34
import logging
45
import os
@@ -10,12 +11,6 @@
1011
from configobj import ConfigObj, ConfigObjError
1112
import pyaes
1213

13-
try:
14-
import importlib.resources as resources
15-
except ImportError:
16-
# Python < 3.7
17-
import importlib_resources as resources
18-
1914
try:
2015
basestring
2116
except NameError:
@@ -78,12 +73,12 @@ def get_included_configs(config_file: Union[str, TextIOWrapper]) -> list:
7873
try:
7974
with open(config_file) as f:
8075
include_directives = filter(lambda s: s.startswith("!includedir"), f)
81-
dirs = map(lambda s: s.strip().split()[-1], include_directives)
82-
dirs = filter(os.path.isdir, dirs)
83-
for dir in dirs:
84-
for filename in os.listdir(dir):
76+
dirs_split = map(lambda s: s.strip().split()[-1], include_directives)
77+
dirs = filter(os.path.isdir, dirs_split)
78+
for dir_ in dirs:
79+
for filename in os.listdir(dir_):
8580
if filename.endswith(".cnf"):
86-
included_configs.append(os.path.join(dir, filename))
81+
included_configs.append(os.path.join(dir_, filename))
8782
except (PermissionError, UnicodeDecodeError):
8883
pass
8984
return included_configs

mycli/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ class MyCli(object):
104104
]
105105

106106
# check XDG_CONFIG_HOME exists and not an empty string
107-
if os.environ.get("XDG_CONFIG_HOME"):
108-
xdg_config_home = os.environ.get("XDG_CONFIG_HOME")
109-
else:
110-
xdg_config_home = "~/.config"
107+
xdg_config_home = os.environ.get("XDG_CONFIG_HOME", "~/.config")
111108
system_config_files = ["/etc/myclirc", os.path.join(os.path.expanduser(xdg_config_home), "mycli", "myclirc")]
112109

113110
pwd_config_file = os.path.join(os.getcwd(), ".myclirc")

mycli/packages/filepaths.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
if os.name == "posix":
66
if platform.system() == "Darwin":
7-
DEFAULT_SOCKET_DIRS = ("/tmp",)
7+
DEFAULT_SOCKET_DIRS = ["/tmp"]
88
else:
9-
DEFAULT_SOCKET_DIRS = ("/var/run", "/var/lib")
9+
DEFAULT_SOCKET_DIRS = ["/var/run", "/var/lib"]
1010
else:
11-
DEFAULT_SOCKET_DIRS = ()
11+
DEFAULT_SOCKET_DIRS = []
1212

1313

1414
def list_path(root_dir):

0 commit comments

Comments
 (0)