Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
I didn't comment it on every instance, but the annoying thing with using list and dict as parameter types, is that they're invariant. Meaning unions have to be exact.
A list[str] cannot be passed to a list[str | int] parameter !
So everywhere you have a union like dict[str, Foo | Bar], you need to expand it to accept all possible permutations:
dict[str, Foo] | dict[str, Bar] | dict[str, Foo | Bar] (same with lists)
That's why, even though some methods not explicitly requiring a list or dict may be an implementation detail, I instead recommended some covariant types like Iterable and Mapping where possible.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Looks done 👍 |
Hmm... I'm not hard set on either. This is also something we can ask about upstream to get some clarification. My personal preference is to follow the implementation, and update it in a version bump PR if it changes. But I won't block on either. |
|
Using GitHub comments was a bit too complex to list the rest of the invariance issues, so I opened donbarbos#1 against your PR branch. |
|
Big thank to you. In the future I'll try to be more careful with invariant types |
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: dragonchain (https://github.com/dragonchain/dragonchain)
- dragonchain/job_processor/contract_job.py:251:16: error: Module has no attribute "errors" [attr-defined]
- dragonchain/job_processor/contract_job.py:268:17: error: Module has no attribute "errors" [attr-defined]
- dragonchain/job_processor/contract_job.py:280:16: error: Module has no attribute "errors" [attr-defined]
|
|
@Avasam if you want i can split this PR into several (like "Improve |
|
@donbarbos No worries! I was just giving this a week in case other maintainers wanted to take a look or had objections, then forgot. I'll merge, thanks for the ping. |
Co-authored-by: Avasam <samuel.06@hotmail.com>
No description provided.