Skip to content

Commit 88bd04b

Browse files
authored
Merge pull request #2258 from NMGRL/develop
mypy: add stub packages and widen base class attribute types
2 parents 7dead74 + 2ef2c30 commit 88bd04b

File tree

8 files changed

+34
-27
lines changed

8 files changed

+34
-27
lines changed

pychron/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
from .version import __version__
1818

1919
try:
20-
import ujson as json
20+
import ujson as json # type: ignore[no-redef]
2121
except ImportError:
2222
try:
23-
import simplejson as json
23+
import simplejson as json # type: ignore[no-redef]
2424
except ImportError:
25-
import json
25+
import json # type: ignore[no-redef]

pychron/envisage/initialization/nodes.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def get_icon(self, object, is_expanded):
5151

5252

5353
class BaseNode(HasTraits):
54-
name = Str
55-
enabled = Bool
54+
name: str = ""
55+
enabled: bool = True
5656

5757

5858
class Plugin(BaseNode):
@@ -73,11 +73,7 @@ class PluginTree(Plugin):
7373
def get_subtree(self, name):
7474
name = name.lower()
7575
return next(
76-
(
77-
p
78-
for p in self.plugins
79-
if isinstance(p, PluginTree) and p.name.lower() == name
80-
)
76+
(p for p in self.plugins if isinstance(p, PluginTree) and p.name.lower() == name)
8177
)
8278

8379
def set_all_enabled(self, v):

pychron/experiment/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, m):
2323

2424

2525
class CheckException(BaseException):
26-
tag = None
26+
tag: str | None = None
2727

2828
def __init__(self, msg):
2929
self._msg = msg

pychron/experiment/utilities/comment_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# ============= enthought library imports =======================
1818
from __future__ import absolute_import
1919

20-
from traits.api import List, Dict
20+
from traits.api import List, Dict, Str
2121

2222
from pychron.core.templater.base_templater import BaseTemplater
2323

@@ -28,7 +28,7 @@ class CommentTemplater(BaseTemplater):
2828

2929
base_predefined_labels = List(["", "irrad_level : irrad_hole"])
3030

31-
label = "irrad_level : irrad_hole"
31+
label = Str("irrad_level : irrad_hole")
3232
persistence_name = "comment"
3333

3434
def render(self, obj):

pychron/pyscripts/commands/core.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def uncamelcase(name):
4444

4545

4646
class Command(HasTraits):
47-
description = Str
48-
example = Str
47+
description: str = ""
48+
example: str = ""
4949
name = Property
5050

5151
# implements(ICommand)
@@ -66,7 +66,7 @@ def _get_command(self):
6666

6767
# return self.__class__.__name__.lower()
6868

69-
def _to_string(self):
69+
def _to_string(self) -> str:
7070
return ""
7171

7272
@classmethod
@@ -99,9 +99,7 @@ def get_text(self):
9999
return self.to_string()
100100

101101
def traits_view(self):
102-
v = View(
103-
self._get_view(), title=self.__class__.__name__, buttons=OKCancelButtons
104-
)
102+
v = View(self._get_view(), title=self.__class__.__name__, buttons=OKCancelButtons)
105103
return v
106104

107105
def help_view(self):
@@ -189,14 +187,16 @@ def _get_view(self):
189187
# width=600,
190188
)
191189

192-
def _to_string(self):
193-
if os.path.isfile(self.path):
194-
head, tail = os.path.split(self.path)
190+
def _to_string(self) -> str:
191+
path = str(self.path)
192+
if path and os.path.isfile(path):
193+
head, tail = os.path.split(path)
195194
words = [
196195
("name", tail),
197196
("root", head),
198197
]
199198
return self._keywords(words)
199+
return ""
200200

201201

202202
class BeginInterval(Command):

pychron/tx/errors.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717

1818
# =============enthought library imports=======================
1919
# ============= standard library imports ========================
20+
from __future__ import annotations
21+
22+
2023
# ============= local library imports ==========================
2124
class ErrorCode(object):
22-
msg = ""
23-
code = None
24-
description = ""
25+
msg: str = ""
26+
code: str | None = None
27+
description: str = ""
2528

26-
def __str__(self):
29+
def __str__(self) -> str:
2730
return "ERROR {} : {}".format(self.code, self.msg)
2831

2932

pychron/tx/protocols/base_valve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
class BaseValveProtocol(ServiceProtocol):
32-
manager_protocol = None
32+
manager_protocol: str | None = None
3333

3434
def __init__(self, application, addr, logger):
3535
ServiceProtocol.__init__(self, logger=logger)

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,12 @@ dev = [
9999
"black",
100100
"mypy>=1.15.0,<2",
101101
"pre-commit>=4.2.0,<5",
102+
"types-requests",
103+
"types-pyyaml",
104+
"types-six",
105+
"types-simplejson",
106+
"types-ujson",
107+
"types-pytz",
108+
"types-pymysql",
109+
"types-paramiko",
102110
]

0 commit comments

Comments
 (0)