Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d2423d

Browse files
authored
Merge pull request jalanb#52 from jalanb/typing
Typing
2 parents 6ec706a + 78bd2af commit 0d2423d

24 files changed

+240
-207
lines changed

.pylintrc

Lines changed: 0 additions & 58 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: python
22
python:
3-
- '3.7'
3+
- '3.9'
44
install: pip install tox codecov
55
script: tox
66
after_success:

pysyte/bash/shell.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
from contextlib import contextmanager
55
from subprocess import getstatusoutput
6+
from typing import List
67

78
from boltons.setutils import IndexedSet
89

@@ -11,8 +12,8 @@ class BashError(ValueError):
1112
pass
1213

1314

14-
_working_dirs = [""]
15-
_path = []
15+
_working_dirs: List[str] = [""]
16+
_path: List[str] = []
1617

1718

1819
def cd(path):

pysyte/cli/arguments.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from bdb import BdbQuit
1212
from pprint import pformat
1313
from functools import partial
14+
from typing import Any
15+
from typing import List
1416

1517
import stackprinter
1618
from deprecated import deprecated
@@ -24,7 +26,7 @@ def config(arguments):
2426
return load_configs(arguments.prog)
2527

2628

27-
def extract_strings(names, name):
29+
def extract_strings(names: dict, name: str) -> List[str]:
2830
try:
2931
value = names[name]
3032
except KeyError:
@@ -143,24 +145,22 @@ def __repr__(self):
143145
repr_ = "\n".join((klass, cmd_, args))
144146
return f"<{repr_}>"
145147

146-
def __getattr__(self, name):
148+
def __getattr__(self, name) -> Any:
147149
return getattr(self._result, name)
148150

149-
def get_args(self):
151+
def get_args(self) -> dict:
150152
attributes = [a for a in dir(self._result) if a[0] != "_"]
151153
return {a: getattr(self._result, a) for a in attributes}
152154

153-
def get_arg(self, name):
154-
if not self._result:
155-
return None
156-
return getattr(self._result, name)
155+
def get_arg(self, name: str) -> Any:
156+
return getattr(self._result, name, None)
157157

158-
def get_strings(self, name):
158+
def get_strings(self, name: str) -> List[str]:
159159
if not self._result:
160-
return None
160+
return []
161161
return extract_strings(self._result.__dict__, name)
162162

163-
def set_arg(self, name, value):
163+
def set_arg(self, name: str, value: Any) -> None:
164164
setattr(self._result, name, value)
165165

166166

@@ -177,7 +177,7 @@ def run(self, caller):
177177
return os.X_OK
178178
except SystemExit as e:
179179
return e.code
180-
except Exception as e: # pylint: disable=broad-except
180+
except Exception as e:
181181
stackprinter.show(e, style=pysyte.stackprinter.style)
182182

183183

pysyte/cli/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Optional
44
from typing import List
55

6-
import pysyte
6+
from pysyte import __file__ as path_to_pysyte
77
from pysyte.oss import linux
88
from pysyte.config.types import ConfigPaths
99
from pysyte.types.dictionaries import NameSpaces
@@ -37,7 +37,7 @@ def add_dir(value: str):
3737
elif expanded.isfile():
3838
configs.append(expanded.parent)
3939

40-
configs = []
40+
configs: List[DirectPath] = []
4141
add_dir("/etc")
4242
for path_ in linux.xdg_dirs():
4343
add_dir(path_)
@@ -54,4 +54,4 @@ def load_configs(name: str, extras: Optional[list] = None) -> NameSpaces:
5454
return config_paths.load(name)
5555

5656

57-
pysyte = load_configs("pysyte", [path(pysyte.__file__)])
57+
pysyte = load_configs("pysyte", [path(path_to_pysyte)])

pysyte/cli/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import sys
88
from dataclasses import dataclass
9+
from typing import Any
10+
from typing import Dict
911
from typing import Optional
1012

1113

@@ -28,17 +30,18 @@ def __call__(self, *args_, **kwargs):
2830
return self.method(*args_, **kwargs)
2931

3032

