diff --git a/docs/source/running_mypy.rst b/docs/source/running_mypy.rst index 5096b00446bc9..2e482b599a887 100644 --- a/docs/source/running_mypy.rst +++ b/docs/source/running_mypy.rst @@ -214,8 +214,6 @@ accepts one of four string values: replace the module (and *anything imported from it*) with an object of type ``Any``. - (Note: this option used to be known as ``--silent-imports``.) - - ``error`` behaves in the same way as ``skip`` but is not quite as silent -- it will flag the import as an error, like this:: diff --git a/mypy/checker.py b/mypy/checker.py index d9fb20aa3a00f..72c53f0500ab8 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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? diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 95a4ecdf2c1a4..a540a25b88e2e 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -2929,12 +2929,7 @@ def check_for_comp(self, e: Union[GeneratorExpr, DictionaryComprehension]) -> No self.chk.binder.put(var, type) 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) + self.accept(e.cond) ctx = self.type_context[-1] # Gain type information from isinstance if it is there diff --git a/mypy/main.py b/mypy/main.py index 4d491f1f990f8..86cf12330b351 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -689,30 +689,10 @@ def add_invertible_flag(flag: str, help=argparse.SUPPRESS) # deprecated options - parser.add_argument('--disallow-any', dest='special-opts:disallow_any', - help=argparse.SUPPRESS) - add_invertible_flag('--strict-boolean', default=False, - help=argparse.SUPPRESS) - parser.add_argument('-f', '--dirty-stubs', action='store_true', - dest='special-opts:dirty_stubs', - help=argparse.SUPPRESS) - parser.add_argument('--use-python-path', action='store_true', - dest='special-opts:use_python_path', - help=argparse.SUPPRESS) - parser.add_argument('-s', '--silent-imports', action='store_true', - dest='special-opts:silent_imports', - help=argparse.SUPPRESS) - parser.add_argument('--almost-silent', action='store_true', - dest='special-opts:almost_silent', - help=argparse.SUPPRESS) - parser.add_argument('--fast-parser', action='store_true', dest='special-opts:fast_parser', - help=argparse.SUPPRESS) - parser.add_argument('--no-fast-parser', action='store_true', - dest='special-opts:no_fast_parser', - 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 " @@ -757,42 +737,7 @@ def add_invertible_flag(flag: str, special_opts = argparse.Namespace() parser.parse_args(args, SplitNamespace(options, special_opts, 'special-opts:')) - # --use-python-path is no longer supported; explain why. - if special_opts.use_python_path: - parser.error("Sorry, --use-python-path is no longer supported.\n" - "If you are trying this because your code depends on a library module,\n" - "you should really investigate how to obtain stubs for that module.\n" - "See https://github.com/python/mypy/issues/1411 for more discussion." - ) - # Process deprecated options - if special_opts.disallow_any: - print("--disallow-any option was split up into multiple flags. " - "See http://mypy.readthedocs.io/en/latest/command_line.html#disallow-dynamic-typing", - file=sys.stderr) - if options.strict_boolean: - print("Warning: --strict-boolean is deprecated; " - "see https://github.com/python/mypy/issues/3195", file=sys.stderr) - if special_opts.almost_silent: - print("Warning: --almost-silent has been replaced by " - "--follow-imports=errors", file=sys.stderr) - if options.follow_imports == 'normal': - options.follow_imports = 'errors' - elif special_opts.silent_imports: - print("Warning: --silent-imports has been replaced by " - "--ignore-missing-imports --follow-imports=skip", file=sys.stderr) - options.ignore_missing_imports = True - if options.follow_imports == 'normal': - options.follow_imports = 'skip' - if special_opts.dirty_stubs: - print("Warning: -f/--dirty-stubs is deprecated and no longer necessary. Mypy no longer " - "checks the git status of stubs.", - file=sys.stderr) - if special_opts.fast_parser: - print("Warning: --fast-parser is now the default (and only) parser.") - if special_opts.no_fast_parser: - print("Warning: --no-fast-parser no longer has any effect. The fast parser " - "is now mypy's default and only parser.", 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) diff --git a/mypy/messages.py b/mypy/messages.py index 5800c4fc20a5f..2162c06acbf01 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -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 diff --git a/mypy/options.py b/mypy/options.py index a9743deea97ce..7388c241f9a29 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -43,7 +43,6 @@ class BuildType: "mypyc", "no_implicit_optional", "show_none_errors", - "strict_boolean", "strict_optional", "strict_optional_whitelist", "warn_no_return", @@ -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 diff --git a/test-data/unit/check-async-await.test b/test-data/unit/check-async-await.test index df67f89aad4cf..5f47cae0d3bf0 100644 --- a/test-data/unit/check-async-await.test +++ b/test-data/unit/check-async-await.test @@ -183,7 +183,7 @@ async def f() -> None: [typing fixtures/typing-full.pyi] [case testAsyncForComprehension] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import Generic, Iterable, TypeVar, AsyncIterator, Tuple T = TypeVar('T') @@ -223,7 +223,7 @@ async def generatorexp(obj: Iterable[int]): [typing fixtures/typing-full.pyi] [case testAsyncForComprehensionErrors] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import Generic, Iterable, TypeVar, AsyncIterator, Tuple T = TypeVar('T') @@ -489,7 +489,7 @@ async def user() -> None: [typing fixtures/typing-full.pyi] [case testAsyncGeneratorAsend] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import AsyncGenerator async def f() -> None: @@ -510,7 +510,7 @@ async def h() -> None: [typing fixtures/typing-full.pyi] [case testAsyncGeneratorAthrow] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import AsyncGenerator async def gen() -> AsyncGenerator[str, int]: @@ -529,7 +529,7 @@ async def h() -> None: [typing fixtures/typing-full.pyi] [case testAsyncGeneratorNoSyncIteration] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import AsyncGenerator async def gen() -> AsyncGenerator[int, None]: @@ -547,7 +547,7 @@ def h() -> None: main:9: error: "AsyncGenerator[int, None]" has no attribute "__iter__"; maybe "__aiter__"? (not iterable) [case testAsyncGeneratorNoYieldFrom] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import AsyncGenerator async def f() -> AsyncGenerator[int, None]: @@ -560,7 +560,7 @@ async def gen() -> AsyncGenerator[int, None]: [typing fixtures/typing-full.pyi] [case testAsyncGeneratorNoReturnWithValue] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import AsyncGenerator async def return_int() -> AsyncGenerator[int, None]: diff --git a/test-data/unit/check-class-namedtuple.test b/test-data/unit/check-class-namedtuple.test index 9e91a5c098ab3..8273c87178a8c 100644 --- a/test-data/unit/check-class-namedtuple.test +++ b/test-data/unit/check-class-namedtuple.test @@ -391,7 +391,7 @@ def f(a: Type[N]): main:9: error: Too few arguments for "N" [case testNewNamedTupleWithDefaults] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import List, NamedTuple, Optional class X(NamedTuple): @@ -431,7 +431,7 @@ UserDefined(1) # E: Argument 1 to "UserDefined" has incompatible type "int"; ex [builtins fixtures/list.pyi] [case testNewNamedTupleWithDefaultsStrictOptional] -# flags: --fast-parser --strict-optional --python-version 3.6 +# flags: --strict-optional --python-version 3.6 from typing import List, NamedTuple, Optional class HasNone(NamedTuple): @@ -450,7 +450,7 @@ class CannotBeNone(NamedTuple): [builtins fixtures/list.pyi] [case testNewNamedTupleWrongType] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import NamedTuple class X(NamedTuple): @@ -458,14 +458,14 @@ class X(NamedTuple): y: int = 'not an int' # E: Incompatible types in assignment (expression has type "str", variable has type "int") [case testNewNamedTupleErrorInDefault] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import NamedTuple class X(NamedTuple): x: int = 1 + '1' # E: Unsupported operand types for + ("int" and "str") [case testNewNamedTupleInheritance] -# flags: --fast-parser --python-version 3.6 +# flags: --python-version 3.6 from typing import NamedTuple class X(NamedTuple): diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 67eb8df5ed486..55d6b3921588e 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -446,70 +446,6 @@ main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" from mod import x [out] -[case testStrictBoolean] -# flags: --strict-boolean -if True: - pass -if 'test': # E: Condition must be a boolean - pass -elif 1: # E: Condition must be a boolean - pass - -def f() -> bool: - return True - -if f: # E: Condition must be a boolean - pass - -if f(): - pass - -class A: - def __call__(self) -> bool: - return False - -if A: # E: Condition must be a boolean - pass - -if A(): # E: Condition must be a boolean - pass - -if A()(): - pass -[builtins fixtures/bool.pyi] - -[case testStrictBooleanTernary] -# flags: --strict-boolean -x = 1 if 'test' else 2 # E: Condition must be a boolean -y = 1 if not 'test' else 2 -[builtins fixtures/bool.pyi] - -[case testStrictBooleanWhile] -# flags: --strict-boolean -while 5: # E: Condition must be a boolean - pass - -while False: - pass -[builtins fixtures/bool.pyi] - -[case testStrictBooleanComplexTypes] -# flags: --strict-boolean -from typing import Any, Type, Union - -x = True # type: Any -y = True # type: Union[bool, int] -z = int # type: Type[int] - -if x: - pass -if y: # E: Condition must be a boolean - pass -if z: # E: Condition must be a boolean - pass -[builtins fixtures/bool.pyi] - - [case testPerFileIncompleteDefsBasic] # flags: --config-file tmp/mypy.ini import standard, incomplete