You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems irrational to be, but to make validate (classmethod) work, you have to instantiate the Vin with a VIN number and call validate again with a VIN number.
Vin('someVIN').validate('someVIN') is the only way that I managed to make it work.
In my humble opinion, you should be able to check like so:
vin='SomeVIN'vin_object=Vin(vin)
vin_object.validate() # This returns True or False
P.S.1:
Or even better would be:
vin='SomeVIN'vin_object=Vin(vin)
ifvin_object.is_valid: # This returns True or Falseprint('Yay!')
vin_object.is_valid_with_exception() # or something like that>>>InvalidVIN: ThisVINnumberisinvalid.
P.S.2:
I had an idea:
defvalidate(self, num: str=None, with_exception: bool=False) ->str:
"""Performs basic VIN validation and sanation. :param num: Other VIN to check :param with_exception: Flag to determine if the validate function should raise an exception or not. """ifnumisNone:
num=self.numnum=num.strip().upper()
iflen(num) !=17:
raiseValidationError(f'VIN number requires 17 chars ({num_len} given)')
pattern=r"^[A-HJ-NPR-Z0-9]{17}$"ifnotre.match(pattern, num):
ifwith_exception:
raiseValidationError(f"VIN number must only contain alphanumeric symbols except 'I', 'O', and 'Q' ")
else:
returnFalsereturnTrue
Cheers 🍺
The text was updated successfully, but these errors were encountered:
validate() can be accessed explicitly (as a class method); otherwise it's called implicitly on object instantiation, so you do not need to call it again. And what is your use case?
It seems irrational to be, but to make validate (classmethod) work, you have to instantiate the Vin with a VIN number and call validate again with a VIN number.
Vin('someVIN').validate('someVIN')
is the only way that I managed to make it work.In my humble opinion, you should be able to check like so:
P.S.1:
Or even better would be:
P.S.2:
I had an idea:
Cheers 🍺
The text was updated successfully, but these errors were encountered: