Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add inverted options and strict mode #2710

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

Merged
merged 9 commits into from
Jan 24, 2017
Merged

Add inverted options and strict mode #2710

merged 9 commits into from
Jan 24, 2017

Conversation

ddfisher
Copy link
Collaborator

Alternative to #2700 with less boilerplate. Fixes #2585.

@ddfisher
Copy link
Collaborator Author

@alexjurkiewicz, how does this look to you?

@ddfisher ddfisher force-pushed the strict-mode-2 branch 2 times, most recently from f7b6c50 to 68c893d Compare January 18, 2017 23:12
strict_flag_names = [] # type: List[str]
strict_flag_assignments = [] # type: List[Tuple[str, bool]]

def add_invertable_flag(flag, *, inverse, default, dest=None, help, strict_flag=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/invertable/invertible/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@alexjurkiewicz
Copy link
Contributor

I like it! Does this work if I run mypy with --strict --allow-untyped-calls? Doesn't the logic at line 348 mean strict mode cannot be overridden?

@ddfisher
Copy link
Collaborator Author

Oops! Fixed.

@alexjurkiewicz
Copy link
Contributor

OK, that logic is much cleaner :)

Regarding the param names, I am not a huge fan of a non-standard approach to option inverses (allow -> disallow, foo -> no-foo, fast -> old, more?). I think it will make understanding any given commandline much harder for those not intimately familiar with the mypy options.

Linters generally use a symbolic approach like --enable-checks E123,E456 --disable-checks E789,012
GCC example from the original PR uses a common prefix of -Wno-

Either of those I prefer.

Beyond that, 👍 and thanks 🙌 !

@alexjurkiewicz alexjurkiewicz mentioned this pull request Jan 18, 2017
@alexjurkiewicz
Copy link
Contributor

Because the opt-out names aren't standard, they may need to be documented somehow. Users probably can't guess that the opposite of --check-untyped-defs is --ignore-untyped-defs.

I was going to suggest adding the inverse to the end of the argument's help text (perhaps only if it's a strict option), but this might be too verbose. No other good ideas immediately...

@gnprice
Copy link
Collaborator

gnprice commented Jan 19, 2017

To my eye "allow"<->"disallow" and "show"<->"hide" feel very predictable and natural, but "check"<->"ignore" much less so.

I think it may be because "allow"<->"disallow" is adding/removing an explicit negation, and "show"<->"hide" is a very common opposition in a wide range of UIs, while "check" vs. "ignore" isn't a standard pairing. Especially when looking at "ignore", there are a lot of possible opposites for that and it isn't obvious that the opposite will be "check". I don't think I'd be sure even looking at the pair "ignore" and "check", in say two different scripts or a CLI invocation that was overriding a config file, that they were exact opposites and there wasn't some third alternative.

Perhaps --no-check-untyped-defs, but allow/disallow and show/hide?

@ddfisher
Copy link
Collaborator Author

ddfisher commented Jan 19, 2017

I agree that check/ignore and fast/old aren't obvious opposites. I'll change both of those to use the generic --no- prefix.

This PR does document the inverse flags, actually -- it adds them to the help output of the standard flag. E.g.:

  --disallow-untyped-calls  disallow calling functions without type
                            annotations from functions with type annotations
                            (inverse: --allow-untyped-calls)
  --disallow-untyped-defs   disallow defining functions without type
                            annotations or with incomplete type annotations
                            (inverse: --allow-untyped-defs)
  --check-untyped-defs      type check the interior of functions without type
                            annotations (inverse: --no-check-untyped-defs)

@ddfisher
Copy link
Collaborator Author

@alexjurkiewicz does this seems reasonable to you? If so, I'll merge.

@ddfisher
Copy link
Collaborator Author

Ah, my understanding is that you're on vacation. We'd like to have the inverted options, so I'm going to merge this (and my understanding is that the --strict flag is in pretty good shape here).

This PR hasn't received detailed review, but enough people have looked at it (and it's an isolated-enough part of the code) that the merge feels reasonable.

@ddfisher ddfisher merged commit 038a2ec into master Jan 24, 2017
@ddfisher ddfisher deleted the strict-mode-2 branch January 24, 2017 01:13
@alexjurkiewicz
Copy link
Contributor

Yes, I am away, my email reply went AWOL apparently. Thanks for helping out / rewriting this feature! I really appreciate the assistance 👍

@ddfisher
Copy link
Collaborator Author

Glad I could help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants