Skip to content

Commit 9f135c2

Browse files
codexByron
authored andcommitted
Remove possibly-unbound type suppressions
<!-- agent --> Make established repository invariants explicit, initialize loop-only locals, and move assignments ahead of exception handling so basedpyright can follow the existing control flow. Regenerate the baseline to remove all 19 reportPossiblyUnboundVariable suppressions, including the two runtime fixes from the preceding commit. Validation: basedpyright --warnings; unbaselined possibly-unbound count 0; eight focused subsystem tests passed. Assisted-by: GPT 5.6 Co-authored-by: GPT 5.6 <codex@openai.com>
1 parent e0e5918 commit 9f135c2

6 files changed

Lines changed: 26 additions & 148 deletions

File tree

.basedpyright/baseline.json

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,6 @@
183183
"lineCount": 1
184184
}
185185
},
186-
{
187-
"code": "reportPossiblyUnboundVariable",
188-
"range": {
189-
"startColumn": 52,
190-
"endColumn": 59,
191-
"lineCount": 1
192-
}
193-
},
194186
{
195187
"code": "reportSelfClsParameterName",
196188
"range": {
@@ -207,14 +199,6 @@
207199
"lineCount": 1
208200
}
209201
},
210-
{
211-
"code": "reportPossiblyUnboundVariable",
212-
"range": {
213-
"startColumn": 41,
214-
"endColumn": 44,
215-
"lineCount": 1
216-
}
217-
},
218202
{
219203
"code": "reportArgumentType",
220204
"range": {
@@ -393,14 +377,6 @@
393377
"lineCount": 1
394378
}
395379
},
396-
{
397-
"code": "reportPossiblyUnboundVariable",
398-
"range": {
399-
"startColumn": 19,
400-
"endColumn": 25,
401-
"lineCount": 1
402-
}
403-
},
404380
{
405381
"code": "reportArgumentType",
406382
"range": {
@@ -467,30 +443,6 @@
467443
"lineCount": 1
468444
}
469445
},
470-
{
471-
"code": "reportPossiblyUnboundVariable",
472-
"range": {
473-
"startColumn": 23,
474-
"endColumn": 34,
475-
"lineCount": 1
476-
}
477-
},
478-
{
479-
"code": "reportPossiblyUnboundVariable",
480-
"range": {
481-
"startColumn": 32,
482-
"endColumn": 43,
483-
"lineCount": 1
484-
}
485-
},
486-
{
487-
"code": "reportPossiblyUnboundVariable",
488-
"range": {
489-
"startColumn": 23,
490-
"endColumn": 34,
491-
"lineCount": 1
492-
}
493-
},
494446
{
495447
"code": "reportArgumentType",
496448
"range": {
@@ -499,14 +451,6 @@
499451
"lineCount": 1
500452
}
501453
},
502-
{
503-
"code": "reportPossiblyUnboundVariable",
504-
"range": {
505-
"startColumn": 28,
506-
"endColumn": 32,
507-
"lineCount": 1
508-
}
509-
},
510454
{
511455
"code": "reportAttributeAccessIssue",
512456
"range": {
@@ -588,16 +532,6 @@
588532
}
589533
}
590534
],
591-
"./git/objects/submodule/root.py": [
592-
{
593-
"code": "reportPossiblyUnboundVariable",
594-
"range": {
595-
"startColumn": 18,
596-
"endColumn": 21,
597-
"lineCount": 1
598-
}
599-
}
600-
],
601535
"./git/objects/tag.py": [
602536
{
603537
"code": "reportIncompatibleVariableOverride",
@@ -701,14 +635,6 @@
701635
"lineCount": 1
702636
}
703637
},
704-
{
705-
"code": "reportPossiblyUnboundVariable",
706-
"range": {
707-
"startColumn": 41,
708-
"endColumn": 45,
709-
"lineCount": 1
710-
}
711-
},
712638
{
713639
"code": "reportArgumentType",
714640
"range": {
@@ -855,38 +781,6 @@
855781
"lineCount": 1
856782
}
857783
},
858-
{
859-
"code": "reportPossiblyUnboundVariable",
860-
"range": {
861-
"startColumn": 26,
862-
"endColumn": 34,
863-
"lineCount": 1
864-
}
865-
},
866-
{
867-
"code": "reportPossiblyUnboundVariable",
868-
"range": {
869-
"startColumn": 32,
870-
"endColumn": 40,
871-
"lineCount": 1
872-
}
873-
},
874-
{
875-
"code": "reportPossiblyUnboundVariable",
876-
"range": {
877-
"startColumn": 18,
878-
"endColumn": 26,
879-
"lineCount": 1
880-
}
881-
},
882-
{
883-
"code": "reportPossiblyUnboundVariable",
884-
"range": {
885-
"startColumn": 22,
886-
"endColumn": 30,
887-
"lineCount": 1
888-
}
889-
},
890784
{
891785
"code": "reportReturnType",
892786
"range": {
@@ -967,22 +861,6 @@
967861
"lineCount": 1
968862
}
969863
},
970-
{
971-
"code": "reportPossiblyUnboundVariable",
972-
"range": {
973-
"startColumn": 39,
974-
"endColumn": 47,
975-
"lineCount": 1
976-
}
977-
},
978-
{
979-
"code": "reportPossiblyUnboundVariable",
980-
"range": {
981-
"startColumn": 43,
982-
"endColumn": 51,
983-
"lineCount": 1
984-
}
985-
},
986864
{
987865
"code": "reportArgumentType",
988866
"range": {
@@ -998,22 +876,6 @@
998876
"endColumn": 38,
999877
"lineCount": 1
1000878
}
1001-
},
1002-
{
1003-
"code": "reportPossiblyUnboundVariable",
1004-
"range": {
1005-
"startColumn": 26,
1006-
"endColumn": 42,
1007-
"lineCount": 1
1008-
}
1009-
},
1010-
{
1011-
"code": "reportPossiblyUnboundVariable",
1012-
"range": {
1013-
"startColumn": 18,
1014-
"endColumn": 34,
1015-
"lineCount": 1
1016-
}
1017879
}
1018880
],
1019881
"./git/repo/fun.py": [

git/index/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,14 +730,17 @@ def _entries_for_paths(
730730
) -> List[BaseIndexEntry]:
731731
entries_added: List[BaseIndexEntry] = []
732732
if path_rewriter:
733+
working_tree_dir = self.repo.working_tree_dir
734+
if working_tree_dir is None:
735+
raise InvalidGitRepositoryError("Cannot rewrite paths without a working tree")
736+
working_tree_dir = str(working_tree_dir)
733737
for path in paths:
734738
if osp.isabs(path):
735739
abspath = path
736-
gitrelative_path = path[len(str(self.repo.working_tree_dir)) + 1 :]
740+
gitrelative_path = path[len(working_tree_dir) + 1 :]
737741
else:
738742
gitrelative_path = path
739-
if self.repo.working_tree_dir:
740-
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
743+
abspath = osp.join(working_tree_dir, gitrelative_path)
741744
# END obtain relative and absolute paths
742745

743746
blob = Blob(
@@ -1467,8 +1470,8 @@ def reset(
14671470
nie = new_inst.entries
14681471
for path in paths:
14691472
path = self._to_relative_path(path)
1473+
key = entry_key(path, 0)
14701474
try:
1471-
key = entry_key(path, 0)
14721475
self.entries[key] = nie[key]
14731476
except KeyError:
14741477
# If key is not in theirs, it mustn't be in ours.

git/objects/submodule/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ def fetch_remotes(module_repo: "Repo") -> None:
877877
#############################
878878
binsha = self.binsha
879879
hexsha = self.hexsha
880+
is_detached = False
880881
if mrepo is not None:
881882
# mrepo is only set if we are not in dry-run mode or if the module
882883
# existed.
@@ -1221,6 +1222,7 @@ def remove(
12211222
for remote in mod.remotes:
12221223
num_branches_with_new_commits = 0
12231224
rrefs = remote.refs
1225+
rref = None
12241226
for rref in rrefs:
12251227
num_branches_with_new_commits += len(mod.git.cherry(rref)) != 0
12261228
# END for each remote ref

git/refs/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry":
269269
return RefLogEntry.from_line(fp.readlines()[index].strip())
270270
# Read until index is reached.
271271

272+
line = b""
272273
for i in range(index + 1):
273274
line = fp.readline()
274275
if not line:

git/repo/base.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -933,13 +933,15 @@ def is_valid_object(self, sha: str, object_type: Union[str, None] = None) -> boo
933933
return False
934934

935935
def _get_daemon_export(self) -> bool:
936-
if self.git_dir:
937-
filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE)
936+
if self.git_dir is None:
937+
return False
938+
filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE)
938939
return osp.exists(filename)
939940

940941
def _set_daemon_export(self, value: object) -> None:
941-
if self.git_dir:
942-
filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE)
942+
if self.git_dir is None:
943+
return
944+
filename = osp.join(self.git_dir, self.DAEMON_EXPORT_FILE)
943945
fileexists = osp.exists(filename)
944946
if value and not fileexists:
945947
touch(filename)
@@ -1279,6 +1281,7 @@ class InfoTD(TypedDict, total=False):
12791281

12801282
keepends = True
12811283
for line_bytes in data.splitlines(keepends):
1284+
line_str = ""
12821285
try:
12831286
line_str = line_bytes.rstrip().decode(defenc)
12841287
except UnicodeDecodeError:
@@ -1737,8 +1740,9 @@ def currently_rebasing_on(self) -> Commit | None:
17371740
17381741
``None`` if we are not currently rebasing.
17391742
"""
1740-
if self.git_dir:
1741-
rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD")
1743+
if not self.git_dir:
1744+
return None
1745+
rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD")
17421746
if not osp.isfile(rebase_head_file):
17431747
return None
17441748
with open(rebase_head_file, "rt") as f:

test/test_repo.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ def test_daemon_export(self):
337337
self.rorepo.daemon_export = orig_val
338338
self.assertEqual(self.rorepo.daemon_export, orig_val)
339339

340+
def test_daemon_export_without_git_dir(self):
341+
repo = Repo.__new__(Repo)
342+
repo.git_dir = None
343+
self.assertFalse(repo._get_daemon_export())
344+
repo._set_daemon_export(True)
345+
340346
def test_alternates(self):
341347
cur_alternates = self.rorepo.alternates
342348
try:

0 commit comments

Comments
 (0)