-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
Possible use for pass
#2642
Comments
Hm, interesting. The other way would be: >>> match (None, 2):
... case (x, _) if x is not None:
... raise ValueError
... But, I agree that |
Do we It wouldn't match - the code wouldn't execute - basically the pass statement. Am I wrong here? |
@kehrazy I'd spend more time remembering and concluding why are there 3 cases for a problem with 2^2=4 possible solutions, than reading the This feels like the case about declaring bit masks for filters alike firewall works
It is useful for when debugging and mentally reiterating "This case works, this case works,, this case works,, this case works,, this case works, how many cases were there? Eight? Okay, I've checked all eight" Or with the bitmask - having it always in full length, with trailing zeroes, is in terms of Chat GPT, tokenizible. Meaning I can have for each bitmask remember it's feeling and operate with it, rather than pure logic. |
@Day0Dreamer hey, yeah, I can see the problem here, thanks for pointing this out. However, personally, when looking at this particular function, my brain goes "Yeah, this function handles these particular cases this way" - not "So, 2^2 - 4 cases... Huh, yeah, there's one that's not covered/handled here - should it be?" You can add a comment, after all. And yeah, I know about the "explicit is better than implicit" thing - does this apply here? |
As far as I know, there's no other way to describe the same thing without |
Why would we even declare a def verify_some_things(value_to_verify: int) -> bool:
"""
This function verifies a lot of cool data.
.. code:: python
>>> verify_some_things(2)
this is a two!
True
:param value_to_verify: an integer, the data to be verified.
:return: bool - True if successful, False if not.
"""
match value_to_verify:
case 1:
print("this is a one!")
return True
case 2:
print("this is a two!")
return True
return False
if __name__ == "__main__":
verify_some_things(1) # this is a two!
verify_some_things(2) # this is a two!
verify_some_things(3) # prints nothing, there's no values matching. |
@kehrazy this comes from a habit of making a truth tables, where each state is accounted for. From the field of general computer science and electronics. It's quite common while designing a logic machine, to start with a truth table, that describes all possible states. Overall, it's a human construct to help humans not forget stuff and make debugging more structured. What I think is actionable about this thread – documentation update. I really use a lot of the sections "This is a wrong way, this is a right way, this is the exception to the rule" inside the docs. p.s. — Already added a |
I've got another use-case for try:
some_data = find_a_thing()
except LookupError:
pass
else:
some_data.do_stuff() Of course, Doing with contextlib.suppress(LookupError):
some_data = find_a_thing()
some_data.do_stuff() is also a no-go since it has the same problem as several instructions in a Following the try-except-else idiom makes things clear, allowing me to communicate the intent. Using This all is to say that the assumption |
From:
WPS420 — Forbid some python keywords.
This is a snippet from a selector. In short, we need at the end a copy of render_data. We can get render_data out of doc, but sometimes we have only the data and no doc in sight.
It would seem, I literally want to just exit the match-case in a case where we have only render_data at the input.
Am I missing something?
The text was updated successfully, but these errors were encountered: