Skip to content

Commit e4400ed

Browse files
committed
Rename argument to strict_optional
1 parent 9405b87 commit e4400ed

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

mypy/expandtype.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def expand_type(
5454
env: Mapping[TypeVarId, Type],
5555
allow_erased_callables: bool = ...,
5656
*,
57-
keep_none_type: bool = ...,
57+
strict_optional: bool = ...,
5858
) -> ProperType:
5959
...
6060

@@ -65,7 +65,7 @@ def expand_type(
6565
env: Mapping[TypeVarId, Type],
6666
allow_erased_callables: bool = ...,
6767
*,
68-
keep_none_type: bool = ...,
68+
strict_optional: bool = ...,
6969
) -> Type:
7070
...
7171

@@ -75,12 +75,12 @@ def expand_type(
7575
env: Mapping[TypeVarId, Type],
7676
allow_erased_callables: bool = False,
7777
*,
78-
keep_none_type: bool = False,
78+
strict_optional: bool = False,
7979
) -> Type:
8080
"""Substitute any type variable references in a type given by a type
8181
environment.
8282
"""
83-
return typ.accept(ExpandTypeVisitor(env, allow_erased_callables, keep_none_type))
83+
return typ.accept(ExpandTypeVisitor(env, allow_erased_callables, strict_optional))
8484

8585

8686
@overload
@@ -198,11 +198,11 @@ def __init__(
198198
self,
199199
variables: Mapping[TypeVarId, Type],
200200
allow_erased_callables: bool = False,
201-
keep_none_type: bool = False,
201+
strict_optional: bool = False,
202202
) -> None:
203203
self.variables = variables
204204
self.allow_erased_callables = allow_erased_callables
205-
self.keep_none_type = keep_none_type
205+
self.strict_optional = strict_optional
206206
self.recursive_guard: set[Type | tuple[int, Type]] = set()
207207

208208
def visit_unbound_type(self, t: UnboundType) -> Type:
@@ -486,7 +486,7 @@ def visit_union_type(self, t: UnionType) -> Type:
486486
# might be subtypes of others, however calling make_simplified_union()
487487
# can cause recursion, so we just remove strict duplicates.
488488
return UnionType.make_union(
489-
remove_trivial(flatten_nested_unions(expanded), self.keep_none_type), t.line, t.column
489+
remove_trivial(flatten_nested_unions(expanded), self.strict_optional), t.line, t.column
490490
)
491491

492492
def visit_partial_type(self, t: PartialType) -> Type:

mypy/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ def fix_instance(
16921692
args.append(arg)
16931693
env[tv.id] = arg
16941694
t.args = tuple(args)
1695-
fixed = expand_type(t, env, keep_none_type=True)
1695+
fixed = expand_type(t, env, strict_optional=True)
16961696
assert isinstance(fixed, Instance)
16971697
t.args = fixed.args
16981698

mypy/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,7 @@ def store_argument_type(
36793679
defn.arguments[i].variable.type = arg_type
36803680

36813681

3682-
def remove_trivial(types: Iterable[Type], keep_none_type: bool = False) -> list[Type]:
3682+
def remove_trivial(types: Iterable[Type], strict_optional: bool = False) -> list[Type]:
36833683
"""Make trivial simplifications on a list of types without calling is_subtype().
36843684
36853685
This makes following simplifications:
@@ -3694,7 +3694,7 @@ def remove_trivial(types: Iterable[Type], keep_none_type: bool = False) -> list[
36943694
p_t = get_proper_type(t)
36953695
if isinstance(p_t, UninhabitedType):
36963696
continue
3697-
if isinstance(p_t, NoneType) and not state.strict_optional and not keep_none_type:
3697+
if isinstance(p_t, NoneType) and not state.strict_optional and not strict_optional:
36983698
removed_none = True
36993699
continue
37003700
if isinstance(p_t, Instance) and p_t.type.fullname == "builtins.object":

0 commit comments

Comments
 (0)