Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-implicit-optional to mypy #10091

Closed
wants to merge 18 commits into from

Conversation

DiddiLeija
Copy link
Member

@DiddiLeija DiddiLeija commented Jun 21, 2021

It must close #10076, to include all the strict flags from Mypy to be used on pypa/pip (they are included by --strict).

It must close pypa#10076, to include all the strict flags from Mypy to be used on pypa/pip.
@uranusjr uranusjr added the skip news Does not need a NEWS file entry (eg: trivial changes) label Jun 21, 2021
@DiddiLeija
Copy link
Member Author

Hi. I'm having a weird error message. I haven't modified anything for this pull request, but got this:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

src/pip/_internal/utils/setuptools_build.py:23: error: Incompatible default for
argument "global_options" (default has type "None", argument has type
"Sequence[str]")
        global_options=None,  # type: Sequence[str]
                       ^
src/pip/_internal/utils/pkg_resources.py:28: error: Returning Any from function
declared to return "Iterable[str]"
            return yield_lines(self.get_metadata(name))
            ^
src/pip/_internal/utils/glibc.py:61: error: Returning Any from function
declared to return "Optional[str]"
        return version_str
        ^
src/pip/_internal/utils/virtualenv.py:20: error: Returning Any from function
declared to return "bool"
        return sys.prefix != getattr(sys, "base_prefix", sys.prefix)
        ^
src/pip/_internal/utils/appdirs.py:17: error: Returning Any from function
declared to return "str"
        return _appdirs.user_cache_dir(appname, appauthor=False)
        ^
src/pip/_internal/utils/appdirs.py:17: error: Call to untyped function
"user_cache_dir" in typed context
        return _appdirs.user_cache_dir(appname, appauthor=False)
               ^
src/pip/_internal/utils/appdirs.py:22: error: Call to untyped function
"user_config_dir" in typed context
        path = _appdirs.user_config_dir(appname, appauthor=False, roaming=...
               ^
src/pip/_internal/utils/appdirs.py:27: error: Returning Any from function
declared to return "str"
        return path
        ^
src/pip/_internal/utils/appdirs.py:34: error: Call to untyped function
"site_config_dir" in typed context
        dirval = _appdirs.site_config_dir(appname, appauthor=False, multip...
                 ^
src/pip/_internal/utils/appdirs.py:37: error: Returning Any from function
declared to return "List[str]"
            return dirval.split(os.pathsep) + ["/etc"]
            ^
src/pip/_internal/utils/misc.py:38: error: Module 'pip._vendor.tenacity' does
not explicitly export attribute 'stop_after_delay'; implicit reexport disabled
    from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
    ^
src/pip/_internal/utils/misc.py:38: error: Module 'pip._vendor.tenacity' does
not explicitly export attribute 'wait_fixed'; implicit reexport disabled
    from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
    ^
src/pip/_internal/utils/misc.py:731: error: Returning Any from function
declared to return "bool"
            return self.secret == other.secret
            ^
src/pip/_internal/utils/filesystem.py:12: error: Module 'pip._vendor.tenacity'
does not explicitly export attribute 'stop_after_delay'; implicit reexport
disabled
    from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
    ^
src/pip/_internal/utils/filesystem.py:12: error: Module 'pip._vendor.tenacity'
does not explicitly export attribute 'wait_fixed'; implicit reexport disabled
    from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
    ^
src/pip/_internal/utils/packaging.py:80: error: Returning Any from function
declared to return "Optional[str]"
        return requires_python
        ^
src/pip/_internal/utils/packaging.py:88: error: Returning Any from function
declared to return "str"
                    return line.strip()
                    ^
src/pip/_internal/utils/logging.py:86: error: Returning Any from function
declared to return "int"
        return getattr(_log_state, "indentation", 0)
        ^
src/pip/_internal/utils/logging.py:164: error: Incompatible default for
argument "no_color" (default has type "None", argument has type "bool")
        def __init__(self, stream=None, no_color=None):
                                                 ^
src/pip/_internal/metadata/base.py:7: error: Module 'pip._internal.utils.misc'
does not explicitly export attribute 'stdlib_pkgs'; implicit reexport disabled
    from pip._internal.utils.misc import stdlib_pkgs  # TODO: Move definit...
    ^
src/pip/_internal/utils/hashes.py:31: error: Incompatible default for argument
"hashes" (default has type "None", argument has type "Dict[str, List[str]]")
        def __init__(self, hashes=None):
                                  ^
src/pip/_internal/cli/progress_bars.py:107: error: "int" not callable
            self.original_handler(signum, frame)
            ^
src/pip/_internal/cli/progress_bars.py:107: error: "Handlers" not callable
            self.original_handler(signum, frame)
            ^
src/pip/_internal/cli/progress_bars.py:107: error: "None" not callable
            self.original_handler(signum, frame)
            ^
src/pip/_internal/cli/progress_bars.py:110: error: Class cannot subclass 'Bar'
(has type 'Any')
    class SilentBar(Bar):
                    ^
src/pip/_internal/cli/progress_bars.py:116: error: Class cannot subclass
'IncrementalBar' (has type 'Any')
    class BlueEmojiBar(IncrementalBar):
                       ^
src/pip/_internal/cli/progress_bars.py:156: error: "DownloadProgressMixin" has
no attribute "next"
                self.next(len(x))  # noqa: B305
                ^
src/pip/_internal/cli/progress_bars.py:157: error: "DownloadProgressMixin" has
no attribute "finish"
            self.finish()
            ^
src/pip/_internal/cli/progress_bars.py:197: error: Class cannot subclass
'_BaseBar' (has type 'Any')
    class DefaultDownloadProgressBar(BaseDownloadProgressBar, _BaseBar):
                                                              ^
src/pip/_internal/cli/progress_bars.py:205: error: Class cannot subclass 'Bar'
(has type 'Any')
    class DownloadBar(BaseDownloadProgressBar, Bar):
                                               ^
src/pip/_internal/cli/progress_bars.py:209: error: Class cannot subclass
'FillingCirclesBar' (has type 'Any')
    ...DownloadFillingCirclesBar(BaseDownloadProgressBar, FillingCirclesBar):
                                                          ^
src/pip/_internal/cli/progress_bars.py:218: error: Class cannot subclass
'Spinner' (has type 'Any')
        WindowsMixin, InterruptibleMixin, DownloadProgressMixin, Spinner
                                                                 ^
src/pip/_internal/cli/progress_bars.py:228: error: Returning Any from function
declared to return "str"
            return next(self._phaser)
            ^
src/pip/_internal/cli/progress_bars.py:259: error: "WindowsMixin" has no
attribute "iter"
            return BAR_TYPES[progress_bar][1]().iter
                   ^
src/pip/_internal/metadata/pkg_resources.py:30: error: Returning Any from
function declared to return "Optional[str]"
            return self._dist.location
            ^
src/pip/_internal/metadata/pkg_resources.py:37: error: Returning Any from
function declared to return "Optional[str]"
                    return line.split(":", 1)[-1].strip()
                    ^
src/pip/_internal/cli/parser.py:12: error: Module 'pip._internal.configuration'
does not explicitly export attribute 'ConfigurationError'; implicit reexport
disabled
    from pip._internal.configuration import Configuration, ConfigurationEr...
    ^
src/pip/_internal/commands/__init__.py:99: error: Returning Any from function
declared to return "Command"
        return command
        ^
src/pip/_internal/cli/autocompletion.py:129: error: Returning Any from function
declared to return "Optional[str]"
                        return opt.metavar
                        ^
src/pip/_internal/pyproject.py:62: error: Call to untyped function (unknown) in
typed context
                pp_toml = toml.load(f)
                          ^
src/pip/_internal/network/cache.py:9: error: Module
'pip._vendor.cachecontrol.caches' does not explicitly export attribute
'FileCache'; implicit reexport disabled
    from pip._vendor.cachecontrol.caches import FileCache
    ^
src/pip/_internal/network/cache.py:18: error: Returning Any from function
declared to return "bool"
        return getattr(response, "from_cache", False)
        ^
src/pip/_internal/cli/spinners.py:30: error: Incompatible default for argument
"file" (default has type "None", argument has type "IO[str]")
            file=None,
                 ^
src/pip/_internal/req/req_uninstall.py:15: error: Module
'pip._internal.utils.logging' does not explicitly export attribute 'getLogger';
implicit reexport disabled
    from pip._internal.utils.logging import getLogger, indent_log
    ^
src/pip/_internal/utils/unpacking.py:89: error: Returning Any from function
declared to return "bool"
        return prefix == abs_directory
        ^
src/pip/_internal/utils/subprocess.py:9: error: Module
'pip._internal.utils.logging' does not explicitly export attribute 'VERBOSE';
implicit reexport disabled
    from pip._internal.utils.logging import VERBOSE, subprocess_logger
    ^
src/pip/_internal/operations/install/wheel.py:453: error: Call to untyped
function "get_export_entry" in typed context
        entry = get_export_entry(specification)
                ^
src/pip/_internal/operations/install/wheel.py:459: error: Incompatible default
for argument "options" (default has type "None", argument has type
"Dict[str, Any]")
        def make(self, specification, options=None):
                                              ^
src/pip/_internal/operations/install/wheel.py:462: error: Returning Any from
function declared to return "List[str]"
            return super().make(specification, options)
            ^
src/pip/_internal/operations/install/wheel.py:462: error: Call to untyped
function "make" in typed context
            return super().make(specification, options)
                   ^
src/pip/_internal/operations/install/wheel.py:699: error: Call to untyped
function "PipScriptMaker" in typed context
        maker = PipScriptMaker(None, scheme.scripts)
                ^
src/pip/_internal/operations/install/wheel.py:720: error: Call to untyped
function "make_multiple" in typed context
        generated_console_scripts = maker.make_multiple(scripts_to_generat...
                                    ^
src/pip/_internal/operations/install/wheel.py:724: error: Call to untyped
function "make_multiple" in typed context
            maker.make_multiple(gui_scripts_to_generate, {'gui': True})
            ^
src/pip/_internal/build_env.py:16: error: Module 'pip._vendor.certifi' does not
explicitly export attribute 'where'; implicit reexport disabled
    from pip._vendor.certifi import where
    ^
src/pip/_internal/network/auth.py:14: error: Module
'pip._internal.utils.logging' does not explicitly export attribute 'getLogger';
implicit reexport disabled
    from pip._internal.utils.logging import getLogger
    ^
src/pip/_internal/network/auth.py:72: error: Class cannot subclass 'AuthBase'
(has type 'Any')
    class MultiDomainBasicAuth(AuthBase):
                               ^
src/pip/_internal/vcs/subversion.py:198: error: Incompatible default for
argument "use_interactive" (default has type "None", argument has type "bool")
        def __init__(self, use_interactive=None):
                                           ^
src/pip/_internal/operations/build/metadata.py:31: error: Call to untyped
function "prepare_metadata_for_build_wheel" in typed context
                distinfo_dir = backend.prepare_metadata_for_build_wheel(
                               ^
src/pip/_internal/models/link.py:217: error: Module 'pip._internal.vcs' does
not explicitly export attribute 'vcs'; implicit reexport disabled
            from pip._internal.vcs import vcs
            ^
src/pip/_internal/network/session.py:30: error: Module
'pip._vendor.cachecontrol' does not explicitly export attribute
'CacheControlAdapter'; implicit reexport disabled
    from pip._vendor.cachecontrol import CacheControlAdapter
    ^
src/pip/_internal/network/session.py:199: error: Class cannot subclass
'BaseAdapter' (has type 'Any')
    class LocalFSAdapter(BaseAdapter):
                         ^
src/pip/_internal/network/session.py:241: error: Class cannot subclass
'HTTPAdapter' (has type 'Any')
    class InsecureHTTPAdapter(HTTPAdapter):
                              ^
src/pip/_internal/network/session.py:254: error: Class cannot subclass
'CacheControlAdapter' (has type 'Any')
    class InsecureCacheControlAdapter(CacheControlAdapter):
                                      ^
src/pip/_internal/network/session.py:267: error: Class cannot subclass
'Session' (has type 'Any')
    class PipSession(requests.Session):
                     ^
src/pip/_internal/utils/direct_url_helpers.py:16: error: Module
'pip._internal.vcs' does not explicitly export attribute 'vcs'; implicit
reexport disabled
    from pip._internal.vcs import vcs
    ^
src/pip/_internal/req/req_install.py:55: error: Module 'pip._internal.vcs' does
not explicitly export attribute 'vcs'; implicit reexport disabled
    from pip._internal.vcs import vcs
    ^
src/pip/_internal/req/req_install.py:250: error: Returning Any from function
declared to return "Optional[str]"
            return pkg_resources.safe_name(self.req.name)
            ^
src/pip/_internal/req/req_install.py:508: error: Call to untyped function
"Pep517HookCaller" in typed context
            self.pep517_backend = Pep517HookCaller(
                                  ^
src/pip/_internal/index/sources.py:10: error: Module 'pip._internal.vcs' does
not explicitly export attribute 'is_url'; implicit reexport disabled
    from pip._internal.vcs import is_url
    ^
src/pip/_internal/index/collector.py:39: error: Module 'pip._internal.vcs' does
not explicitly export attribute 'vcs'; implicit reexport disabled
    from pip._internal.vcs import vcs
    ^
src/pip/_internal/index/collector.py:57: error: Returning Any from function
declared to return "Optional[str]"
                return scheme
                ^
src/pip/_internal/index/collector.py:327: error: Call to untyped function
"parse" in typed context
        document = html5lib.parse(
                   ^
src/pip/_internal/operations/build/wheel.py:31: error: Call to untyped function
"build_wheel" in typed context
                wheel_name = backend.build_wheel(
                             ^
src/pip/_internal/commands/cache.py:10: error: Module
'pip._internal.utils.logging' does not explicitly export attribute 'getLogger';
implicit reexport disabled
    from pip._internal.utils.logging import getLogger
    ^
src/pip/_internal/network/download.py:70: error: Returning Any from function
declared to return "Iterable[bytes]"
        return DownloadProgressProvider(
        ^
src/pip/_internal/network/download.py:70: error: Call to untyped function
"DownloadProgressProvider" in typed context
        return DownloadProgressProvider(
               ^
src/pip/_internal/commands/configuration.py:153: error: Returning Any from
function declared to return "Optional[Kind]"
                    return kinds.SITE
                    ^
src/pip/_internal/commands/configuration.py:155: error: Returning Any from
function declared to return "Optional[Kind]"
                    return kinds.USER
                    ^
src/pip/_internal/commands/configuration.py:157: error: Returning Any from
function declared to return "Optional[Kind]"
                return file_options[0]
                ^
src/pip/_internal/commands/configuration.py:274: error: Returning Any from
function declared to return "str"
                return options.editor
                ^
src/pip/_internal/req/constructors.py:31: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'is_url'; implicit reexport disabled
    from pip._internal.vcs import is_url, vcs
    ^
src/pip/_internal/req/constructors.py:31: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'vcs'; implicit reexport disabled
    from pip._internal.vcs import is_url, vcs
    ^
docs/pip_sphinxext.py:20: error: Class cannot subclass 'Directive' (has type
'Any')
    class PipNewsInclude(rst.Directive):
                         ^
docs/pip_sphinxext.py:76: error: Class cannot subclass 'Directive' (has type
'Any')
    class PipCommandUsage(rst.Directive):
                          ^
docs/pip_sphinxext.py:92: error: Class cannot subclass 'Directive' (has type
'Any')
    class PipCommandDescription(rst.Directive):
                                ^
docs/pip_sphinxext.py:108: error: Class cannot subclass 'Directive' (has type
'Any')
    class PipOptions(rst.Directive):
                     ^
docs/pip_sphinxext.py:218: error: Class cannot subclass 'Directive' (has type
'Any')
    class PipCLIDirective(rst.Directive):
                          ^
src/pip/_internal/commands/debug.py:10: error: Module 'pip._vendor.certifi'
does not explicitly export attribute 'where'; implicit reexport disabled
    from pip._vendor.certifi import where
    ^
src/pip/_internal/commands/debug.py:71: error: Returning Any from function
declared to return Module
        return getattr(pip._vendor, module_name)
        ^
src/pip/_internal/commands/debug.py:86: error: Returning Any from function
declared to return "Optional[str]"
        return version
        ^
src/pip/_internal/operations/freeze.py:179: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'RemoteNotFoundError'; implicit reexport
disabled
        from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidE...
        ^
src/pip/_internal/operations/freeze.py:179: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'RemoteNotValidError'; implicit reexport
disabled
        from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidE...
        ^
src/pip/_internal/operations/freeze.py:179: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'vcs'; implicit reexport disabled
        from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidE...
        ^
src/pip/_internal/distributions/sdist.py:88: error: Call to untyped function
"get_requires_for_build_wheel" in typed context
                    reqs = backend.get_requires_for_build_wheel()
                           ^
src/pip/_internal/resolution/resolvelib/found_candidates.py:92: error: Class
cannot subclass 'Sequence' (has type 'Any')
    class FoundCandidates(collections_abc.Sequence):
                          ^
src/pip/_internal/wheel_builder.py:27: error: Module 'pip._internal.vcs' does
not explicitly export attribute 'vcs'; implicit reexport disabled
    from pip._internal.vcs import vcs
    ^
src/pip/_internal/operations/prepare.py:45: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'vcs'; implicit reexport disabled
    from pip._internal.vcs import vcs
    ^
src/pip/_internal/cli/req_command.py:205: error: Returning Any from function
declared to return "Optional[int]"
                return func(self, options, args)
                ^
src/pip/_internal/cli/req_command.py:241: error: Incompatible default for
argument "download_dir" (default has type "None", argument has type "str")
            download_dir=None,  # type: str
                         ^
src/pip/_internal/commands/list.py:235: error: Returning Any from function
declared to return "SupportsLessThan"
                key=lambda dist: dist.project_name.lower(),
                                 ^
src/pip/_internal/commands/install.py:31: error: Module
'pip._internal.utils.logging' does not explicitly export attribute 'getLogger';
implicit reexport disabled
    from pip._internal.utils.logging import getLogger
    ^
Found 101 errors in 48 files (checked 150 source files)

use logger.warning(......................................................Passed
check for eval().........................................................Passed
rst ``code`` is two backticks............................................Passed
NEWS fragment........................................(no files to check)Skipped
check-manifest...........................................................Passed
Error: The process '/opt/hostedtoolcache/Python/3.9.5/x64/bin/pre-commit' failed with exit code 1

I think it is because mypy --strict runs after I enabled it, and found those errors. What do you think about this?

@pfmoore
Copy link
Member

pfmoore commented Jun 21, 2021

I think you're right, these are issues that mypy detects in strict mode, and they will need fixing before we enable --strict.

To be clear, I would not assume that all of these are simply incorrect annotations, nor would I necessarily assume that the right fix should be to relax or adjust type annotations to make the checks pass. It's quite possible that mypy is reporting genuine code issues here. (In fact, I sort of hope it is, otherwise we're putting a lot of effort into annotations and it's not giving us much back in terms of better error detection 🙂)

@DiddiLeija
Copy link
Member Author

Actually, there are some errors unrelated to annotations (well, I think so 😅 ). For example, look at these fragments:

src/pip/_internal/models/link.py:217: error: Module 'pip._internal.vcs' does
not explicitly export attribute 'vcs'; implicit reexport disabled
            from pip._internal.vcs import vcs
            ^
src/pip/_internal/network/session.py:30: error: Module
'pip._vendor.cachecontrol' does not explicitly export attribute
'CacheControlAdapter'; implicit reexport disabled
    from pip._vendor.cachecontrol import CacheControlAdapter
    ^
src/pip/_internal/network/session.py:199: error: Class cannot subclass
'BaseAdapter' (has type 'Any')
    class LocalFSAdapter(BaseAdapter):
                         ^
src/pip/_internal/network/session.py:241: error: Class cannot subclass
'HTTPAdapter' (has type 'Any')
    class InsecureHTTPAdapter(HTTPAdapter):
                              ^
src/pip/_internal/network/session.py:254: error: Class cannot subclass
'CacheControlAdapter' (has type 'Any')
    class InsecureCacheControlAdapter(CacheControlAdapter):
                                      ^
src/pip/_internal/network/session.py:267: error: Class cannot subclass
'Session' (has type 'Any')
    class PipSession(requests.Session):
                     ^
src/pip/_internal/utils/direct_url_helpers.py:16: error: Module
'pip._internal.vcs' does not explicitly export attribute 'vcs'; implicit
reexport disabled
    from pip._internal.vcs import vcs
    ^
src/pip/_internal/req/req_install.py:55: error: Module 'pip._internal.vcs' does
not explicitly export attribute 'vcs'; implicit reexport disabled
    from pip._internal.vcs import vcs
    ^
src/pip/_internal/commands/cache.py:10: error: Module
'pip._internal.utils.logging' does not explicitly export attribute 'getLogger';
implicit reexport disabled
    from pip._internal.utils.logging import getLogger
    ^
src/pip/_internal/commands/debug.py:10: error: Module 'pip._vendor.certifi'
does not explicitly export attribute 'where'; implicit reexport disabled
    from pip._vendor.certifi import where
    ^
src/pip/_internal/operations/freeze.py:179: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'RemoteNotFoundError'; implicit reexport
disabled
        from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidE...
        ^
src/pip/_internal/operations/freeze.py:179: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'RemoteNotValidError'; implicit reexport
disabled
        from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidE...
        ^
src/pip/_internal/operations/freeze.py:179: error: Module 'pip._internal.vcs'
does not explicitly export attribute 'vcs'; implicit reexport disabled
        from pip._internal.vcs import RemoteNotFoundError, RemoteNotValidE...
        ^

What do you think about them?

@pfmoore
Copy link
Member

pfmoore commented Jun 21, 2021

Why do you think they are unrelated? Did you check the mypy docs? I found this one, so I suspect the others are from mypy too.

@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 21, 2021

Why do you think they are unrelated?

@pfmoore, I didn't say they were unrelated to mypy, I said they are unrelated to --no-implicit-optional. I know that all the errors that I posted here are related to mypy.

@pfmoore
Copy link
Member

pfmoore commented Jun 21, 2021

Sorry, my misunderstanding. It looks like --strict enables a lot more than just --no-implicit-optional - we might want to consider whether we really want to enable all of those checks.

I'm not a good person to ask, I'm at best +0 on stricter typing (it feels to me like we spend more time fixing typing bugs than catching actual code issues, so I feel like we might have hit the point of diminishing returns here).

@DiddiLeija
Copy link
Member Author

Sorry, my misunderstanding.

Don't worry 😉.

I'm at best +0 on stricter typing (it feels to me like we spend more time fixing typing bugs than catching actual code issues, so I feel like we might have hit the point of diminishing returns here).

Might be. Anyway, I will keep this PR open if someone wants to comment about this.

@uranusjr
Copy link
Member

It feels like a good point to start though. If we decide we don’t like some typing checks, we can always disable them individually (--strict is simply a shorthand of a bunch of selective toggles). I took a look at the currently failing lint job and quite like this one, for example:

src/pip/_internal/utils/misc.py:38: error: Module 'pip._vendor.tenacity' does
not explicitly export attribute 'stop_after_delay'; implicit reexport disabled
    from pip._vendor.tenacity import retry, stop_after_delay, wait_fixed
    ^

@DiddiLeija
Copy link
Member Author

I will first add --no-implicit-optional (the original option we wanted to use).

It applies for the Mypy check.
@DiddiLeija
Copy link
Member Author

If we really need another strictness check, we can simply add them to the mypy args. Or maybe adding the whole --strict must be useful, but let's see.

@pfmoore
Copy link
Member

pfmoore commented Jun 21, 2021

I took a look at the currently failing lint job and quite like this one, for example

Does that one not mean that we either need to ask tenacity to change their export list, or change our code to use a dotted name? If we just switch the way we reference the name, I see no great benefit (and two minor disadvantages, in that it's more verbose and it will fail if someone changes it back expecting the two ways to be equivalent). Conversely, if we decide we should ask tenacity to change their code, that will add a whole load of busy-work for both us and them - and unless it turns out that we're actually using an API that they don't support, there's not much benefit.

Of course, if you're saying that our response to this message should be that we treat it as saying we're using an unsupported API and we should stop doing so then I guess that is a genuine code problem that the warning has picked up. But would we then rewrite that chunk of code to avoid using the unsupported API? Could we do that?

I still feel we've got more pressing things we should be spending our time on. And while I don't object to anyone spending their time however they want to, policy choices like this impact everyone contributing whether they support the check or not.

Disclaimer: I only skimmed the mypy description of the message, so I may well have misunderstood what it's saying.

Edit: I read the tenacity source. The re-exports in __init__.py are clearly deliberately intended to allow people to import the symbols from tenacity directly. IMO it's neither our, or mypy's place to be telling tenacity that they are doing this wrong 🙁

@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 21, 2021

Seems like we are going to need more time (and more people) to decide how to apply the mypy arguments. I'll convert this to draft.

@DiddiLeija DiddiLeija marked this pull request as draft June 21, 2021 18:27
@pfmoore
Copy link
Member

pfmoore commented Jun 21, 2021

Thanks.

Based on my analysis of the tenacity warning that @uranusjr pointed out, I'm a strong -1 on enabling --no-implicit-reexport.

@DiddiLeija
Copy link
Member Author

Based on my analysis of the tenacity warning that @uranusjr pointed out, I'm a strong -1 on enabling --no-implicit-reexport.

I agree with @pfmoore. That's why I only enabled the --no-implicit-optional instead of --strict by now.

@DiddiLeija DiddiLeija changed the title Add a --strict option to the Mypy checks Add strict options to the Mypy checks Jun 23, 2021
@DiddiLeija
Copy link
Member Author

DiddiLeija commented Jun 28, 2021

Is there any other strictness flag we can safely include? Tell me, and I'll add it as soon as possible.

@DiddiLeija
Copy link
Member Author

Any other strictness flag to include? We've already added --no-implicit-optional, and dropped --no-implicit-reexport. Anything else to include now?

@pradyunsg pradyunsg changed the title Add strict options to the Mypy checks Add --no-implicit-optional to mypy Jul 13, 2021
@pradyunsg
Copy link
Member

FWIW, another thing worth doing is removing # mypy: strict-optional=False comments from the codebase.

@pradyunsg
Copy link
Member

pradyunsg commented Jul 23, 2021

@DiddiLeija Could you rebase this PR instead of merging main repeatedly? In general, rebasing a PR will result in a cleaner "git history" when the PR is merged.

If you don't know what "rebase this PR" means, here's a resource: https://dev.to/matks/what-it-means-to-rebase-a-pull-request-submitted-on-github-5717 :)

@DiddiLeija
Copy link
Member Author

@DiddiLeija Could you rebase this PR instead of merging main repeatedly? In general, rebasing a PR will result in a cleaner "git history" when the PR is merged.

If you don't know what "rebase this PR" means, here's a resource: https://dev.to/matks/what-it-means-to-rebase-a-pull-request-submitted-on-github-5717 :)

Ok, I'll consider that in the future. Thanks @pradyunsg!

@uranusjr
Copy link
Member

FWIW we can always squash and rebase right before merging, so don't need to sweat too hard on this.

@github-actions github-actions bot added the needs rebase or merge PR has conflicts with current master label Aug 15, 2021
@DiddiLeija
Copy link
Member Author

I think #10439 could resolve this. If the "implicit optional" annotations are fixed, then I can merge main into this branch one single time. After that, I hope this won't fail (at least, there won't be a lot of things to do!).

@uranusjr uranusjr added the state: blocked Can not be done until something else is done label Sep 7, 2021
@DiddiLeija DiddiLeija changed the title Add --no-implicit-optional to mypy Add --no-implicit-optional to mypy Sep 13, 2021
@pradyunsg
Copy link
Member

What's the next steps here? I haven't really kept up with this whole discussion, and I'm not sure what all we want to do here.

@DiddiLeija
Copy link
Member Author

I want to enable --no-implicit-optional to mypy in our CI. We are waiting for #10439 to go ahead, because @jdufresne is trying to resolve most of the #mypy:strict-optional=False situations on that PR. I consider that would resolve our issues with the pre-commit check.

@DiddiLeija
Copy link
Member Author

Closing this, since our blocker (#10439) has been closed, so we can't go ahead for now. Maybe I will keep the linked issue open, so maybe we can solve it on the future.

@DiddiLeija DiddiLeija closed this Oct 19, 2021
@DiddiLeija DiddiLeija deleted the mypy-strict-flag branch October 19, 2021 14:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs rebase or merge PR has conflicts with current master skip news Does not need a NEWS file entry (eg: trivial changes) state: blocked Can not be done until something else is done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding the --strict option to mypy
5 participants