{"action":"created","issue":{"url":"https://api.github.com/repos/ambv/typehinting/issues/107","labels_url":"https://api.github.com/repos/ambv/typehinting/issues/107/labels{/name}","comments_url":"https://api.github.com/repos/ambv/typehinting/issues/107/comments","events_url":"https://api.github.com/repos/ambv/typehinting/issues/107/events","html_url":"https://github.com/ambv/typehinting/issues/107","id":74505744,"number":107,"title":"Can we have a generic Type[T]?","user":{"login":"NYKevin","id":1929766,"avatar_url":"https://avatars.githubusercontent.com/u/1929766?v=3","gravatar_id":"","url":"https://api.github.com/users/NYKevin","html_url":"https://github.com/NYKevin","followers_url":"https://api.github.com/users/NYKevin/followers","following_url":"https://api.github.com/users/NYKevin/following{/other_user}","gists_url":"https://api.github.com/users/NYKevin/gists{/gist_id}","starred_url":"https://api.github.com/users/NYKevin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NYKevin/subscriptions","organizations_url":"https://api.github.com/users/NYKevin/orgs","repos_url":"https://api.github.com/users/NYKevin/repos","events_url":"https://api.github.com/users/NYKevin/events{/privacy}","received_events_url":"https://api.github.com/users/NYKevin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ambv/typehinting/labels/postponed","name":"postponed","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-05-08T21:42:19Z","updated_at":"2015-05-22T15:49:38Z","closed_at":null,"body":"The `type` object occupies a rather strange place in the type hierarchy:\r\n\r\n    >>> type(type) is type\r\n    True\r\n\r\n(I'm pretty sure that's a flat lie, since you can't instantiate something from itself, but regardless...)\r\n\r\n    >>> isinstance(type, object)\r\n    True\r\n    >>> isinstance(object, type)\r\n    True\r\n    >>> isinstance(type, type)\r\n    True\r\n\r\nIn Java, the (very rough) equivalent is a class, specifically [`Class<T>`](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html).  It's also generic; the type variable refers to the instance.  Java has it easy because they don't support metaclasses.  Classes are not first class in Java, so their type hierarchy doesn't have to deal with the strange loops shown above.\r\n\r\nI realize metaclasses in their full generality are out of scope (at least for now), but a generic `Type[T]` like Java's would be nice to have.  So far as I can tell from the Mypy documentation, it doesn't currently exist.\r\n\r\nHere's some example code which might like to have this feature:\r\n\r\n    def make_foo(class_: Type[T]) -> T:\r\n        # Instantiate and return a T"},"comment":{"url":"https://api.github.com/repos/ambv/typehinting/issues/comments/104696057","html_url":"https://github.com/ambv/typehinting/issues/107#issuecomment-104696057","issue_url":"https://api.github.com/repos/ambv/typehinting/issues/107","id":104696057,"user":{"login":"NYKevin","id":1929766,"avatar_url":"https://avatars.githubusercontent.com/u/1929766?v=3","gravatar_id":"","url":"https://api.github.com/users/NYKevin","html_url":"https://github.com/NYKevin","followers_url":"https://api.github.com/users/NYKevin/followers","following_url":"https://api.github.com/users/NYKevin/following{/other_user}","gists_url":"https://api.github.com/users/NYKevin/gists{/gist_id}","starred_url":"https://api.github.com/users/NYKevin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NYKevin/subscriptions","organizations_url":"https://api.github.com/users/NYKevin/orgs","repos_url":"https://api.github.com/users/NYKevin/repos","events_url":"https://api.github.com/users/NYKevin/events{/privacy}","received_events_url":"https://api.github.com/users/NYKevin/received_events","type":"User","site_admin":false},"created_at":"2015-05-22T15:49:38Z","updated_at":"2015-05-22T15:49:38Z","body":"@agronholm The only reason Java calls the superclass implementation in that case is because it supports overloading.  Python doesn't, so I would expect LSP adherence in practice.  It may be difficult to enforce statically, however (cf. the Circle-Ellipse problem).  But that doesn't mean you can get away with violating it for non-static methods.  Things will break, whether the linter catches it or not.\r\n\r\n@ilevkivskyi That seems a rather odd syntax to me.  I'm not sure invariant `Type[T]` is necessarily all that useful anyway.  What's the point of a type variable if you know statically what its value will be?"}}