From a6b4907da72c5587ef9bea41d4ef05e01d840013 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 22 Feb 2024 08:37:47 -0500 Subject: [PATCH 1/2] Add mypy to 3.8 --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 1128a0d..51b79c8 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ python = 3.11 = unit 3.10 = unit 3.9 = unit - 3.8 = unit + 3.8 = unit,mypy [testenv] commands = From b4de8413e62a9933959a724b0e6530f94ee04516 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 22 Feb 2024 10:01:07 -0500 Subject: [PATCH 2/2] Tighten typing, fix mypy errors, remove redundant checks Also fix ruff warning: update pyproject.toml --- galaxy_release_util/point_release.py | 21 ++++++++++----------- pyproject.toml | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/galaxy_release_util/point_release.py b/galaxy_release_util/point_release.py index 5306a37..39b3081 100644 --- a/galaxy_release_util/point_release.py +++ b/galaxy_release_util/point_release.py @@ -172,13 +172,11 @@ def add_changelog_item(changes, child): changelog_items: List[ChangelogItem] = [] root_section = document[0] assert isinstance(root_section, docutils.nodes.section) - assert root_section.tagname == "section" - for release in root_section.children: + for node in root_section.children: # ignore title and comment - assert isinstance(release, (docutils.nodes.title, docutils.nodes.comment, docutils.nodes.section)), release - if release.tagname == "section": - assert release[0].tagname == "title" - release_version = release[0].astext() + assert isinstance(node, (docutils.nodes.title, docutils.nodes.comment, docutils.nodes.section)), node + if isinstance(node, docutils.nodes.section): + release_version = node[0].astext() current_date = None if " (" in release_version: version_str, current_date = release_version.split(" (") @@ -189,19 +187,20 @@ def add_changelog_item(changes, child): version_str = release_version current_version = Version(version_str) package.add_release(ReleaseItem(version=current_version, date=current_date)) - changes = [] - for changelog_item in release[1:]: + changes: List = [] + for changelog_item in node[1:]: # could be bullet list or a nested section with bugfix, docs, etc - if changelog_item.tagname == "bullet_list": + if isinstance(changelog_item, docutils.nodes.bullet_list): for child in changelog_item.children: add_changelog_item(changes, child) - elif changelog_item.tagname == "paragraph": + elif isinstance(changelog_item, docutils.nodes.paragraph): changes = changelog_item.rawsource.splitlines() - elif changelog_item.tagname == "section": + elif isinstance(changelog_item, docutils.nodes.section): kind = changelog_item[0].astext() section_delimiter = "=" * len(kind) changes.append(f"\n{section_delimiter}\n{kind}\n{section_delimiter}\n") for section_changelog_item in changelog_item[1:]: + assert isinstance(section_changelog_item, docutils.nodes.bullet_list) for child in section_changelog_item: add_changelog_item(changes, child) changelog_items.append(ChangelogItem(version=current_version, date=current_date, changes=changes)) diff --git a/pyproject.toml b/pyproject.toml index 2bed9bc..417e723 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,4 +9,4 @@ line-length = 120 [tool.ruff] line-length = 120 # Never enforce `E501`, enforced by black -ignore = ["E501"] +lint.ignore = ["E501"]