-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Implement attr.converters.default_if_none #414
Conversation
Yeah this is something the plugin currently doesn't support:
The underlying problem is that it's hard to extract the type of the function call in the mypy pipeline. A workaround could be to write:
But that's broken also, but I think easier to fix. Now I remember, in our work code, when we started using mypy I removed all our uses of optional and just wrote our own converters. |
I guess until mypy opens up it's plugin API (I talked to Jukka here at EuroPython and it's legit on their roadmap) we’ll have to comment stuff out, wait for mypy to release the support? Having hard-coded support is “fine” for now… Does the signature look correct to you tho? If someone rubber-stamps it, I’ll just comment it out and we open an issue on mypy. |
I can review the signature. As for commenting it out I'm not sure since I'm not sure when we'll fix the plugin. It might be a while. |
Just to be clear: by special casing I mean that mypy only supports our shipped converters for now. Would that be a significant amount of work too? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being completely honest I wouldn't use this feature because if I passed in None
somewhere I would like it to blow up, or have mypy tell me about it so that I can handle it in the caller.
But the code all looks correct and the signature is pretty much what mypy wants it to be.
Hmm. Maybe I could detect the converters by name and handle them specially. That might actually work. |
Yeah, that’s what I was thinking. |
FYI: python/mypy#5411 Here's one implementing |
So this is a stab at #400 which I find a reasonable usage of converters.
Typing tests fail tho and they also fail for
attr.validators.optional
. Am I right to suspect that this has to be fixed in mypy's plugin? Gives us a bit of a Mexican stand-off, doesn't it? It’s completely possible that I additionally got the stubs wrong so feel free to advice.cc @euresti @chadrik