Skip to content

Modernize type hints: replace Optional[T] with T | None across codebase - #936

Closed
mathdugre with Copilot wants to merge 3 commits into
mainfrom
copilot/convert-optional-to-type-or-none
Closed

mathdugre with Copilot wants to merge 3 commits into
mainfrom
copilot/convert-optional-to-type-or-none

Conversation

Copilot AI commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

This updates type annotations to the Python 3.10+ union style by replacing Optional[...] with ... | None, aligning the codebase with current typing guidance. The change is mechanical and scoped to annotation/style consistency, with one related inline note updated to match the new syntax.

  • Typing modernization (PEP 604)

    • Replaced Optional[T] annotations with T | None in core modules and tests.
    • Kept behavior unchanged; only annotation syntax was updated.
  • Related cleanup

    • Removed obsolete typing.Optional imports left unused after conversion.
    • Removed stale typing imports (Type, List, Tuple) where no longer needed due to pyupgrade normalization.
  • Documentation/comment alignment

    • Updated the inline comment in nipoppy/layout.py that described optional field typing so it now references OptionalFpathInfo | None instead of Optional[OptionalFpathInfo].

Example transformation applied throughout:

# before
from typing import Optional
def run(session_id: Optional[str] = None) -> None: ...

# after
def run(session_id: str | None = None) -> None: ...

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • sandbox.zenodo.org
    • Triggering command: /usr/bin/python /usr/bin/python -u -c import sys;exec(eval(sys.stdin.readline())) (dns block)
  • zenodo.org
    • Triggering command: /usr/bin/python /usr/bin/python -u -c import sys;exec(eval(sys.stdin.readline())) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[MAINT] Convert Optional[<type>] to <type> | None</issue_title>
<issue_description>Ref: python/cpython#30222 (review)

I would honestly start over -- throw away all changes so far, and take this:

To define a union, use e.g. ``Union[int, str]`` or the shorthand ``int | str``. Details:

Insert a single sentence before "Details:"

Using that shorthand is recommended.

</issue_description>

<agent_instructions>Identify use of Optional type annotation and convert them to the <type> | None best practices.
Follow the example from the issue.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI and others added 2 commits March 24, 2026 20:56
Copilot AI changed the title [WIP] Convert Optional types to type | None annotation Modernize type hints: replace Optional[T] with T | None across codebase Mar 24, 2026
Copilot AI requested a review from mathdugre March 24, 2026 21:01
@codecov

codecov Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
nipoppy/_data_retriever.py 100.00% <100.00%> (ø)
nipoppy/base.py 100.00% <100.00%> (ø)
nipoppy/config/container.py 100.00% <100.00%> (ø)
nipoppy/config/main.py 100.00% <100.00%> (ø)
nipoppy/config/pipeline.py 98.79% <100.00%> (ø)
nipoppy/config/pipeline_step.py 100.00% <100.00%> (ø)
nipoppy/config/tracker.py 100.00% <100.00%> (ø)
nipoppy/console.py 100.00% <ø> (ø)
nipoppy/container.py 98.49% <100.00%> (ø)
nipoppy/layout.py 99.26% <100.00%> (-0.01%) ⬇️
... and 26 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has had no activity for 45 days.

@github-actions github-actions Bot added the stale label May 10, 2026
@nipoppy-bot nipoppy-bot Bot added this to Software Jul 9, 2026
@nipoppy-bot nipoppy-bot Bot moved this to Cancelled in Software Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Cancelled

Development

Successfully merging this pull request may close these issues.

[MAINT] Convert Optional[<type>] to <type> | None

3 participants