Skip to content

Commit

Permalink
fix pypa#932: ensure type annotations in version file don't cause lin…
Browse files Browse the repository at this point in the history
…ter issues
  • Loading branch information
RonnyPfannschmidt committed Sep 22, 2023
1 parent 4a27740 commit ee3cbc3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20230922_160525_ronny_version_file_annotations.md
@@ -0,0 +1,4 @@

### Fixed

- fix #932: ensure type annotations in version file don't cause linter issues
14 changes: 11 additions & 3 deletions src/setuptools_scm/_integration/dump_version.py
Expand Up @@ -17,10 +17,18 @@
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple
from typing import Tuple, Union
VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
VERSION_TUPLE = object
__version__ = version = {version!r} # type: str
__version_tuple__ = version_tuple = {version_tuple!r} # type: Tuple[int | str, ...]
version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE
__version__ = version = {version!r}
__version_tuple__ = version_tuple = {version_tuple!r}
""",
".txt": "{version}",
}
Expand Down
5 changes: 2 additions & 3 deletions testing/test_basic_api.py
Expand Up @@ -180,9 +180,8 @@ def read(name: str) -> str:
dump_version(tmp_path, version, "first.py", scm_version=scm_version)
lines = read("first.py").splitlines()
assert lines[-2:] == [
"__version__ = version = '1.0.dev42' # type: str",
"__version_tuple__ = version_tuple = (1, 0, 'dev42')"
" # type: Tuple[int | str, ...]",
"__version__ = version = '1.0.dev42'",
"__version_tuple__ = version_tuple = (1, 0, 'dev42')",
]

version = "1.0.1+g4ac9d2c"
Expand Down

0 comments on commit ee3cbc3

Please sign in to comment.