Skip to content

customize validator to reject NaN, Infinity #1010

Answered by Julian
stealthrabbi asked this question in Q&A
Discussion options

You must be logged in to vote

There may be more than one problem, but there's certainly at least one simple one, which is you did:

type_checker = (
            Draft7Validator.TYPE_CHECKER.redefine("number", self.is_my_int),
        )

probably using the parentheses to break up the line, but that's a 1-element tuple, because you have a comma there.

So you've passed a tuple in as a type checker, when the right type for that argument is an instance of TypeChecker (which redefine returns).

You want just type_checker = Draft7Validator.TYPE_CHECKER.redefine("number", self.is_my_int) or if you want it on multiple lines remove the comma.

Beyond that it'd be helpful to see a bit more of a fully functioning example to offer ad…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stealthrabbi
Comment options

Answer selected by stealthrabbi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants