Skip to content

style: add typing to pass mypy and pyright in snakemake.io.__init__ and snakemake.io.container#4082

Merged
johanneskoester merged 9 commits intomainfrom
style/post-4032
Mar 13, 2026
Merged

style: add typing to pass mypy and pyright in snakemake.io.__init__ and snakemake.io.container#4082
johanneskoester merged 9 commits intomainfrom
style/post-4032

Conversation

@Hocnonsense
Copy link
Copy Markdown
Contributor

@Hocnonsense Hocnonsense commented Mar 13, 2026

fix bugs introduced in #4032

QC

  • The PR contains a test case for the changes or the changes are already covered by an existing test case.
  • The change does neither modify the language nor the behavior or functionalities of Snakemake.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of function-based file paths and wildcard resolution for more reliable IO behavior.
  • New Features

    • Added a property to report temporary file sizes for input collections, aiding cleanup and monitoring.
  • Chores

    • Strengthened internal type hints and typing consistency to improve reliability and maintainability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b4afab24-181c-4015-a792-96a5b0af89ee

📥 Commits

Reviewing files that changed from the base of the PR and between e1d19b8 and 80d9518.

📒 Files selected for processing (1)
  • src/snakemake/io/container.py

📝 Walkthrough

Walkthrough

Tightened and modernized type annotations in io modules: added a TypeVar and Coroutine typing for iocache, introduced forward references and relaxed return types for Namedlist/ReportHref and _IOFile, changed wait_for_files default to frozenset(), and added InputFiles.size_tempfiles.

Changes

Cohort / File(s) Summary
Typing & iocache
src/snakemake/io/__init__.py
Added TypeVar T and Coroutine imports; updated iocache signature to Callable[..., Coroutine[Any,Any,T]]; generalized async cache typing.
_IOFile & property typings
src/snakemake/io/__init__.py
Widened _IOFile._file to a forward-referenced Callable[\"Namedlist\", str]; annotated storage_object -> Any and `file -> str
wait_for_files, flag, apply_wildcards, flatten
src/snakemake/io/__init__.py
Changed wait_for_files consider_local default to frozenset() (with # type: ignore[assignment]); flag() flag_value typed as Any; added lazy Namedlist import in apply_wildcards; simplified flatten typing and removed several list-item ignores.
Namedlist generics & ReportHref forward refs
src/snakemake/io/container.py
Removed key TypeVar from Namedlist, now Generic[_TNamedList]; fromdict expects Dict[str, _TNamedList]; items() yields (str, value); ReportHref uses parent: Optional[\"ReportHref\"] and constructs returns via self.__class__.
InputFiles & optional deps handling
src/snakemake/io/container.py
Added InputFiles.size_tempfiles property using is_flagged; adjusted _safely_store_params/params logic to initialize optional deps (pd, np, pl) with # type: ignore where needed and other small typing cleanups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is incomplete. It mentions fixing bugs from #4032 and adding typing, but lacks detail on what bugs were fixed and why the changes are necessary. Provide more context about the bugs introduced in #4032 and explain how the typing changes address them.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding typing annotations to pass mypy and pyright in specific modules.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch style/post-4032
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

Flake8 can be used to improve the quality of Python code reviews.

Flake8 is a Python linter that wraps PyFlakes, pycodestyle and Ned Batchelder's McCabe script.

To configure Flake8, add a '.flake8' or 'setup.cfg' file to your project root.

See Flake8 Documentation for more details.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/snakemake/io/__init__.py`:
- Around line 791-799: In the except MissingOutputException block, preserve the
original exception context by chaining the new WorkflowError from the caught
exception (use "raise WorkflowError(... ) from e") and avoid shadowing the
built-in by renaming the local variable dir to dirpath (update the assignment
"dir = _file if self.is_directory else os.path.dirname(_file)" to use dirpath).
Keep references to _file, is_directory, and the is_callable(self._file) check
unchanged and ensure the new WorkflowError is raised using "from e".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 247f5fa0-2360-4902-92cb-da773ec49db1

📥 Commits

Reviewing files that changed from the base of the PR and between e8ad771 and 1528efa.

📒 Files selected for processing (2)
  • src/snakemake/io/__init__.py
  • src/snakemake/io/container.py

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/snakemake/io/__init__.py`:
- Around line 461-463: Fix the misspelling in the inline comment inside the
storage_object method: change "silance" to "silence" in the comment that starts
with "assume that all .storage_object is called after .is_storage check..." near
the storage_object function (which returns get_flag_value(self._file,
"storage_object")). Ensure only the comment text is updated and no code behavior
is changed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 567b8dff-42a1-46fa-8cf4-0193779e24bd

📥 Commits

Reviewing files that changed from the base of the PR and between 1528efa and e510316.

📒 Files selected for processing (1)
  • src/snakemake/io/__init__.py

@Hocnonsense Hocnonsense changed the title style: add typing to pass mypy and pyright style: add typing to pass mypy and pyright in snakemake.io.__init__ and snakemake.io.container Mar 13, 2026
@fgvieira fgvieira added the bug Something isn't working label Mar 13, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/snakemake/io/__init__.py (1)

1046-1046: Use collections.abc.Set annotation to match immutable default value.

Line 1046 annotates consider_local as Set[_IOFile] (mutable protocol) but defaults to frozenset() (immutable), requiring # type: ignore[assignment]. Since this parameter is used only for membership checks, annotate it as collections.abc.Set[_IOFile] to properly reflect its immutable usage and eliminate the ignore comment.

♻️ Proposed typing-only adjustment
-    consider_local: Set[_IOFile] = frozenset(),  # type: ignore[assignment]
+    consider_local: collections.abc.Set[_IOFile] = frozenset(),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/snakemake/io/__init__.py` at line 1046, The parameter annotation for
consider_local currently uses typing.Set[_IOFile] but the default is an
immutable frozenset() and the value is only used for membership checks; change
the annotation to collections.abc.Set[_IOFile] (import collections.abc as
needed) on the function or variable where consider_local is declared and remove
the trailing "# type: ignore[assignment]" so the type matches the immutable
default and eliminates the ignore; reference the consider_local parameter and
the _IOFile element type when making this edit.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/snakemake/io/__init__.py`:
- Line 1046: The parameter annotation for consider_local currently uses
typing.Set[_IOFile] but the default is an immutable frozenset() and the value is
only used for membership checks; change the annotation to
collections.abc.Set[_IOFile] (import collections.abc as needed) on the function
or variable where consider_local is declared and remove the trailing "# type:
ignore[assignment]" so the type matches the immutable default and eliminates the
ignore; reference the consider_local parameter and the _IOFile element type when
making this edit.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b56a6f4-c7d2-459c-aad7-0567059f9fd6

📥 Commits

Reviewing files that changed from the base of the PR and between e510316 and e1d19b8.

📒 Files selected for processing (1)
  • src/snakemake/io/__init__.py

Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
@johanneskoester johanneskoester enabled auto-merge (squash) March 13, 2026 13:22
@johanneskoester johanneskoester merged commit a554741 into main Mar 13, 2026
59 checks passed
@johanneskoester johanneskoester deleted the style/post-4032 branch March 13, 2026 19:41
@github-project-automation github-project-automation bot moved this from In review to Done in Snakemake Hackathon 2026 Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants