Skip to content

Commit e998179

Browse files
committed
Reworked typing
1 parent 881caee commit e998179

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

mycli/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from os.path import exists
77
import struct
88
import sys
9-
from typing import IO, BinaryIO, Literal, TextIO
9+
from typing import IO, BinaryIO, Literal
1010

1111
from configobj import ConfigObj, ConfigObjError
1212
from Cryptodome.Cipher import AES
@@ -23,7 +23,7 @@ def log(logger: logging.Logger, level: int, message: str) -> None:
2323
logger.log(level, message)
2424

2525

26-
def read_config_file(f: str | TextIO | TextIOWrapper, list_values: bool = True) -> ConfigObj | None:
26+
def read_config_file(f: str | IO[str], list_values: bool = True) -> ConfigObj | None:
2727
"""Read a config file.
2828
2929
*list_values* set to `True` is the default behavior of ConfigObj.
@@ -50,7 +50,7 @@ def read_config_file(f: str | TextIO | TextIOWrapper, list_values: bool = True)
5050
return config
5151

5252

53-
def get_included_configs(config_file: str | TextIOWrapper) -> list[str | TextIOWrapper]:
53+
def get_included_configs(config_file: str | IO[str]) -> list[str | IO[str]]:
5454
"""Get a list of configuration files that are included into config_path
5555
with !includedir directive.
5656
@@ -62,7 +62,7 @@ def get_included_configs(config_file: str | TextIOWrapper) -> list[str | TextIOW
6262
"""
6363
if not isinstance(config_file, str) or not os.path.isfile(config_file):
6464
return []
65-
included_configs: list[str | TextIOWrapper] = []
65+
included_configs: list[str | IO[str]] = []
6666

6767
try:
6868
with open(config_file) as f:
@@ -78,7 +78,7 @@ def get_included_configs(config_file: str | TextIOWrapper) -> list[str | TextIOW
7878
return included_configs
7979

8080

81-
def read_config_files(files: list[str | TextIOWrapper], list_values: bool = True) -> ConfigObj:
81+
def read_config_files(files: list[str | IO[str]], list_values: bool = True) -> ConfigObj:
8282
"""Read and merge a list of config files."""
8383

8484
config = create_default_config(list_values=list_values)

mycli/main.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
import threading
1212
import traceback
13-
from typing import Any, Generator, Iterable, Literal
13+
from typing import IO, Any, Generator, Iterable, Literal
1414

1515
try:
1616
from pwd import getpwuid
@@ -90,7 +90,7 @@ class MyCli:
9090
defaults_suffix = None
9191

9292
# In order of being loaded. Files lower in list override earlier ones.
93-
cnf_files: list[str | TextIOWrapper] = [
93+
cnf_files: list[str | IO[str]] = [
9494
"/etc/my.cnf",
9595
"/etc/mysql/my.cnf",
9696
"/usr/local/etc/my.cnf",
@@ -99,7 +99,7 @@ class MyCli:
9999

100100
# check XDG_CONFIG_HOME exists and not an empty string
101101
xdg_config_home = os.environ.get("XDG_CONFIG_HOME", "~/.config")
102-
system_config_files: list[str | TextIOWrapper] = [
102+
system_config_files: list[str | IO[str]] = [
103103
"/etc/myclirc",
104104
os.path.join(os.path.expanduser(xdg_config_home), "mycli", "myclirc"),
105105
]
@@ -134,7 +134,7 @@ def __init__(
134134
self.cnf_files = [defaults_file]
135135

136136
# Load config.
137-
config_files: list[str | TextIOWrapper] = self.system_config_files + [myclirc] + [self.pwd_config_file]
137+
config_files: list[str | IO[str]] = self.system_config_files + [myclirc] + [self.pwd_config_file]
138138
c = self.config = read_config_files(config_files)
139139
self.multi_line = c["main"].as_bool("multi_line")
140140
self.key_bindings = c["main"]["key_bindings"]
@@ -2011,11 +2011,9 @@ def thanks_picker() -> str:
20112011

20122012
with resources.files(mycli).joinpath("SPONSORS").open('r') as f:
20132013
lines += f.read()
2014-
2015-
lines = lines.split("\n")
20162014

20172015
contents = []
2018-
for line in lines:
2016+
for line in lines.split("\n"):
20192017
if m := re.match(r"^ *\* (.*)", line):
20202018
contents.append(m.group(1))
20212019
return choice(contents) if contents else 'our sponsors'

0 commit comments

Comments
 (0)