Skip to content

Commit 58003db

Browse files
committed
Rename argument to strict_optional
1 parent 675dc3f commit 58003db

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
@@ -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
) -> ProperType:
7070
...
7171

@@ -76,7 +76,7 @@ def expand_type(
7676
env: Mapping[TypeVarId, Type],
7777
allow_erased_callables: bool = ...,
7878
*,
79-
keep_none_type: bool = ...,
79+
strict_optional: bool = ...,
8080
) -> Type:
8181
...
8282

@@ -86,12 +86,12 @@ def expand_type(
8686
env: Mapping[TypeVarId, Type],
8787
allow_erased_callables: bool = False,
8888
*,
89-
keep_none_type: bool = False,
89+
strict_optional: bool = False,
9090
) -> Type:
9191
"""Substitute any type variable references in a type given by a type
9292
environment.
9393
"""
94-
return typ.accept(ExpandTypeVisitor(env, allow_erased_callables, keep_none_type))
94+
return typ.accept(ExpandTypeVisitor(env, allow_erased_callables, strict_optional))
9595

9696

9797
@overload
@@ -214,11 +214,11 @@ def __init__(
214214
self,
215215
variables: Mapping[TypeVarId, Type],
216216
allow_erased_callables: bool = False,
217-
keep_none_type: bool = False,
217+
strict_optional: bool = False,
218218
) -> None:
219219
self.variables = variables
220220
self.allow_erased_callables = allow_erased_callables
221-
self.keep_none_type = keep_none_type
221+
self.strict_optional = strict_optional
222222
self.recursive_guard: set[Type | tuple[int, Type]] = set()
223223

224224
def visit_unbound_type(self, t: UnboundType) -> Type:
@@ -502,7 +502,7 @@ def visit_union_type(self, t: UnionType) -> Type:
502502
# might be subtypes of others, however calling make_simplified_union()
503503
# can cause recursion, so we just remove strict duplicates.
504504
return UnionType.make_union(
505-
remove_trivial(flatten_nested_unions(expanded), self.keep_none_type), t.line, t.column
505+
remove_trivial(flatten_nested_unions(expanded), self.strict_optional), t.line, t.column
506506
)
507507

508508
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
@@ -3684,7 +3684,7 @@ def store_argument_type(
36843684
defn.arguments[i].variable.type = arg_type
36853685

36863686

3687-
def remove_trivial(types: Iterable[Type], keep_none_type: bool = False) -> list[Type]:
3687+
def remove_trivial(types: Iterable[Type], strict_optional: bool = False) -> list[Type]:
36883688
"""Make trivial simplifications on a list of types without calling is_subtype().
36893689
36903690
This makes following simplifications:
@@ -3699,7 +3699,7 @@ def remove_trivial(types: Iterable[Type], keep_none_type: bool = False) -> list[
36993699
p_t = get_proper_type(t)
37003700
if isinstance(p_t, UninhabitedType):
37013701
continue
3702-
if isinstance(p_t, NoneType) and not state.strict_optional and not keep_none_type:
3702+
if isinstance(p_t, NoneType) and not state.strict_optional and not strict_optional:
37033703
removed_none = True
37043704
continue
37053705
if isinstance(p_t, Instance) and p_t.type.fullname == "builtins.object":

0 commit comments

Comments
 (0)