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

Some (may be) bugs I found #2

Closed
dinkopehar opened this issue Nov 10, 2018 · 4 comments
Closed

Some (may be) bugs I found #2

dinkopehar opened this issue Nov 10, 2018 · 4 comments

Comments

@dinkopehar
Copy link
Contributor

Hi. Nice small library, tested out a lot of things. I really does match anything. But I found some mistakes or bugs.

  1. I know None is matched in _, but shouldn't None be matched with None also? For example:
x = None
print(match(x, None, 'None', _, 'Everything else')) => return Everything else
  1. If I match integer 1 or float 1.0 with True, shouldn't match function not match with those values ? Same is for 0 or 0.0 . I know 0 and 1 are also boolean False and True, but there are a lot of other false values too.
x = 1
print(match(x, True, 'True value', _, 'Everything else')) => returns True value
  1. Last thing, I don't know if you wanted this to match or no, but child class inhereting parent class, when matched with any of those classes, returns True.
class Parent:
    pass

class Child(Parent):
    pass

x = Child()
print(match(x, Parent, 'Child class', _, 'Everything else')) => returns Child class

Thank you for your time and time it took you to write this library 👍 👍 👍 .
I also made a pull request to fix some minor mistakes, so your welcome 🦊

@santinic
Copy link
Owner

santinic commented Nov 10, 2018

  1. You are right, fixed.
  2. You are so right, fixed.
  3. I didn't think about this. But it feels right, what do you think ? Matching parents allows to do clever stuff like:
class Pet: pass
class Dog(Pet): pass
class Cat(Pet): pass

match(obj,
  Dog, 'dog',
  Cat, 'cat',
  Pet, 'any other pet',
  _, 'this is not a pet at all',
)

Thank you very much Dinko!

@santinic
Copy link
Owner

Fixed (among other things) in v0.1.6

@dinkopehar
Copy link
Contributor Author

I guess 3. bullet point you mentioned is valid, as long as the Classes are in order they are inherited from.

For example, if you have class Box that is parent of BoxWithLegs that is parent of BoxWithLegsAndArms, you have to type all them in order from Child to Parent, otherwise if you had type BoxWithLegsAndArms, their match would be instantly maybe Box or BoxWithLegs. Maybe you want that, maybe no. Your call, but anyway... thanks for merging my fork. It's my first merge 😄 .

@santinic
Copy link
Owner

Well, congratulation for your first merge ;)

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

No branches or pull requests

2 participants