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

Switch attribute for unique and/or full Cases #451

Open
awygle opened this issue Jul 26, 2020 · 7 comments
Open

Switch attribute for unique and/or full Cases #451

awygle opened this issue Jul 26, 2020 · 7 comments

Comments

@awygle
Copy link
Collaborator

@awygle awygle commented Jul 26, 2020

It would be useful to be able to indicate that a Switch should cover all possible Cases, or at least that the given Cases should not overlap.

@jeanthom
Copy link

@jeanthom jeanthom commented Jul 28, 2020

Somewhat related to #404 and #436

@whitequark
Copy link
Member

@whitequark whitequark commented Jul 28, 2020

Yeah, I think all of these should be implemented as lints with configurable severity.

@awygle
Copy link
Collaborator Author

@awygle awygle commented Aug 3, 2020

I actually disagree that these should be lints. To my mind, a lint would make sense if the property we were looking for wasn't wholly contained to a particular language construct. In this case, the semantics of Switch(mode="full") vs Switch(mode="unique") vs Switch(mode="priority") (syntax descriptive only at this time) are both well-defined and entirely contained to the Switch context manager. Can you explain on your thinking as to why these would be lints?

@whitequark
Copy link
Member

@whitequark whitequark commented Aug 3, 2020

Can you explain on your thinking as to why these would be lints?

Two reasons:

  1. Lints are something that can be removed without changing the semantics of the program at all. Not everything that fulfills this requirement must be a lint, but lints are generally more lightweight, so I default to those.
  2. In my mind, people will want something along the lines of "please ensure all of the cases in my program/file/module are full", and lints would need to have a mechanism for inheriting them from outer scopes.

@awygle
Copy link
Collaborator Author

@awygle awygle commented Aug 3, 2020

I see. I agree that 2 is a good reason to have a lint. I'll sit and think a bit about whether I want a lint also or a lint instead.

For 1, what do you mean by "lightweight"? Syntactically, at least the way I'm imagining them working (and yes, I know we haven't designed them yet), from a user perspective using a lint would be heavier-weight than passing a constructor argument (not to mention adding rightward lean), but maybe you have a different mental picture.

@whitequark
Copy link
Member

@whitequark whitequark commented Aug 3, 2020

For 1, what do you mean by "lightweight"?

In the sense that it doesn't introduce changes to the core language, not in terms of end-user syntax. I agree that syntactically a lint can end up being heavier.

@whitequark
Copy link
Member

@whitequark whitequark commented Aug 17, 2020

We discussed this on the meeting. The conclusion was that we want both the Switch-specific attribute (syntactically a kwarg) and a lint, because they serve different goals: Switch(mode="unique") explicitly declares intent for this specific Switch, whereas enabling a lint that warns (or errors) on non-unique switches implicitly analyzes your code for suspicious constructs in general.

Also, without the kwarg, disabling the lint for just a single Switch that may contain nested Switches introduces extreme rightward drift of 2 indents, which would likely significantly detract from the lint's usability. In other words, the kwarg completes the lint instead of competing with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants