Conversation
mypy/applytype.py
Outdated
| # Translate constructor fn back to class. | ||
| if isinstance(type, CallableType) and type.is_type_obj(): | ||
| types[i] = type = type.ret_type | ||
|
|
There was a problem hiding this comment.
I don't think this is right, though somehow it never made a difference in my tests. The value C (the class) is not the same sort of thing as an instance of the class C.
|
Do you plan to add support for invoking a class method on a value of type |
|
Of course; I hope that already works. --Guido (mobile)
|
|
No it doesn't. Another reason not to release this yet. :-(
|
|
Mind having another look? I did add support for class methods, at
least for a few cases.
|
The TypeC tests no pass except for one ProUser* that should be ProUser; but something's seriously wrong because many other tests now fail.
- Add tests for Type[Any] and plain Type, and fix a bug that found. - Respond to easy review feedback (adding comments/docstrings mostly).
We only support two special cases (hopefully the most common ones): - Type[<concrete_class>] - Type[<type_variable_with_concrete_class_upper_bound>]
(This happens when type checking a call, not during semantic analysis.)
|
Another look? I've addressed all XXX comments, and added more tests. Would like to get this in 0.4.2. |
|
Ignore AppVeyor. I don't know why it keeps doing this even though I removed appveyor.yml. |
| class User: pass | ||
| class ProUser(User): pass | ||
| def new_user(user_class: Type[User]) -> User: | ||
| return user_class() |
There was a problem hiding this comment.
Test calling with invalid arguments to __init__. Also test a class with non-default __init__ and call constructor with both valid and invalid arguments.
|
Please ignore the AppVeyor build, as usual. |
|
Addressed all remaining comments. |
mypy/join.py
Outdated
| elif isinstance(self.s, Instance) and self.s.type.fullname() == 'builtins.type': | ||
| return self.s | ||
| else: | ||
| return AnyType() |
There was a problem hiding this comment.
Don't return AnyType here -- instead, use self.default(self.s), which usually returns object.
|
Looks pretty good now! Here are a few additional things to test:
These are optional but if you don't implement these consider creating issues:
|
|
Pushed solutions for the first 4 bullets. |
|
Looks like Type[C] is indeed a subtype of Callable[[], C]: class C: pass
T = Type[C]
def f(a: Callable[[], C]) -> None: pass
f(C)
f(T)has no errors. I can write a more elaborate test after lunch. UPDATE: But I'm not sure what the last two bullets imply then. |
TBD