Skip to content

Commit adc8f6e

Browse files
committed
types(doc): Expose aliases at runtime for autodoc
why: sphinx-autodoc-typehints emitted forward reference warnings for aliases only defined under TYPE_CHECKING. what: - provide fallback DataclassInstance, move TypeAlias imports out of TYPE_CHECKING, and import StrPath/TypeGuard at runtime - ensure sync/url/registry modules import shared aliases directly to make type hints resolvable during docs build - tidy _internal types docstring wording to drop glossary term that caused warnings
1 parent 55bd6fe commit adc8f6e

10 files changed

Lines changed: 19 additions & 38 deletions

File tree

src/libvcs/_internal/dataclasses.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
if t.TYPE_CHECKING:
1515
from _typeshed import DataclassInstance
16+
else:
17+
DataclassInstance = object
1618

1719

1820
class SkipDefaultFieldsReprMixin:

src/libvcs/_internal/shortcuts.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88
from __future__ import annotations
99

1010
import typing as t
11+
from typing import TypeGuard
1112

1213
from libvcs import GitSync, HgSync, SvnSync, exc
14+
from libvcs._internal.run import ProgressCallbackProtocol
15+
from libvcs._internal.types import StrPath, VCSLiteral
1316
from libvcs.exc import InvalidVCS
1417
from libvcs.url import registry as url_tools
1518

16-
if t.TYPE_CHECKING:
17-
from typing import TypeGuard
18-
19-
from libvcs._internal.run import ProgressCallbackProtocol
20-
from libvcs._internal.types import StrPath, VCSLiteral
21-
2219

2320
class VCSNoMatchFoundForUrl(exc.LibVCSException):
2421
def __init__(self, url: str, *args: object) -> None:

src/libvcs/_internal/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Internal :term:`type annotations <annotation>`.
1+
"""Internal type annotations.
22
33
Notes
44
-----
@@ -19,7 +19,7 @@
1919
""":class:`os.PathLike` or :class:`str`"""
2020

2121
StrOrBytesPath: TypeAlias = str | bytes | PathLike[str] | PathLike[bytes]
22-
""":class:`os.PathLike`, :class:`str` or :term:`bytes-like object`"""
22+
""":class:`os.PathLike`, :class:`str` or bytes-like object"""
2323

2424

2525
VCSLiteral = t.Literal["git", "svn", "hg"]

src/libvcs/pytest_plugin.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@
1313
import pytest
1414

1515
from libvcs import exc
16-
from libvcs._internal.run import run
16+
from libvcs._internal.run import _ENV, run
1717
from libvcs.sync.git import GitRemote, GitSync
1818
from libvcs.sync.hg import HgSync
1919
from libvcs.sync.svn import SvnSync
2020

21-
if t.TYPE_CHECKING:
22-
from typing import TypeAlias
23-
24-
from libvcs._internal.run import _ENV
25-
2621

2722
class MaxUniqueRepoAttemptsExceeded(exc.LibVCSException):
2823
"""Raised when exceeded threshold of attempts to find a unique repo destination."""

src/libvcs/sync/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
from urllib import parse as urlparse
1010

1111
from libvcs._internal.run import _CMD, CmdLoggingAdapter, ProgressCallbackProtocol, run
12-
13-
if t.TYPE_CHECKING:
14-
from libvcs._internal.types import StrPath
12+
from libvcs._internal.types import StrPath
1513

1614
logger = logging.getLogger(__name__)
1715

src/libvcs/sync/git.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
VCSLocation,
3232
convert_pip_url as base_convert_pip_url,
3333
)
34-
35-
if t.TYPE_CHECKING:
36-
from libvcs._internal.types import StrPath
34+
from libvcs._internal.types import StrPath
3735

3836
logger = logging.getLogger(__name__)
3937

src/libvcs/sync/hg.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
import pathlib
1616
import typing as t
1717

18+
from libvcs._internal.types import StrPath
1819
from libvcs.cmd.hg import Hg
1920

2021
from .base import BaseSync
2122

22-
if t.TYPE_CHECKING:
23-
from libvcs._internal.types import StrPath
24-
2523
logger = logging.getLogger(__name__)
2624

2725

src/libvcs/sync/svn.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
import re
2222
import typing as t
2323

24+
from libvcs._internal.types import StrPath
2425
from libvcs.cmd.svn import Svn
2526

2627
from .base import BaseSync
2728

28-
if t.TYPE_CHECKING:
29-
from libvcs._internal.types import StrPath
30-
3129
logger = logging.getLogger(__name__)
3230

3331

src/libvcs/url/base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
import dataclasses
66
import typing as t
7+
from _collections_abc import dict_values
8+
from collections.abc import Iterator
9+
from re import Pattern
710

811
from libvcs._internal.dataclasses import SkipDefaultFieldsReprMixin
912

10-
if t.TYPE_CHECKING:
11-
from _collections_abc import dict_values
12-
from collections.abc import Iterator
13-
from re import Pattern
14-
1513

1614
class URLProtocol(t.Protocol):
1715
"""Common interface for VCS URL Parsers."""

src/libvcs/url/registry.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
from __future__ import annotations
44

55
import typing as t
6+
from typing import TypeAlias
67

78
from libvcs._internal.module_loading import import_string
9+
from .base import URLProtocol
810

9-
if t.TYPE_CHECKING:
10-
from typing import TypeAlias
11-
12-
from .base import URLProtocol
13-
14-
ParserLazyMap: TypeAlias = dict[str, type[URLProtocol] | str]
15-
ParserMap: TypeAlias = dict[str, type[URLProtocol]]
11+
ParserLazyMap: TypeAlias = dict[str, type[URLProtocol] | str]
12+
ParserMap: TypeAlias = dict[str, type[URLProtocol]]
1613

1714
DEFAULT_PARSERS: ParserLazyMap = {
1815
"git": "libvcs.url.git.GitURL",

0 commit comments

Comments
 (0)