33+
ParseCaller = Callable[[arguments.ArgumentsParser], arguments.ArgumentsParser]
34+
35+
3136
@dataclass
3237
class CallerData:
3338
method: MainMethod
34-
add_args: Callable
39+
add_args: Optional[ParseCaller]
3540

3641

3742
def run(
3843
main_method: Callable,
39-
add_args: Optional[
40-
Callable[[arguments.ArgumentsParser], arguments.ArgumentsParser]
41-
] = None,
44+
add_args: Optional[ParseCaller] = None,
4245
post_parse: Optional[Callable] = None,
4346
usage: Optional[str] = None,
4447
epilog: Optional[str] = None,
@@ -101,4 +104,4 @@ def main(self, argument_handler):
101104
sys.exit(handler.run(caller))
102105

103106

104-
args = {}
107+
args: Dict[str, Any] = {}

pysyte/decorators.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

pysyte/iteration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def last(sequence: Sequence[T], message=None) -> T:
2626
2727
>>> assert last([1, 2, 3]) == 3
2828
"""
29-
return first(reversed(sequence), message)
29+
return first(list(reversed(sequence)), message)
3030

3131

3232
def first_or(sequence: Sequence[T], value) -> T:
@@ -49,6 +49,6 @@ def first_that(predicate, sequence: Sequence[T], message=None) -> T:
4949
>>> assert first_that(lambda x: x > 1, [1, 2, 3]) == 2
5050
"""
5151
try:
52-
return first(_ for _ in sequence if predicate(_))
52+
return first([_ for _ in sequence if predicate(_)])
5353
except (ValueError, StopIteration):
5454
raise KeyError(message or "Not Found")

pysyte/net/hosts.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
import getpass
44
import socket
55
from dataclasses import dataclass
6+
from typing import List
67

78

89
@dataclass
910
class Host:
1011
hostname: str
11-
aliases: list
12-
addresses: list
13-
users: list
12+
aliases: List[str]
13+
addresses: List[str]
14+
users: List[str]
1415

1516

16-
localhost = Host(
17-
*(list(socket.gethostbyname_ex(socket.gethostname())) + [getpass.getuser()])
18-
)
17+
def _read_localhost() -> Host:
18+
"""Read host values for localhost"""
19+
host, aliases, addresses = socket.gethostbyname_ex(socket.gethostname())
20+
user = getpass.getuser()
21+
return Host(host, aliases, addresses, [user])
22+
23+
24+
localhost = _read_localhost()

pysyte/oss/getch.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import sys
1818
import tty
1919
from curses import ascii
20+
from typing import Dict
21+
from typing import List
22+
from typing import Tuple
2023

2124
import termios
2225
from deprecated import deprecated
@@ -36,7 +39,6 @@ def get_ord():
3639
class TerminalContext(object):
3740
"""Context wrapper to set up termios values"""
3841

39-
# pylint: disable=too-few-public-methods
4042
def __init__(self):
4143
self.fd = None
4244
self.old_settings = None
@@ -70,7 +72,6 @@ def timeout_raiser(_signum, _frame):
7072
class TimerContext(object):
7173
"""Context wrapper for a timeout"""
7274

73-
# pylint: disable=too-few-public-methods
7475
def __init__(self, seconds):
7576
self.seconds = seconds
7677
self.old_handler = None
@@ -90,7 +91,7 @@ def __exit__(self, typ_, value, traceback):
9091
return True
9192

9293

93-
_key_cache = []
94+
_key_cache: List[Tuple[int, ...]] = []
9495

9596

9697
def cache_keys(keys):
@@ -230,7 +231,7 @@ def get_extended_key_name(codes):
230231
return known_keys()[codes]
231232

232233

233-
def known_keys():
234+
def known_keys() -> Dict[Tuple[int, ...], str]:
234235
result = {
235236
(27, 79, 70): "end",
236237
(27, 79, 72): "home",
@@ -279,7 +280,7 @@ def known_keys():
279280
return add_ascii_keys(result)
280281

281282

282-
def add_ascii_keys(data):
283+
def add_ascii_keys(data) -> Dict[Tuple[int, ...], str]:
283284
"""Update the data with ascii keys
284285
285286
>>> data = add_ascii_keys({})

0 commit comments

Comments
 (0)