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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ignore validators set to 'None' #1253

Closed
wants to merge 1 commit into from

Conversation

dodslaser
Copy link

@dodslaser dodslaser commented May 3, 2024

Fixes a regression in 4.22.0 where validators set to 'None' are not ignored, causing a TypeError: 'NoneType' object is not callable on validation. In version 4.21.1 and earlier, any validator set to None would be ignored.


馃摎 Documentation preview 馃摎: https://python-jsonschema--1253.org.readthedocs.build/en/1253/

Fixes a regression in 4.22.0 where validators set to 'None' are not ignored, causing a `TypeError: 'NoneType' object is not callable` on validation. In version 4.21.1 and earlier, any validator set to None would be ignored.
@Julian
Copy link
Member

Julian commented May 3, 2024

Hey there.

This isn't something I intentionally changed, but it's also not a regression really, the type of validators is (always was) documented to be callables with 4 arguments -- if you want one that does nothing just don't add it at all to extend, or add it and make it be a function which does nothing, but yeah I don't make any guarantees on what any sentinel value will do here, this all may change.

@dodslaser
Copy link
Author

Hey there.

This isn't something I intentionally changed, but it's also not a regression really, the type of validators is (always was) documented to be callables with 4 arguments -- if you want one that does nothing just don't add it at all to extend, or add it and make it be a function which does nothing, but yeah I don't make any guarantees on what any sentinel value will do here, this all may change.

OK, that makes sense. I originally noticed in the source that None validators would be ignored, so I assumed it was an intended feature to ignore a keyword. When this behavior broke with 1.22.0 I wasn't sure if that was on purpose.

I guess one could argue that ignoring a validator is cleaner (and potentially very slightly faster) than repeatedly calling a no-op function, but I haven't tested that, and I doubt I would notice a significant performance hit.

Either way, for my use case I can probably replace None with a lambda *_: ... and call it a day 馃槃

@Julian
Copy link
Member

Julian commented May 3, 2024

Definitely trust the docs for what's public API yeah.

Not including the keyword at all should be even faster if you want to micro-optimize, but yeah I doubt it will show up in any case.

(Thanks regardless for the PR).

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.

None yet

2 participants