8000 Kill __subclasscheck__ by ilevkivskyi · Pull Request #283 · python/typing · GitHub
[go: up one dir, main page]

Skip to content

Kill __subclasscheck__ #283

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

Merged
merged 28 commits into from
Sep 27, 2016
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7d73596
Started #136
ilevkivskyi Sep 18, 2016
20de824
Started #136
ilevkivskyi Sep 18, 2016
8e6f0a6
More work on #136
ilevkivskyi Sep 18, 2016
bcde4c6
Finish first round of #136
ilevkivskyi Sep 18, 2016
9987bb2
Shorter error messages
ilevkivskyi Sep 18, 2016
90d72da
Added lru_cache for Generic[]
ilevkivskyi Sep 18, 2016
603ff6d
Flexible cache for Generic[]
ilevkivskyi Sep 18, 2016
fa4a681
Skip GenericMeta in FrozenSetMeta MRO
ilevkivskyi Sep 18, 2016
cc99972
Revert "Skip GenericMeta in FrozenSetMeta MRO"
ilevkivskyi Sep 18, 2016
b587dc0
Remove redundant metaclass for frozenset
ilevkivskyi Sep 18, 2016
e25b303
Some formatting
ilevkivskyi Sep 18, 2016
3ccb7a9
Fix async/await tests
ilevkivskyi Sep 18, 2016
0606059
Fixed ContextManger test
ilevkivskyi Sep 18, 2016
8b909d6
Be consistent about _TypeAlias
ilevkivskyi Sep 18, 2016
554f2ed
Removed debugging print()
ilevkivskyi Sep 18, 2016
11189b0
Simplified code
ilevkivskyi Sep 19, 2016
4c91c3b
Increased cache size to 50; start backporting changes to Python 2
ilevkivskyi Sep 22, 2016
1920009
Backport Union and Optional to Python 2
ilevkivskyi Sep 23, 2016
f003eca
Finished backport to Python 2; some polishing is needed
ilevkivskyi Sep 23, 2016
e130c77
Added many unit tests for bugs fixed by PR
ilevkivskyi Sep 24, 2016
fe2d3b7
Updated docstrings and other minor things
ilevkivskyi Sep 24, 2016
e4cebff
Optimized caching + first part of response to comments
ilevkivskyi Sep 25, 2016
9b443cb
Second part of response to comments. Need to port all comments etc. t…
ilevkivskyi Sep 26, 2016
bd160a1
Start backporting comments to Python2; improve caching
ilevkivskyi Sep 26, 2016
80ce513
Get rid of frozensetmeta, it causes random failures
ilevkivskyi Sep 26, 2016
c4f11e8
Backported everything to Python 2
Sep 26, 2016
230a500
Do not duplicate real errors while caching
ilevkivskyi Sep 26, 2016
e8c85b2
Merge remote-tracking branch 'origin/master'
ilevkivskyi Sep 26, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Flexible cache for Generic[]
  • Loading branch information
ilevkivskyi committed Sep 18, 2016
commit 603ff6d8e6285f9aeb4e49df1e7d0ccd46a35294
16 changes: 14 additions & 2 deletions src/typing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
from abc import abstractmethod, abstractproperty
from functools import lru_cache
from functools import lru_cache, wraps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather see import functools, like the following imports. (abstractmethod and -property are special because they are used a lot, and also well-known).

import collections
import contextlib
import functools
Expand Down Expand Up @@ -826,6 +826,18 @@ def _next_in_mro(cls):
return next_in_mro


def tp_cache(func):
cached = lru_cache(maxsize=25)(func)
wraps(func)
def inner(*args, **kwargs):
if any(not isinstance(arg, collections_abc.Hashable) for arg in args):
print("Not Hashable")
return func(*args, **kwargs)
else:
return cached(*args, **kwargs)
return inner


class GenericMeta(TypingMeta, abc.ABCMeta):
"""Metaclass for generic types."""

Expand Down Expand Up @@ -911,7 +923,7 @@ def __eq__(self, other):
def __hash__(self):
return hash((self.__name__, self.__parameters__))

@lru_cache(maxsize=25)
@tp_cache
def __getitem__(self, params):
if not isinstance(params, tuple):
params = (params,)
Expand Down
290A
0