Repository navigation
Replace lists with tuples to improve type-inferrence - #17194
freundTech wants to merge 1 commit into
Conversation
|
The workflow failure seems to be related to CircleCI and not caused by my code. Maybe a rerun can fix it. CircleCI won't let the PR author trigger a rerun by themselves though. |
|
You can always rerun by rebasing, but I'm comfortable merging given the nature of the failure. |
|
@freundTech can you explain your reasoning for why you think those objects should be tuples rather than lists? |
|
The main reason those should be tuples is that the contained types are heterogeneous. The first entry is a value ( In addition Lists are mutable and therefor invariant. This means that for Using a tuple allows mypy to infer the types as This then goes on to cause a type-error in line 2044, because you obviously can't use an index accessor on |
|
I agree with the reasoning here. @freundTech Can you re-push to get a clean build? |
|
I believe it’s not correct to replace these lists with tuples, because Python-Markdown needs them to be mutable: |
|
Oh I see. This is a |
|
I just rebased this and the CI checks pass now. @andersk's solution looks good too, |
|
@freundTech Thanks for your work here! I ended up merging the commit from @andersk. Looking forward to more contributions. |
I recently submitted a PR to mypy, which improves handling of generic types. This PR, if accepted, would lead to a type-error being reported in your code which was previously not reported.
I described it in detail here in the mypy PR: python/mypy#9994 (comment)
Testing plan: I ran mypy, both the current version and the version with my PR against the source code