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

Skip to content

Commit db0fde0

Browse files
committed
some stricter typing
1 parent 2c163bf commit db0fde0

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

IPython/core/ultratb.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ def _format_exception_only(
336336
)
337337
)
338338
if textline == "":
339-
textline = py3compat.cast_unicode(value.text, "utf-8")
339+
# sep 2025:
340+
# textline = py3compat.cast_unicode(value.text, "utf-8")
341+
assert isinstance(value.text, str)
342+
textline = value.text
340343

341344
if textline is not None:
342345
i = 0
@@ -425,7 +428,7 @@ def show_exception_only(
425428
def _some_str(self, value: Any) -> str:
426429
# Lifted from traceback.py
427430
try:
428-
return py3compat.cast_unicode(str(value))
431+
return str(value)
429432
except:
430433
return "<unprintable %s object>" % type(value).__name__
431434

@@ -704,16 +707,19 @@ def format_exception(self, etype, evalue):
704707
if not isinstance(notes, Sequence) or isinstance(notes, (str, bytes)):
705708
notes = [_safe_string(notes, "__notes__", func=repr)]
706709

710+
for note in notes:
711+
assert isinstance(note, str)
712+
713+
str_notes: Sequence[str] = notes
714+
707715
# ... and format it
708716
return [
709717
theme_table[self._theme_name].format(
710718
[(Token.ExcName, etype_str), (Token, ": "), (Token, evalue_str)]
711719
),
712720
*(
713-
theme_table[self._theme_name].format(
714-
[(Token, _safe_string(py3compat.cast_unicode(n), "note"))]
715-
)
716-
for n in notes
721+
theme_table[self._theme_name].format([(Token, note)])
722+
for note in str_notes
717723
),
718724
]
719725

IPython/utils/text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ def match_target(s: str) -> str:
187187
else:
188188
pred = pattern
189189
if not prune:
190-
return type(self)([el for el in self if pred(match_target(el))])
190+
return type(self)([el for el in self if pred(match_target(el))]) # type: ignore [no-untyped-call]
191191
else:
192-
return type(self)([el for el in self if not pred(match_target(el))])
192+
return type(self)([el for el in self if not pred(match_target(el))]) # type: ignore [no-untyped-call]
193193

194194
def fields(self, *fields: List[str]) -> List[List[str]]:
195195
"""Collect whitespace-separated fields from string list

pyproject.toml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ exclude = [
111111
'IPython/sphinxext/ipython_directive.py',
112112
'IPython/terminal/ipapp.py',
113113
'IPython/utils/path.py',
114+
'IPython/core/debugger_backport.py',
114115
]
115-
# check_untyped_defs = true
116+
check_untyped_defs = true
116117
# disallow_untyped_calls = true
117118
# disallow_untyped_decorators = true
118119
# ignore_errors = false
@@ -127,6 +128,7 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
127128
[[tool.mypy.overrides]]
128129
module = [
129130
"IPython.core.crashhandler",
131+
"IPython.utils.text",
130132
]
131133
check_untyped_defs = true
132134
disallow_incomplete_defs = true
@@ -138,23 +140,15 @@ ignore_missing_imports = false
138140

139141
[[tool.mypy.overrides]]
140142
module = [
141-
"IPython.utils.text",
143+
"IPython.core.ultratb",
142144
]
143-
disallow_untyped_defs = true
144145
check_untyped_defs = true
146+
disallow_incomplete_defs = true
147+
disallow_untyped_calls = false
145148
disallow_untyped_decorators = true
146-
147-
[[tool.mypy.overrides]]
148-
module = [
149-
"IPython.core.ultratb",
150-
]
151149
disallow_untyped_defs = false
152150
ignore_errors = false
153151
ignore_missing_imports = false
154-
disallow_untyped_calls = false
155-
disallow_incomplete_defs = true
156-
check_untyped_defs = true
157-
disallow_untyped_decorators = true
158152

159153
[[tool.mypy.overrides]]
160154
module = [

0 commit comments

Comments
 (0)