GithubHelp home page GithubHelp logo

Comments (7)

Day0Dreamer avatar Day0Dreamer commented on May 20, 2024 1

@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.

kehrazy avatar kehrazy commented on May 20, 2024 1

@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.

sobolevn avatar sobolevn commented on May 20, 2024

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.

kehrazy avatar kehrazy commented on May 20, 2024

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.

sobolevn avatar sobolevn commented on May 20, 2024

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.

kehrazy avatar kehrazy commented on May 20, 2024

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.

Day0Dreamer avatar Day0Dreamer commented on May 20, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.