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

Skip to content

Commit 0406826

Browse files
authored
Use --strict for selfcheck (#13464)
1 parent 3864db6 commit 0406826

16 files changed

Lines changed: 52 additions & 44 deletions

misc/analyze_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def compress(chunk: JsonDict) -> JsonDict:
8989
cache: dict[int, JsonDict] = {}
9090
counter = 0
9191

92-
def helper(chunk: Any) -> Any:
92+
def helper(chunk: JsonDict) -> JsonDict:
9393
nonlocal counter
9494
if not isinstance(chunk, dict):
9595
return chunk
@@ -121,7 +121,7 @@ def helper(chunk: Any) -> Any:
121121
def decompress(chunk: JsonDict) -> JsonDict:
122122
cache: dict[int, JsonDict] = {}
123123

124-
def helper(chunk: Any) -> Any:
124+
def helper(chunk: JsonDict) -> JsonDict:
125125
if not isinstance(chunk, dict):
126126
return chunk
127127
if ".id" in chunk:

misc/incremental_checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ def stop_daemon() -> None:
197197
def load_cache(incremental_cache_path: str = CACHE_PATH) -> JsonDict:
198198
if os.path.exists(incremental_cache_path):
199199
with open(incremental_cache_path) as stream:
200-
return json.load(stream)
200+
cache = json.load(stream)
201+
assert isinstance(cache, dict)
202+
return cache
201203
else:
202204
return {}
203205

misc/upload-pypi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ def is_whl_or_tar(name: str) -> bool:
3232
def get_release_for_tag(tag: str) -> dict[str, Any]:
3333
with urlopen(f"{BASE}/{REPO}/releases/tags/{tag}") as f:
3434
data = json.load(f)
35+
assert isinstance(data, dict)
3536
assert data["tag_name"] == tag
3637
return data
3738

3839

3940
def download_asset(asset: dict[str, Any], dst: Path) -> Path:
4041
name = asset["name"]
42+
assert isinstance(name, str)
4143
download_url = asset["browser_download_url"]
4244
assert is_whl_or_tar(name)
4345
with urlopen(download_url) as src_file:

mypy/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,7 @@ def read_deps_cache(manager: BuildManager, graph: Graph) -> dict[str, FgDepMeta]
11231123
return None
11241124

11251125
module_deps_metas = deps_meta["deps_meta"]
1126+
assert isinstance(module_deps_metas, dict)
11261127
if not manager.options.skip_cache_mtime_checks:
11271128
for id, meta in module_deps_metas.items():
11281129
try:
@@ -1167,6 +1168,7 @@ def _load_json_file(
11671168
)
11681169
return None
11691170
else:
1171+
assert isinstance(result, dict)
11701172
return result
11711173

11721174

mypy/dmypy_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ def run_command(self, command: str, data: dict[str, object]) -> dict[str, object
267267
# Only the above commands use some error formatting.
268268
del data["is_tty"]
269269
del data["terminal_width"]
270-
return method(self, **data)
270+
ret = method(self, **data)
271+
assert isinstance(ret, dict)
272+
return ret
271273

272274
# Command functions (run in the server via RPC).
273275

mypy/fastparse.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def parse(
305305
if raise_on_error and errors.is_errors():
306306
errors.raise_error()
307307

308+
assert isinstance(tree, MypyFile)
308309
return tree
309310

310311

@@ -1632,7 +1633,9 @@ def visit_ExtSlice(self, n: ast3.ExtSlice) -> TupleExpr:
16321633
# Index(expr value)
16331634
def visit_Index(self, n: Index) -> Node:
16341635
# cast for mypyc's benefit on Python 3.9
1635-
return self.visit(cast(Any, n).value)
1636+
value = self.visit(cast(Any, n).value)
1637+
assert isinstance(value, Node)
1638+
return value
16361639

16371640
# Match(expr subject, match_case* cases) # python 3.10 and later
16381641
def visit_Match(self, n: Match) -> MatchStmt:
@@ -1762,7 +1765,9 @@ def visit(self, node: AST | None) -> ProperType | None:
17621765
method = "visit_" + node.__class__.__name__
17631766
visitor = getattr(self, method, None)
17641767
if visitor is not None:
1765-
return visitor(node)
1768+
typ = visitor(node)
1769+
assert isinstance(typ, ProperType)
1770+
return typ
17661771
else:
17671772
return self.invalid_type(node)
17681773
finally:
@@ -1949,7 +1954,9 @@ def visit_Bytes(self, n: Bytes) -> Type:
19491954

19501955
def visit_Index(self, n: ast3.Index) -> Type:
19511956
# cast for mypyc's benefit on Python 3.9
1952-
return self.visit(cast(Any, n).value)
1957+
value = self.visit(cast(Any, n).value)
1958+
assert isinstance(value, Type)
1959+
return value
19531960

19541961
def visit_Slice(self, n: ast3.Slice) -> Type:
19551962
return self.invalid_type(n, note="did you mean to use ',' instead of ':' ?")

mypy/ipc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,6 @@ def connection_name(self) -> str:
270270
if sys.platform == "win32":
271271
return self.name
272272
else:
273-
return self.sock.getsockname()
273+
name = self.sock.getsockname()
274+
assert isinstance(name, str)
275+
return name

mypy/literals.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def visit_op_expr(self, e: OpExpr) -> Key:
173173
return ("Binary", e.op, literal_hash(e.left), literal_hash(e.right))
174174

175175
def visit_comparison_expr(self, e: ComparisonExpr) -> Key:
176-
rest: Any = tuple(e.operators)
176+
rest: tuple[str | Key | None, ...] = tuple(e.operators)
177177
rest += tuple(literal_hash(o) for o in e.operands)
178178
return ("Comparison",) + rest
179179

@@ -182,7 +182,7 @@ def visit_unary_expr(self, e: UnaryExpr) -> Key:
182182

183183
def seq_expr(self, e: ListExpr | TupleExpr | SetExpr, name: str) -> Key | None:
184184
if all(literal(x) == LITERAL_YES for x in e.items):
185-
rest: Any = tuple(literal_hash(x) for x in e.items)
185+
rest: tuple[Key | None, ...] = tuple(literal_hash(x) for x in e.items)
186186
return (name,) + rest
187187
return None
188188

@@ -191,7 +191,7 @@ def visit_list_expr(self, e: ListExpr) -> Key | None:
191191

192192
def visit_dict_expr(self, e: DictExpr) -> Key | None:
193193
if all(a and literal(a) == literal(b) == LITERAL_YES for a, b in e.items):
194-
rest: Any = tuple(
194+
rest: tuple[Key | None, ...] = tuple(
195195
(literal_hash(a) if a else None, literal_hash(b)) for a, b in e.items
196196
)
197197
return ("Dict",) + rest

mypy/metastore.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,14 @@ def _query(self, name: str, field: str) -> Any:
185185
return results[0][0]
186186

187187
def getmtime(self, name: str) -> float:
188-
return self._query(name, "mtime")
188+
mtime = self._query(name, "mtime")
189+
assert isinstance(mtime, float)
190+
return mtime
189191

190192
def read(self, name: str) -> str:
191-
return self._query(name, "data")
193+
data = self._query(name, "data")
194+
assert isinstance(data, str)
195+
return data
192196

193197
def write(self, name: str, data: str, mtime: float | None = None) -> bool:
194198
import sqlite3

mypy/nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,10 +3150,10 @@ class FakeInfo(TypeInfo):
31503150
def __init__(self, msg: str) -> None:
31513151
self.msg = msg
31523152

3153-
def __getattribute__(self, attr: str) -> None:
3153+
def __getattribute__(self, attr: str) -> type:
31543154
# Handle __class__ so that isinstance still works...
31553155
if attr == "__class__":
3156-
return object.__getattribute__(self, attr)
3156+
return object.__getattribute__(self, attr) # type: ignore[no-any-return]
31573157
raise AssertionError(object.__getattribute__(self, "msg"))
31583158

31593159

0 commit comments

Comments
 (0)