Skip to content
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

[regression] Files with mixed strict-optional forget None'able argument (with ParamSpec decorator) #16246

Closed
intgr opened this issue Oct 11, 2023 · 2 comments
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate topic-strict-optional

Comments

@intgr
Copy link
Contributor

intgr commented Oct 11, 2023

Bug Report

I am in the progress of introducing strict_optional in my project. Some files have strict_optional disabled, others enabled.

Updating from mypy 1.5.1 to 1.6.0 caused some false positives when passing None to x | None arguments that are called across module boundaries.

To Reproduce

module_a.py:

# mypy: no-strict-optional

from typing import Callable, ParamSpec, TypeVar

P = ParamSpec("P")
T = TypeVar("T")


def paramspec_decorator(func: Callable[P, T]) -> Callable[P, T]:
    return func


@paramspec_decorator
def example_func(arg: str | None) -> None:
    print(arg)

module_b.py:

from module_a import example_func

example_func(None)

Expected Behavior

example_func should accept None argument.

Actual Behavior

% mypy --strict module_b.py
module_b.py:3: error: Argument 1 to "example_func" has incompatible type "None"; expected "str"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.6.0
  • Mypy command-line flags: --strict
  • Python version used: 3.11.5
@intgr intgr added the bug mypy got something wrong label Oct 11, 2023
@AlexWaygood AlexWaygood added the topic-paramspec PEP 612, ParamSpec, Concatenate label Oct 11, 2023
@intgr intgr changed the title [regression] Files with mixed strict-optional forget None'abe argument (with ParamSpec decorator) [regression] Files with mixed strict-optional forget None'able argument (with ParamSpec decorator) Oct 11, 2023
@ilevkivskyi
Copy link
Member

I understand this behavior may be surprising, but this is not a bug actually. This behavior is consistent with how e.g. regular type variables (and other types) always behaved with no-strict-optional, see #15932 where this was originally reported. ParamSpec was accidentally special.

Note this flag doesn't mean "do not report errors related to None in this file" (because it is actually not a well defined thing), but rather "in this file None is considered as subtype of all types".

@ilevkivskyi ilevkivskyi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@intgr
Copy link
Contributor Author

intgr commented Oct 13, 2023

Fair enough, this can be solved on my end by migrating more files to strict_optional=true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate topic-strict-optional
Projects
None yet
Development

No branches or pull requests

3 participants