Skip to content

Commit

Permalink
Type should not inherit from type. (#267)
Browse files Browse the repository at this point in the history
Fixes #266.
  • Loading branch information
gvanrossum authored Aug 24, 2016
1 parent 4a6885a commit a1952c4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions python2/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,19 @@ def new_user(user_class):

joe = new_user(BasicUser)

def test_type_optional(self):
A = Optional[Type[BaseException]]

def foo(a):
# type: (A) -> Optional[BaseException]
if a is None:
return None
else:
return a()

assert isinstance(foo(KeyboardInterrupt), KeyboardInterrupt)
assert foo(None) is None


class NewTypeTests(BaseTestCase):

Expand Down
2 changes: 1 addition & 1 deletion python2/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ def __new__(cls, *args, **kwds):


# This is not a real generic class. Don't use outside annotations.
class Type(type, Generic[CT_co]):
class Type(Generic[CT_co]):
"""A special construct usable to annotate class objects.
For example, suppose we have the following classes::
Expand Down
12 changes: 12 additions & 0 deletions src/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,18 @@ def new_user(user_class: Type[U]) -> U:

joe = new_user(BasicUser)

def test_type_optional(self):
A = Optional[Type[BaseException]]

def foo(a: A) -> Optional[BaseException]:
if a is None:
return None
else:
return a()

assert isinstance(foo(KeyboardInterrupt), KeyboardInterrupt)
assert foo(None) is None


class NewTypeTests(BaseTestCase):

Expand Down
2 changes: 1 addition & 1 deletion src/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ def __new__(cls, *args, **kwds):


# This is not a real generic class. Don't use outside annotations.
class Type(type, Generic[CT_co], extra=type):
class Type(Generic[CT_co], extra=type):
"""A special construct usable to annotate class objects.
For example, suppose we have the following classes::
Expand Down

0 comments on commit a1952c4

Please sign in to comment.