Skip to content

Commit

Permalink
Deprecate --strict-boolean
Browse files Browse the repository at this point in the history
(Putting this in a separate commit since it's more controversial --
since it did work, some people might still be using it, even though
it's been deprecated since May 2017.  See discussion in
python#3195.)
  • Loading branch information
Guido van Rossum committed Oct 5, 2018
1 parent d70ef2b commit 946be60
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 20 deletions.
5 changes: 0 additions & 5 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2693,11 +2693,6 @@ def visit_if_stmt(self, s: IfStmt) -> None:
if isinstance(t, DeletedType):
self.msg.deleted_as_rvalue(t, s)

if self.options.strict_boolean:
is_bool = isinstance(t, Instance) and t.type.fullname() == 'builtins.bool'
if not (is_bool or isinstance(t, AnyType)):
self.fail(messages.NON_BOOLEAN_IN_CONDITIONAL, e)

if_map, else_map = self.find_isinstance_check(e)

# XXX Issue a warning if condition is always False?
Expand Down
5 changes: 0 additions & 5 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2930,11 +2930,6 @@ def check_for_comp(self, e: Union[GeneratorExpr, DictionaryComprehension]) -> No

def visit_conditional_expr(self, e: ConditionalExpr) -> Type:
cond_type = self.accept(e.cond)
if self.chk.options.strict_boolean:
is_bool = (isinstance(cond_type, Instance)
and cond_type.type.fullname() == 'builtins.bool')
if not (is_bool or isinstance(cond_type, AnyType)):
self.chk.fail(messages.NON_BOOLEAN_IN_CONDITIONAL, e)
ctx = self.type_context[-1]

# Gain type information from isinstance if it is there
Expand Down
6 changes: 1 addition & 5 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,10 @@ def add_invertible_flag(flag: str,
help=argparse.SUPPRESS)

# deprecated options
add_invertible_flag('--strict-boolean', default=False,
help=argparse.SUPPRESS)
parser.add_argument('--quick-and-dirty', action='store_true',
help=argparse.SUPPRESS)

# options specifying code to check
code_group = parser.add_argument_group(
title="Running code",
description="Specify the code you want to type check. For more details, see "
Expand Down Expand Up @@ -739,9 +738,6 @@ def add_invertible_flag(flag: str,
parser.parse_args(args, SplitNamespace(options, special_opts, 'special-opts:'))

# Process deprecated options
if options.strict_boolean:
print("Warning: --strict-boolean is deprecated; "
"see https://github.com/python/mypy/issues/3195", file=sys.stderr)
if options.quick_and_dirty:
print("Warning: --quick-and-dirty is deprecated. It will disappear in the next release.",
file=sys.stderr)
Expand Down
1 change: 0 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
TYPEDDICT_KEY_MUST_BE_STRING_LITERAL = \
'Expected TypedDict key to be string literal' # type: Final
MALFORMED_ASSERT = 'Assertion is always true, perhaps remove parentheses?' # type: Final
NON_BOOLEAN_IN_CONDITIONAL = 'Condition must be a boolean' # type: Final
DUPLICATE_TYPE_SIGNATURES = 'Function has duplicate type signatures' # type: Final
GENERIC_INSTANCE_VAR_CLASS_ACCESS = \
'Access to generic instance variables via class is ambiguous' # type: Final
Expand Down
4 changes: 0 additions & 4 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class BuildType:
"mypyc",
"no_implicit_optional",
"show_none_errors",
"strict_boolean",
"strict_optional",
"strict_optional_whitelist",
"warn_no_return",
Expand Down Expand Up @@ -131,9 +130,6 @@ def __init__(self) -> None:
# Files in which to ignore all non-fatal errors
self.ignore_errors = False

# Only allow booleans in conditions
self.strict_boolean = False

# Apply strict None checking
self.strict_optional = True

Expand Down

0 comments on commit 946be60

Please sign in to comment.