Skip to content

Fix type hints: add py.typed marker and resolve mypy errors#773

Merged
lanpa merged 3 commits into
masterfrom
fix-type-hints-issue-749
Apr 9, 2026
Merged

Fix type hints: add py.typed marker and resolve mypy errors#773
lanpa merged 3 commits into
masterfrom
fix-type-hints-issue-749

Conversation

@lanpa
Copy link
Copy Markdown
Owner

@lanpa lanpa commented Apr 8, 2026

Description

tensorboardX lacked a py.typed marker (PEP 561), causing mypy to skip analysis entirely when importing from the package. This PR adds the marker and cleans up mypy errors in writer.py.

Technical Details

  • tensorboardX/py.typed: Empty marker file; tells mypy/pyright the package ships inline types
  • MANIFEST.in: Include py.typed in sdist
  • tensorboardX/writer.py: Fix Optional handling, string concatenation type errors, and method signature issues surfaced by mypy
  • pyproject.toml: Add mypy dev dependency; configure mypy to ignore generated protobuf files

Before (any downstream project importing tensorboardX):

error: Skipping analyzing "tensorboardX": module is installed, but missing library stubs or py.typed marker  [import-untyped]
    from tensorboardX import SummaryWriter

After:

$ mypy check_import.py
Success: no issues found in 1 source file

Verification Results

  • uv run mypy tensorboardX — 0 errors
  • All 94 existing tests pass

Related Issue

Checklist

  • Code follows project style (make lint)
  • Tests passed locally (make test)
  • Documentation updated if necessary

Self-review: I have verified these changes and they are ready for review.

@lanpa
Copy link
Copy Markdown
Owner Author

lanpa commented Apr 9, 2026

@copilot How would you confirm #749 is solved by this PR?

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

@copilot How would you confirm #749 is solved by this PR?

The fix can be confirmed by reproducing the exact error from issue #749 before and after:

Before this PR (no py.typed marker), running mypy on any file importing tensorboardX gives:

error: Skipping analyzing "tensorboardX": module is installed, but missing library stubs or py.typed marker  [import-untyped]
    from tensorboardX import SummaryWriter

After this PR, the same check passes cleanly:

# check_import.py
from tensorboardX import SummaryWriter
$ mypy check_import.py
Success: no issues found in 1 source file

The key change is the addition of tensorboardX/py.typed — an empty marker file that signals PEP 561 compliance, telling mypy (and other type checkers) that tensorboardX ships its own inline type annotations and should be analyzed rather than skipped. The MANIFEST.in update ensures this file is included in the distributed package, and the pyproject.toml packages list already picks it up via find_packages().

Copilot AI changed the title Fix type hints and add py.typed marker Fix type hints: add py.typed marker and resolve mypy errors Apr 9, 2026
Copilot finished work on behalf of lanpa April 9, 2026 08:23
@lanpa lanpa merged commit 48a5f8a into master Apr 9, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants