diff --git a/setup.cfg b/setup.cfg index 60e866562cd..40faad55a2e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,7 +64,7 @@ formats = sdist.tgz,bdist_wheel [mypy] ignore_missing_imports = True -no_implicit_optional = True +no_implicit_optional = False strict_equality = True warn_redundant_casts = True warn_return_any = True diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 694f45fb6d4..a0ffecd607f 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -403,9 +403,7 @@ class ExceptionInfo(Generic[_E]): @classmethod def from_exc_info( - cls, - exc_info: Tuple["Type[_E]", "_E", TracebackType], - exprinfo: Optional[str] = None, + cls, exc_info: Tuple["Type[_E]", "_E", TracebackType], exprinfo: str = None ) -> "ExceptionInfo[_E]": """returns an ExceptionInfo for an existing exc_info tuple. @@ -429,9 +427,7 @@ def from_exc_info( return cls(exc_info, _striptext) @classmethod - def from_current( - cls, exprinfo: Optional[str] = None - ) -> "ExceptionInfo[BaseException]": + def from_current(cls, exprinfo: str = None) -> "ExceptionInfo[BaseException]": """returns an ExceptionInfo matching the current traceback .. warning:: diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index f06c9cfffb1..bcf56b10273 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -1,6 +1,5 @@ import os from typing import List -from typing import Optional import py @@ -108,10 +107,7 @@ def get_dir_from_path(path): def determine_setup( - inifile: str, - args: List[str], - rootdir_cmd_arg: Optional[str] = None, - config: Optional["Config"] = None, + inifile: str, args: List[str], rootdir_cmd_arg: str = None, config: "Config" = None ): dirs = get_dirs_from_args(args) if inifile: diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index 94713662571..0beeced0df7 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -17,7 +17,7 @@ class OutcomeException(BaseException): contain info about test and collection outcomes. """ - def __init__(self, msg: Optional[str] = None, pytrace: bool = True) -> None: + def __init__(self, msg: str = None, pytrace: bool = True) -> None: if msg is not None and not isinstance(msg, str): error_msg = ( "{} expected string as 'msg' parameter, got '{}' instead.\n" @@ -45,10 +45,7 @@ class Skipped(OutcomeException): __module__ = "builtins" def __init__( - self, - msg: Optional[str] = None, - pytrace: bool = True, - allow_module_level: bool = False, + self, msg: str = None, pytrace: bool = True, allow_module_level: bool = False ) -> None: OutcomeException.__init__(self, msg=msg, pytrace=pytrace) self.allow_module_level = allow_module_level @@ -63,9 +60,7 @@ class Failed(OutcomeException): class Exit(Exception): """ raised for immediate program exits (no tracebacks/summaries)""" - def __init__( - self, msg: str = "unknown reason", returncode: Optional[int] = None - ) -> None: + def __init__(self, msg: str = "unknown reason", returncode: int = None) -> None: self.msg = msg self.returncode = returncode super().__init__(msg) @@ -74,7 +69,7 @@ def __init__( # exposed helper methods -def exit(msg: str, returncode: Optional[int] = None) -> "NoReturn": +def exit(msg: str, returncode: int = None) -> "NoReturn": """ Exit testing process. @@ -155,7 +150,7 @@ def xfail(reason: str = "") -> "NoReturn": def importorskip( - modname: str, minversion: Optional[str] = None, reason: Optional[str] = None + modname: str, minversion: str = None, reason: Optional[str] = None ) -> Any: """Imports and returns the requested module ``modname``, or skip the current test if the module cannot be imported. diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index f03d45ab76c..bffda93a908 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -567,7 +567,7 @@ def raises( def raises( # noqa: F811 expected_exception: Union["Type[_E]", Tuple["Type[_E]", ...]], *args: Any, - match: Optional[Union[str, "Pattern"]] = None, + match: Union[str, "Pattern"] = None, **kwargs: Any ) -> Union["RaisesContext[_E]", Optional[_pytest._code.ExceptionInfo[_E]]]: r""" @@ -725,7 +725,7 @@ def __init__( self, expected_exception: Union["Type[_E]", Tuple["Type[_E]", ...]], message: str, - match_expr: Optional[Union[str, "Pattern"]] = None, + match_expr: Union[str, "Pattern"] = None, ) -> None: self.expected_exception = expected_exception self.message = message diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 58076d66b9d..b5f3c723281 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -77,7 +77,7 @@ def warns( def warns( # noqa: F811 expected_warning: Union["Type[Warning]", Tuple["Type[Warning]", ...]], *args: Any, - match: Optional[Union[str, "Pattern"]] = None, + match: Union[str, "Pattern"] = None, **kwargs: Any ) -> Union["WarningsChecker", Any]: r"""Assert that code raises a particular class of warning. @@ -207,7 +207,7 @@ def __init__( expected_warning: Optional[ Union["Type[Warning]", Tuple["Type[Warning]", ...]] ] = None, - match_expr: Optional[Union[str, "Pattern"]] = None, + match_expr: Union[str, "Pattern"] = None, ) -> None: super().__init__()