Skip to content

Apply mypy-tests custom config to other mypy-based tests #13825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Apr 14, 2025

Extracted from #13627
Also relates to #12178 and #8403

We have the infra/tooling in place for per-stub mypy configuration. But those configs didn't extend to other tests, making it unusable since stubtest would still fail.

Easier with review with whitespace changes hidden.

Comment on lines 54 to 57
@contextmanager
def temporary_mypy_config_file(
configurations: Iterable[MypyDistConf],
) -> Generator[tempfile._TemporaryFileWrapper[str]]: # pyright: ignore[reportPrivateUsage]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a full review, but I'd prefer to keep the temporary file workaround logic separate from the actual logic for the temporary files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah sure that makes sense. We may have to reuse temporary files elsewhere. It'd be nice if already separate.

The workaround used to only be done in tests/mypy_test.py, but I'll extract it and put it somewhere in ts_lib

@Avasam Avasam requested a review from srittau April 28, 2025 03:39
Comment on lines +18 to +27
# The configuration section in the metadata file looks like the following, with multiple module sections possible
# [mypy-tests]
# [mypy-tests.yaml]
# module_name = "yaml"
# [mypy-tests.yaml.values]
# disallow_incomplete_defs = true
# disallow_untyped_defs = true


def mypy_configuration_from_distribution(distribution: str) -> list[MypyDistConf]:
Copy link
Collaborator Author

@Avasam Avasam Apr 28, 2025

Choose a reason for hiding this comment

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

Maybe this should be a docstring ?

Suggested change
# The configuration section in the metadata file looks like the following, with multiple module sections possible
# [mypy-tests]
# [mypy-tests.yaml]
# module_name = "yaml"
# [mypy-tests.yaml.values]
# disallow_incomplete_defs = true
# disallow_untyped_defs = true
def mypy_configuration_from_distribution(distribution: str) -> list[MypyDistConf]:
def mypy_configuration_from_distribution(distribution: str) -> list[MypyDistConf]:
"""
The configuration section in the metadata file looks like the following, with multiple module sections possible
```toml
[mypy-tests]
[mypy-tests.yaml]
module_name = "yaml"
[mypy-tests.yaml.values]
disallow_incomplete_defs = true
disallow_untyped_defs = true
```
"""

Copy link
Collaborator

Choose a reason for hiding this comment

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

I actually prefer this to be a comment. It doesn't really feel like something that's relevant to the API. That said, it would probably be better to document it in CONTRIBUTING instead.

@srittau srittau merged commit 5faa040 into python:main Apr 28, 2025
58 checks passed
@Avasam Avasam deleted the Apply-mypy-tests-custom-config-to-other-mypy-based-tests branch April 28, 2025 14:27
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