-
Couldn't load subscription status.
- Fork 275
Add typing.Counter and typing.ChainMap #366
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
Changes from all commits
3ae6137
4f5ad2c
a0baeb3
622ddfc
dd0eb3d
c0f748a
5c5c2e7
3dfbaf9
cbb42d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ | |
| 'SupportsRound', | ||
|
|
||
| # Concrete collection types. | ||
| 'Counter', | ||
| 'Deque', | ||
| 'Dict', | ||
| 'DefaultDict', | ||
|
|
@@ -1898,6 +1899,31 @@ def __new__(cls, *args, **kwds): | |
| return _generic_new(collections.defaultdict, cls, *args, **kwds) | ||
|
|
||
|
|
||
| class Counter(collections.Counter, Dict[T, int], extra=collections.Counter): | ||
|
|
||
| __slots__ = () | ||
|
|
||
| def __new__(cls, *args, **kwds): | ||
| if _geqv(cls, Counter): | ||
| return collections.Counter(*args, **kwds) | ||
| return _generic_new(collections.Counter, cls, *args, **kwds) | ||
|
|
||
|
|
||
| if hasattr(collections, 'ChainMap'): | ||
| # ChainMap only exists in 3.3+ | ||
| __all__.append('ChainMap') | ||
|
|
||
| class ChainMap(collections.ChainMap, MutableMapping[KT, VT], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typeshed defines this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think MutableMapping is right; ChainMap is not a subclass of dict. I'll submit that change to typeshed. |
||
| extra=collections.ChainMap): | ||
|
|
||
| __slots__ = () | ||
|
|
||
| def __new__(cls, *args, **kwds): | ||
| if _geqv(cls, ChainMap): | ||
| return collections.ChainMap(*args, **kwds) | ||
| return _generic_new(collections.ChainMap, cls, *args, **kwds) | ||
|
|
||
|
|
||
| # Determine what base class to use for Generator. | ||
| if hasattr(collections_abc, 'Generator'): | ||
| # Sufficiently recent versions of 3.5 have a Generator ABC. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test checking that a subclass of counter could be instantiated, as you do for
ChainMapintest_chainmap_subclass. (And also for Python 3)