Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions python2/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import Pattern, Match
import abc
import typing
import weakref
try:
import collections.abc as collections_abc
except ImportError:
Expand Down Expand Up @@ -849,6 +850,14 @@ class Node(Generic[T]): pass
self.assertEqual(t, deepcopy(t))
self.assertEqual(t, copy(t))

def test_weakref_all(self):
T = TypeVar('T')
things = [Any, Union[T, int], Callable[..., T], Tuple[Any, Any],
Optional[List[int]], typing.Mapping[int, str],
typing.re.Match[bytes], typing.Iterable['whatever']]
for t in things:
self.assertEqual(weakref.ref(t)(), t)

def test_parameterized_slots(self):
T = TypeVar('T')
class C(Generic[T]):
Expand Down
2 changes: 1 addition & 1 deletion python2/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __repr__(self):
class _TypingBase(object):
"""Internal indicator of special typing constructs."""
__metaclass__ = TypingMeta
__slots__ = ()
__slots__ = ('__weakref__',)

def __init__(self, *args, **kwds):
pass
Expand Down
9 changes: 9 additions & 0 deletions src/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import Pattern, Match
import abc
import typing
import weakref
try:
import collections.abc as collections_abc
except ImportError:
Expand Down Expand Up @@ -896,6 +897,14 @@ class Node(Generic[T]): ...
self.assertEqual(t, copy(t))
self.assertEqual(t, deepcopy(t))

def test_weakref_all(self):
T = TypeVar('T')
things = [Any, Union[T, int], Callable[..., T], Tuple[Any, Any],
Optional[List[int]], typing.Mapping[int, str],
typing.re.Match[bytes], typing.Iterable['whatever']]
for t in things:
self.assertEqual(weakref.ref(t)(), t)

def test_parameterized_slots(self):
T = TypeVar('T')
class C(Generic[T]):
Expand Down
2 changes: 1 addition & 1 deletion src/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __repr__(self):
class _TypingBase(metaclass=TypingMeta, _root=True):
"""Internal indicator of special typing constructs."""

__slots__ = ()
__slots__ = ('__weakref__',)

def __init__(self, *args, **kwds):
pass
Expand Down