-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Counter() support non-int #3438
Comments
While the |
Actually I overlooked the big box which says:
PRs to improve |
Some previous discussion in python/mypy#4032 |
Hi, I arrived here from python/mypy#4032. I'm trying to use Are we in a discussion about whether the standard library's |
Note that changes to |
This is a good example, where defaults for type vars (python/typing#307) would come in handy. |
Have there been any changes in this or any suggested work-arounds? I'm using |
Feel free to file a PR to see what
You could just use class DefaultDictWithTotal(defaultdict):
def total(self) -> float:
'Sum of the counts'
return sum(self.values()) |
Thanks. FWIW, in order to pass
and then to use it: |
I marked this as deferred for now, pending the implementation of type var defaults. |
See #11422 for the type var generics feature tracker. |
Type var defaults are now available. |
@srittau I also opened up a PR for this, that I think covers some of the additional edge cases that weren't covered, but happy to close it if you prefer to simply implement them, or if you want to take a look. |
I'm quite surprised because I can use a Counter to store non-integer values. Is it a feature or just permissiveness in implementation?
E.g. the following code works (tested on python 3.7.4):
The text was updated successfully, but these errors were encountered: