Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ def fix_instance(
else:
unpacked = [arg]
for arg in unpacked:
with state.strict_optional_set(options.strict_optional):
with state.strict_optional_set(True):
# Gradually expand defaults, as they may depend on previous variables.
if tv.has_default():
arg = expand_type(arg, env)
Expand Down
22 changes: 22 additions & 0 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,28 @@ class SupportsIndex(Protocol):
def __index__(self) -> int: ...
[builtins fixtures/slice.pyi]

[case testSliceWithPerFileStrictOptional]
# flags: --no-strict-optional
# mypy: strict-optional
"x"[1:]
[file builtins.py]
from typing import Generic, TypeVar

_StartT = TypeVar("_StartT", covariant=True)
_StopT = TypeVar("_StopT", covariant=True, default=_StartT)
_StepT = TypeVar("_StepT", covariant=True, default=_StartT | _StopT)

class object:
def __init__(self) -> None: pass
class type: pass
class tuple(Generic[_StartT]): pass
class function: pass
class int: pass
class str:
def __getitem__(self, index: slice[int | None]) -> str: pass
class slice(Generic[_StartT, _StopT, _StepT]): pass
class dict: pass

[case testNoneSliceBounds]
from typing import Any
a: Any
Expand Down
Loading