Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
srittau
left a comment
There was a problem hiding this comment.
Thanks, but please use the new union syntax (i.e. Foo | Bar).
|
I considered doing this earlier, but didn't because I think this will be slightly annoying, since the idiomatic way to narrow is There probably isn't a good solution here, but just wanted to call it out. |
|
Yes, I had the same concern as Shantanu. I think PEP 661 (https://www.python.org/dev/peps/pep-0661/) would provide a cleaner solution. |
|
Maybe @altendky has a use case that requires this change? We can always change over to PEP 661 when that gets accepted and is available for use. That said, I have no opinion, what solution is best. |
|
We could define Edit: PEP 661 mentions this as a rejected idea, but unlike most of their other rejected ideas, it actually works and it was apparently rejected only because nobody likes it. |
|
Welp, of course the time I don't chat about a change first it ends up deserving discussion. if field.default_factory != dataclasses.MISSING: # type: ignore[misc]Here's a minimal example. Note that the first error seems to be python/mypy#10750 and I was already avoiding it with https://mypy-play.net/?mypy=latest&python=3.10&flags=strict&gist=f66bb887158648e99b97c042165dd684 import dataclasses
@dataclasses.dataclass
class C:
f: int = 0
for field in dataclasses.fields(C):
if field.default_factory != dataclasses.MISSING:
passI just tried Regardless, I'll be adding an ignore "for now" since of course this wouldn't be released anyways. If there's another more proper solution and this isn't a useful interrim change, I can handle that. Thanks to all for the interest and effort here. |
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: pydantic (https://github.com/samuelcolvin/pydantic.git)
- pydantic/dataclasses.py:174: error: unused "type: ignore" comment
|
srittau
left a comment
There was a problem hiding this comment.
This looks fine to me, but I'll defer judgement to @hauntsaninja and @JelleZijlstra.
|
I'd prefer to stick with the current stub until PEP 661 gives us better tools to deal with this situation. |
No description provided.