Skip to content

Conversation

@dkuku
Copy link

@dkuku dkuku commented Jul 30, 2020

cool lib but is failing for me on some mocked vins with invalid characters - can we add this checks ?

@nighcoder
Copy link
Owner

Greetings Daniel.
Thanks for your feedback.

I've had a look on your PR and I like the idea of checking for valid vins for every call to parsing functions, but I don't like having the valid function defined in two places. Is is_valid fn failing on your tests?
One thing is_valid does not check and your implementation does is to check if argument is string. So maybe we can add the string check to is_valid and use that in the valid wrapper?

@dkuku
Copy link
Author

dkuku commented Jul 30, 2020 via email

@dkuku
Copy link
Author

dkuku commented Jul 30, 2020

The decorator can take the optional param. With a set of options O(1) access time and no order. Then in every if test you just add as first argument 'set contains param and' current test then check I , if param won't be in set then it will be skipped.

@dkuku
Copy link
Author

dkuku commented Jul 30, 2020

Or it can also use optional kwargs - its more pythonic this way when I think about it. Still can accept a dict of **options, then it should work with editor code completion

@nighcoder
Copy link
Owner

nighcoder commented Jul 30, 2020

we have vins with spaces in our app. Currently it passes the tests with these in your lib

is_valid should not return True for strings that contain spaces. If it does, it's a bug.
I tried it with some vin strings with spaces and returned false.
If you mean the tests in the project, I see that not all tests check for valid vins so I guess those will pass with vins with spaces.

@nighcoder
Copy link
Owner

I like the idea of adding extra arguments to parsing fns to fine tune their behaviour. I would remove the upper wrapper and add an ignore_case=True extra param to each function.

I was aware that most fns (except parser) don't check the validity of the input before parsing it, but didn't think of it as an issue at the time. I do realize now that returning a result for a junk string is error prone and confusing. So I'm wondering now if it's any value to adding the possibility of opting-out of input validation check.

I'm not sure I follow you about the checks. The only optional check I see when determining the validity is the check digit which is only enforced for NA vehicles. All the other checks (len = 17, is string, only valid chars) I see as non optional.

Other thing to note, if we're going to use is_valid as from inside the parser fns, we need to make it stop depending on country and its corner case where it returns unassigned.

@dkuku
Copy link
Author

dkuku commented Jul 31, 2020 via email

@nighcoder
Copy link
Owner

You make a good point about parsing partial input data.

I've checked some functions with your example and some functions return something, others return None. That doesn't feel right

I've checked a bit the function in question to check their requirements and I've found a minimal requirements for their inputs:

  • is a string
  • has only valid characters from CHARS
  • is no longer than 17 in length
  • doesn't start with 0

Some functions have additional requirements: like a minimal number of characters, or like check_valid that only work for North America.

Copy link
Owner

@nighcoder nighcoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think valid should return None if we're getting bad data. That way we can differentiate between False returned by a predicate and False returned by the wrapper.
As for the wrapper itself:

  • string check is ok
  • length check change to >17 to allow for partial vins
  • IOQ check is not enough... we have the whole unicode set to filter out. Use the CHARS constant to filter the input or just copy the relevant part from is_valid
  • I would also add the check that string does not start with 0.

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

Successfully merging this pull request may close these issues.

2 participants