GeezerVison is showing github.com — Fix strict optional with generic defaults (#21788) · python/mypy@60fa82e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: mypy/typeanal.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2189,7 +2189,7 @@ def fix_instance( |
2189 | 2189 | else: |
2190 | 2190 | unpacked = [arg] |
2191 | 2191 | for arg in unpacked: |
2192 | | - with state.strict_optional_set(options.strict_optional): |
| 2192 | + with state.strict_optional_set(True): |
2193 | 2193 | # Gradually expand defaults, as they may depend on previous variables. |
2194 | 2194 | if tv.has_default(): |
2195 | 2195 | arg = expand_type(arg, env) |
|
Collapse file
Copy file name to clipboardExpand all lines: test-data/unit/check-expressions.test +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1248,6 +1248,28 @@ class SupportsIndex(Protocol): |
1248 | 1248 | def __index__(self) -> int: ... |
1249 | 1249 | [builtins fixtures/slice.pyi] |
1250 | 1250 |
|
| 1251 | +[case testSliceWithPerFileStrictOptional] |
| 1252 | +# flags: --no-strict-optional |
| 1253 | +# mypy: strict-optional |
| 1254 | +"x"[1:] |
| 1255 | +[file builtins.py] |
| 1256 | +from typing import Generic, TypeVar |
| 1257 | + |
| 1258 | +_StartT = TypeVar("_StartT", covariant=True) |
| 1259 | +_StopT = TypeVar("_StopT", covariant=True, default=_StartT) |
| 1260 | +_StepT = TypeVar("_StepT", covariant=True, default=_StartT | _StopT) |
| 1261 | + |
| 1262 | +class object: |
| 1263 | + def __init__(self) -> None: pass |
| 1264 | +class type: pass |
| 1265 | +class tuple(Generic[_StartT]): pass |
| 1266 | +class function: pass |
| 1267 | +class int: pass |
| 1268 | +class str: |
| 1269 | + def __getitem__(self, index: slice[int | None]) -> str: pass |
| 1270 | +class slice(Generic[_StartT, _StopT, _StepT]): pass |
| 1271 | +class dict: pass |
| 1272 | + |
1251 | 1273 | [case testNoneSliceBounds] |
1252 | 1274 | from typing import Any |
1253 | 1275 | a: Any |
|