Make Counter generic over the value
Closes: #3438
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
@erictraut: I'm unsure why pyright fails the test case as written: https://github.com/python/typeshed/actions/runs/8613668710/job/23605460935?pr=11632
custom_c = cast("Counter[str, Foo]", Counter())
# [...]
custom_c["a"] += 42 # type: ignore
pyright claims that the type ignore is unnecessary here, but unless I'm missing something, both __getitem__() and __setitem()__ are annotated to require a Foo instance, not int in this case.
I'm not able to repro the problem when I copy and paste your modified definition of Counter along with the minimal test case snippet. When I do that, pyright generates an error for custom_c["a"] += 42 as I would expect. So there must be something else going on with your test if you're not seeing this error.
I remember that this is at least the second time, where a pyright "bug" can't be reproduced outside our CI environment. Something strange is going on with our CI it seems.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
The weird CI problems are gone now. Ready to review.
Diff from mypy_primer, showing the effect of this PR on open source code:
materialize (https://github.com/MaterializeInc/materialize)
+ misc/python/materialize/parallel_workload/parallel_workload.py:326: error: Argument 1 to "defaultdict" has incompatible type "type[Counter[_T, _C]]"; expected "Callable[[], Counter[Never, Never]] | None" [arg-type]