Skip to content

Exempt test modules from mypy return type annotation requirement#201

Open
jaraco with Copilot wants to merge 2 commits into
mainfrom
copilot/change-mypy-config-for-tests
Open

Exempt test modules from mypy return type annotation requirement#201
jaraco with Copilot wants to merge 2 commits into
mainfrom
copilot/change-mypy-config-for-tests

Conversation

Copilot AI commented May 3, 2026

Copy link
Copy Markdown
Contributor

Test functions under tests/**/test_*.py don't need -> None return type annotations — they're not part of the public API and aren't shipped in the package. Adding them everywhere is pure noise.

Changes

  • mypy.ini: Adds a [mypy-tests.*] per-module override that disables the no-untyped-def error code for test modules, so projects using this skeleton no longer need to annotate every test function's return type.
[mypy-tests.*]
# Tests don't need return type annotations
disable_error_code =
    no-untyped-def,

Copilot AI linked an issue May 3, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Update mypy configuration to exempt test return type declarations Exempt test modules from mypy return type annotation requirement May 3, 2026
Copilot AI requested a review from jaraco May 3, 2026 23:31
Copilot finished work on behalf of jaraco May 3, 2026 23:31
@jaraco
jaraco marked this pull request as ready for review July 12, 2026 17:11
@jaraco

jaraco commented Jul 12, 2026

Copy link
Copy Markdown
Owner

@Avasam Any concerns about this change?

Comment thread mypy.ini
Comment on lines +19 to +20
disable_error_code =
no-untyped-def,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From my own shared configs: https://github.com/BesLogic/shared-configs/blob/main/mypy.ini
Also covers my concern at #200 (comment)
And avoids clunkyness trying to expand disable_error_code = downstream

Feel free to reword to your likings

Suggested change
disable_error_code =
no-untyped-def,
disallow_untyped_defs = false
# Still typecheck the content of test functions, as it validates exposed API usage
check_untyped_defs = true

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.

Avoid need for return type declarations in tests

3 participants