Skip to content

Commit 048cf04

Browse files
committed
Use property decorator to support typing
1 parent 6d09bb6 commit 048cf04

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

git/refs/symbolic.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,23 @@ def set_object(
387387
# set the commit on our reference
388388
return self._get_reference().set_object(object, logmsg)
389389

390-
commit = property(
391-
_get_commit,
392-
set_commit, # type: ignore[arg-type]
393-
doc="Query or set commits directly",
394-
)
395-
396-
object = property(
397-
_get_object,
398-
set_object, # type: ignore[arg-type]
399-
doc="Return the object our ref currently refers to",
400-
)
390+
@property
391+
def commit(self) -> "Commit":
392+
"""Query or set commits directly"""
393+
return self._get_commit()
394+
395+
@commit.setter
396+
def commit(self, commit: Union[Commit, "SymbolicReference", str]) -> "SymbolicReference":
397+
return self.set_commit(commit)
398+
399+
@property
400+
def object(self) -> AnyGitObject:
401+
"""Return the object our ref currently refers to"""
402+
return self._get_object()
403+
404+
@object.setter
405+
def object(self, object: Union[AnyGitObject, "SymbolicReference", str]) -> "SymbolicReference":
406+
return self.set_object(object)
401407

402408
def _get_reference(self) -> "SymbolicReference":
403409
"""
@@ -496,12 +502,14 @@ def set_reference(
496502
return self
497503

498504
# Aliased reference
499-
reference: Union["Head", "TagReference", "RemoteReference", "Reference"]
500-
reference = property( # type: ignore[assignment]
501-
_get_reference,
502-
set_reference, # type: ignore[arg-type]
503-
doc="Returns the Reference we point to",
504-
)
505+
@property
506+
def reference(self) -> "SymbolicReference":
507+
return self._get_reference()
508+
509+
@reference.setter
510+
def reference(self, ref: Union[AnyGitObject, "SymbolicReference", str]) -> "SymbolicReference":
511+
return self.set_reference(ref)
512+
505513
ref = reference
506514

507515
def is_valid(self) -> bool:

git/repo/base.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,19 @@ def __ne__(self, rhs: object) -> bool:
354354
def __hash__(self) -> int:
355355
return hash(self.git_dir)
356356

357-
# Description property
358-
def _get_description(self) -> str:
357+
@property
358+
def description(self) -> str:
359+
"""The project's description"""
359360
filename = osp.join(self.git_dir, "description")
360361
with open(filename, "rb") as fp:
361362
return fp.read().rstrip().decode(defenc)
362363

363-
def _set_description(self, descr: str) -> None:
364+
@description.setter
365+
def description(self, descr: str) -> None:
364366
filename = osp.join(self.git_dir, "description")
365367
with open(filename, "wb") as fp:
366368
fp.write((descr + "\n").encode(defenc))
367369

368-
description = property(_get_description, _set_description, doc="the project's description")
369-
del _get_description
370-
del _set_description
371-
372370
@property
373371
def working_tree_dir(self) -> Optional[PathLike]:
374372
"""
@@ -885,13 +883,14 @@ def _set_daemon_export(self, value: object) -> None:
885883
elif not value and fileexists:
886884
os.unlink(filename)
887885

888-
daemon_export = property(
889-
_get_daemon_export,
890-
_set_daemon_export,
891-
doc="If True, git-daemon may export this repository",
892-
)
893-
del _get_daemon_export
894-
del _set_daemon_export
886+
@property
887+
def daemon_export(self) -> bool:
888+
"""If True, git-daemon may export this repository"""
889+
return self._get_daemon_export()
890+
891+
@daemon_export.setter
892+
def daemon_export(self, value: object) -> None:
893+
self._set_daemon_export(value)
895894

896895
def _get_alternates(self) -> List[str]:
897896
"""The list of alternates for this repo from which objects can be retrieved.
@@ -929,11 +928,14 @@ def _set_alternates(self, alts: List[str]) -> None:
929928
with open(alternates_path, "wb") as f:
930929
f.write("\n".join(alts).encode(defenc))
931930

932-
alternates = property(
933-
_get_alternates,
934-
_set_alternates,
935-
doc="Retrieve a list of alternates paths or set a list paths to be used as alternates",
936-
)
931+
@property
932+
def alternates(self) -> List[str]:
933+
"""Retrieve a list of alternates paths or set a list paths to be used as alternates"""
934+
return self._get_alternates()
935+
936+
@alternates.setter
937+
def alternates(self, alts: List[str]) -> None:
938+
self._set_alternates(alts)
937939

938940
def is_dirty(
939941
self,

0 commit comments

Comments
 (0)