Comments (7)
@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 pass
case.
This feels like the case about declaring bit masks for filters alike firewall works
class PluginsFilterBits(object):
"""A class for filter bits."""
known_to_renderfarm = FilterBit(bit=0b0100, name="known_to_renderfarm") # noqa: WPS339
built_in = FilterBit(bit=0b0010, name="built_in") # noqa: WPS339
is_script = FilterBit(bit=0b0001, name="is_script") # noqa: WPS339
weird = FilterBit(bit=0b1000, name="weird") # noqa: WPS339
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.
from wemake-python-styleguide.
@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?
from wemake-python-styleguide.
Hm, interesting.
The other way would be:
>>> match (None, 2):
... case (x, _) if x is not None:
... raise ValueError
...
But, I agree that pass
seems like the clearest solution here.
from wemake-python-styleguide.
Do we really
have to make our match statements inclusive? Is there a need for
case (None, _): pass
at all?
It wouldn't match - the code wouldn't execute - basically the pass statement. Am I wrong here?
from wemake-python-styleguide.
pass
here means exactly what it should do in the first place: nothing.
So, providing pass
in a case
statement means that this case does not do anything.
As far as I know, there's no other way to describe the same thing without pass
and using ...
here is not correct.
from wemake-python-styleguide.
Why would we even declare a pass
?
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.
from wemake-python-styleguide.
@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 noqa
comment and forgot about the problem :D
from wemake-python-styleguide.
Related Issues (20)
- Ignoring the absence of a new line between methods
- Gihub Action: Unable to process file command 'output' successfully. HOT 2
- Forbid importing the same object with two different names.
- Pydocstyle is no longer maintained HOT 1
- WPS473 is counted lines containing concatenated strings as empty. HOT 1
- False positive WPS441
- Disallow suppressing CancelledError
- def func(): ... causes false positives for WPS220, E704 and WPS473 HOT 6
- WPS508 on negating chain comparison HOT 4
- `self._tokens[1]`: `IndexError: list index out of range`
- Question about WPS324 — Enforce consistent return statements. HOT 2
- How to set up WPS (wemake-python-styleguide) autocheck in PyCharm HOT 1
- Drop `astor` in favour of `ast.unparse`
- Remove usage of deprecated nodes: `ast.Num`, `ast.Str`, `ast.Bytes`, etc
- Better detect literal nodes with `wps_op_eval`
- Do we still need `fix_line_number`?
- Too many exceptions in one `except`
- WPS221 wrong case
- WPS331 should recommend the opposite HOT 2
- Drop the abandoned `flake8-commas` plugin from deps HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wemake-python-styleguide.