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

--strict is too strict to be useful #7767

Closed
msullivan opened this issue Oct 21, 2019 · 9 comments
Closed

--strict is too strict to be useful #7767

msullivan opened this issue Oct 21, 2019 · 9 comments
Labels
needs discussion topic-configuration Configuration files and flags

Comments

@msullivan
Copy link
Collaborator

We provide a --strict flag that is strict enough that we can not use it in mypy itself, which is one of the most carefully typed projects I know of.

We should possibly consider removing some flags from strict.

@jstasiak
Copy link
Contributor

I've been thinking about something related recently – I think it'd be useful to have a way to disable some specific checks while enabling strict mode. So hypothetically --strict --allow-return-any would enable all strict checks but --disallow-return-any. Ideally strict could also go in the config file but that's another issue.

As it is now I often have mypy configurations that are quite repetitive and when a new check is introduced there's no way to have it enabled automatically after upgrading mypy (although I understand some people wouldn't like it).

@Michael0x2a
Copy link
Collaborator

@jstasiak -- I think overriding specific parts of --strict is actually currently supported. For example, I can suppress the return-any errors by doing mypy --strict --no-warn-return-any blah.py.

Somewhat tangentially: maybe we should rename --warn-return-any to --disallow-return-any. It'd definitely be more consistent that way.

@jstasiak
Copy link
Contributor

Lovely, I completely missed that! (+1 on renaming here)

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 28, 2019

I like the idea of making --strict only strict enough that we can reasonably use it in mypy. We could also support an ever stricter mode, such as --strict --strict that would enable more options still.

@SyntaxColoring
Copy link
Contributor

We could also support an ever stricter mode, such as --strict --strict that would enable more options still.

Having seen how this turned out with C and C++, be careful going down this path.

In C++, this is a common incantation to compile with the equivalent of "strict mode":

g++ -std=c++17 -Wall -Wextra -Wpedantic my_source_file.cpp
  • -std=c++17 selects the variant of the C++ standard to check against. In particular, this says to exclude non-standard GNU extensions.
  • -Wall enables all warnings.
  • -Wextra enables more warnings because I lied before; -Wall doesn't actually enable all warnings.
  • -Wpedantic enables more warnings on top of that!

That's a lot of arcane options to get the compiler to help you code better.

The end result is that unwary programmers write worse code because they don't know the magic words to get the compiler to help them.

@tony
Copy link

tony commented Aug 5, 2022

For anyone who happens upon this from google / searching, here's a recent example of mypy-ifying a project of mine so users can have an idea:

Warning: --strict diff is huge.

libvcs: Basic diff, --strict diff

libtmux: Basic diff, --strict diff

unihan-etl: Basic diff, --strict diff

tmuxp: Basic diff, More. --strict diff

@steve-mavens
Copy link

steve-mavens commented Jan 6, 2023

@SyntaxColoring That said, I would actually use an option that enables absolutely everything, and is guaranteed to do so in future. The reason is that when I'm writing a mypy config, I could enable that and then disable anything I need to. That is, every rule that's too strict for me, and I don't want to have to # type: ignore case by case. As it is, if I use strict = true there's no easy way to see whether there are any rules in mypy that are useful but that I need to opt into. So I end up browsing the config docs and then comparing everything that looks nice against the list of what's included in "strict".

When I bump mypy to a new version, I might have to exclude some new rules. But that's fine for me, because I only do that when I'm ready to tinker with the code and/or config. I won't come complaining that the latest mypy broke my build etc ;-)

@yokomotod
Copy link

With #13464, mypy project started to use --strict option, so

We provide a --strict flag that is strict enough that we can not use it in mypy itself

is no longer true.

Is that means --strict option is enough useful and recommended for normal users (who like the type safe) too?

I am currently considering enabling this option, but by finding this issue I am concerned that it is overly strict.

@hauntsaninja
Copy link
Collaborator

Plenty of people use strict on their projects.

By and large I'd define strict as "mostly the set of checks needed to ensure that you do not have any type unsoundness without an explicit circumvention of the type system, like type ignore, explicit use of Any or cast"

Note that you can turn on strict, then turn off individual checks that don't yet work well for you. I recently wrote up some advice to get to --strict over here: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion topic-configuration Configuration files and flags
Projects
None yet
Development

No branches or pull requests