Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit dba3efc

Browse files
author
David Robertson
committed
Use set_reference over a write to .reference
`.reference` is a property whose setter function is `set_reference`. My isn't happy when we try to assign directly: ``` scripts-dev/release.py:208: error: Trying to assign name "reference" that is not in "__slots__" of type "git.refs.head.HEAD" [misc] scripts-dev/release.py:208: error: Incompatible types in assignment (expression has type "HEAD", variable has type "Union[Head, TagReference, RemoteReference, Reference]") [assignment] ``` but calling `set_reference` ourselves makes the typechecker happy. Confusingly the following three types are all different: - the `refererence` property: `Union['Head', 'TagReference', 'RemoteReference', 'Reference']` - return type of `_get_reference`: `SymbolicReference` - `set_reference` first argument: `Union[Commit_ish, 'SymbolicReference', str]` where `Commit_ish = Union['Commit', 'TagObject', 'Blob', 'Tree']` It seems that typecheckers haven't settled down on The Way to handle properties whose getter and setter types differ: see e.g. python/mypy#3004 .
1 parent 41618ef commit dba3efc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

scripts-dev/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def prepare() -> None:
202202
click.get_current_context().abort()
203203

204204
# Check out the base branch and ensure it's up to date
205-
repo.head.reference = base_branch
205+
repo.head.set_reference(base_branch, "check out the base branch")
206206
repo.head.reset(index=True, working_tree=True)
207207
if not base_branch.is_remote():
208208
update_branch(repo)

0 commit comments

Comments
 (0)