8000 Type[C] by gvanrossum · Pull Request #1569 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Type[C] #1569

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 23 commits into from
Jun 8, 2016
Merged

Type[C] #1569

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b7ddf36
Tentative tests for Type[C].
May 18, 2016
eb61f1d
Pave the way for implementing Type[C].
May 20, 2016
7b52ac6
WIP: Introducing TypeType: Type[x] becomes TypeType(x).
May 20, 2016
1fd14f0
WIP: Fix/new tests; implement more subtype checks.
May 23, 2016
371e425
WIP: Towards supporting Type[T].
May 23, 2016
96696ff
Fix things so all tests pass!
May 24, 2016
aa37595
Some cleanup and fixup (not done).
May 24, 2016
d4745b0
Improve equivalence between type and Type.
May 25, 2016
cf4a0b7
Add support for method lookup from Type[].
May 25, 2016
81ee239
Print a proper error for unsupported Type[] args.
May 26, 2016
3d92049
Reject Type[U] where U's bound is a generic class.
May 26, 2016
5ab11d2
Support classes with @overload-ed __init__.
May 26, 2016
afb0482
Update our copies of typing.py to the latest from the python/typing r…
May 26, 2016
db30d59
Make Type[A] erase to Type[A], but Type[T] erases to Type[Any].
Jun 6, 2016
6029c9d
Special-case joining Type[] with builtins.type.
Jun 7, 2016
786ef96
Special-case joining Type[] with builtins.type.
Jun 7, 2016
ef247f2
Delete outdated XXX comment.
Jun 7, 2016
4162103
Finishing touch -- fix and test TypeAnalyser.visit_type_type().
Jun 7, 2016
26ff267
Added tests as requested.
Jun 7, 2016
256b31a
Remove comment asking for name for analyze_type_type_callee().
Jun 7, 2016
d224aff
Use self.default(self.s) instead of AnyType()/NonType() in join/meet.
Jun 7, 2016
d9c74a0
Add tests for overloaded __init__.
Jun 7, 2016
eaa9e0d
Add more tests. Fixed a bug in join() this found.
Jun 7, 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
Make Type[A] erase to Type[A], but Type[T] erases to Type[Any].
  • Loading branch information
Guido van Rossum committed Jun 7, 2016
commit db30d59f39c251782753c01221ddc58c5c3893a7
4 changes: 2 additions & 2 deletions mypy/erasetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def erase_type(typ: Type) -> Type:
B[X] -> B[Any]
Tuple[A, B] -> tuple
Callable[...] -> Callable[[], None]
Type[X] -> Type[Any]
"""

return typ.accept(EraseTypeVisitor())
Expand Down Expand Up @@ -73,8 +74,7 @@ def visit_union_type(self, t: UnionType) -> Type:
return AnyType() # XXX: return underlying type if only one?

def visit_type_type(self, t: TypeType) -> Type:
# XXX No idea if this makes much sense.
return TypeType(AnyType(), line=t.line)
return TypeType(t.item.accept(self), line=t.line)


def erase_generic_types(t: Type) -> Type:
Expand Down
6 changes: 5 additions & 1 deletion mypy/test/testtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from mypy.meet import meet_types
from mypy.types import (
UnboundType, AnyType, Void, CallableType, TupleType, TypeVarDef, Type,
Instance, NoneTyp, ErrorType, Overloaded
Instance, NoneTyp, ErrorType, Overloaded, TypeType,
)
from mypy.nodes import ARG_POS, ARG_OPT, ARG_STAR, CONTRAVARIANT, INVARIANT, COVARIANT
from mypy.replacetvars import replace_type_vars
Expand Down Expand Up @@ -177,6 +177,10 @@ def test_erase_with_type_object(self):
self.assert_erase(self.fx.callable_type(self.fx.a, self.fx.b),
self.fx.callable_type(self.fx.void))

def test_erase_with_type_type(self):
self.assert_erase(self.fx.type_a, self.fx.type_a)
self.assert_erase(self.fx.type_t, TypeType(AnyType()))

def assert_erase(self, orig, result):
assert_equal(str(erase_type(orig)), str(result))

Expand Down
6 changes: 5 additions & 1 deletion mypy/typefixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from typing import List

from mypy.types import (
TypeVarType, AnyType, Void, ErrorType, NoneTyp, Instance, CallableType, TypeVarDef
TypeVarType, AnyType, Void, ErrorType, NoneTyp, Instance, CallableType, TypeVarDef,
TypeType,
)
from mypy.nodes import (
TypeInfo, ClassDef, Block, ARG_POS, ARG_OPT, ARG_STAR, SymbolTable,
Expand Down Expand Up @@ -140,6 +141,9 @@ def __init__(self, variance: int=COVARIANT) -> None:
self.lsta = Instance(self.std_listi, [self.a]) # List[A]
self.lstb = Instance(self.std_listi, [self.b]) # List[B]

self.type_a = TypeType(self.a)
self.type_t = TypeType(self.t)

# Helper methods

def callable(self, *a):
Expand Down
0