Skip to content

Commit cdf2041

Browse files
committed
refactor(GitStatus): Use dataclasses
1 parent f84a56e commit cdf2041

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

libvcs/projects/git.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import logging
1919
import pathlib
2020
import re
21-
from typing import Dict, NamedTuple, Optional, TypedDict, Union
21+
from typing import Dict, Optional, TypedDict, Union
2222
from urllib import parse as urlparse
2323

2424
from .. import exc
@@ -54,14 +54,21 @@ def to_tuple(self):
5454
GitRemotesArgs = Union[None, GitFullRemoteDict, Dict[str, str]]
5555

5656

57-
class GitStatus(NamedTuple):
57+
@dataclasses.dataclass
58+
class GitStatus:
5859
branch_oid: Optional[str]
5960
branch_head: Optional[str]
6061
branch_upstream: Optional[str]
6162
branch_ab: Optional[str]
6263
branch_ahead: Optional[str]
6364
branch_behind: Optional[str]
6465

66+
def to_dict(self):
67+
return dataclasses.asdict(self)
68+
69+
def to_tuple(self):
70+
return dataclasses.astuple(self)
71+
6572

6673
def extract_status(value) -> GitStatus:
6774
"""Returns ``git status -sb --porcelain=2`` extracted to a dict

tests/projects/test_git.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def test_extract_status():
628628
assert {
629629
"branch_oid": "d4ccd4d6af04b53949f89fbf0cdae13719dc5a08",
630630
"branch_head": "fix-current-remote-name",
631-
}.items() <= extract_status(FIXTURE_A)._asdict().items()
631+
}.items() <= extract_status(FIXTURE_A).to_dict().items()
632632

633633

634634
@pytest.mark.parametrize(
@@ -676,7 +676,7 @@ def test_extract_status():
676676
)
677677
def test_extract_status_b(fixture: str, expected_result: dict):
678678
assert (
679-
extract_status(textwrap.dedent(fixture))._asdict().items()
679+
extract_status(textwrap.dedent(fixture)).to_dict().items()
680680
>= expected_result.items()
681681
)
682682

@@ -727,7 +727,7 @@ def test_extract_status_b(fixture: str, expected_result: dict):
727727
def test_extract_status_c(fixture: str, expected_result: dict):
728728
assert (
729729
expected_result.items()
730-
<= extract_status(textwrap.dedent(fixture))._asdict().items()
730+
<= extract_status(textwrap.dedent(fixture)).to_dict().items()
731731
)
732732

733733

0 commit comments

Comments
 (0)