{"action":"opened","issue":{"url":"https://api.github.com/repos/microsoft/pyright/issues/364","repository_url":"https://api.github.com/repos/microsoft/pyright","labels_url":"https://api.github.com/repos/microsoft/pyright/issues/364/labels{/name}","comments_url":"https://api.github.com/repos/microsoft/pyright/issues/364/comments","events_url":"https://api.github.com/repos/microsoft/pyright/issues/364/events","html_url":"https://github.com/microsoft/pyright/issues/364","id":528544172,"node_id":"MDU6SXNzdWU1Mjg1NDQxNzI=","number":364,"title":"confusing behavior with protocols","user":{"login":"cshesse","id":48501609,"node_id":"MDQ6VXNlcjQ4NTAxNjA5","avatar_url":"https://avatars3.githubusercontent.com/u/48501609?v=4","gravatar_id":"","url":"https://api.github.com/users/cshesse","html_url":"https://github.com/cshesse","followers_url":"https://api.github.com/users/cshesse/followers","following_url":"https://api.github.com/users/cshesse/following{/other_user}","gists_url":"https://api.github.com/users/cshesse/gists{/gist_id}","starred_url":"https://api.github.com/users/cshesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cshesse/subscriptions","organizations_url":"https://api.github.com/users/cshesse/orgs","repos_url":"https://api.github.com/users/cshesse/repos","events_url":"https://api.github.com/users/cshesse/events{/privacy}","received_events_url":"https://api.github.com/users/cshesse/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-11-26T07:37:51Z","updated_at":"2019-11-26T07:37:51Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"**Describe the bug**\r\n\r\nWhile debugging a type failure with `typeshed` and `shutil.copyfileobj`, I found a difference between `mypy` and `pyright` in terms of handling constrained TypeVars with protocols.  It's not clear to me what is going on, but I don't see why the code should fail.\r\n\r\n**To Reproduce**\r\n\r\n```\r\nfrom typing import TypeVar, Protocol\r\n\r\n\r\nT = TypeVar(\"T\")\r\nStrLike = TypeVar(\"StrLike\", str, bytes)\r\nT_contra = TypeVar(\"T_contra\", contravariant=True)\r\n\r\n\r\nclass Writer(Protocol[T_contra]):\r\n    def write(self, data: T_contra) -> None:\r\n        ...\r\n\r\n\r\nclass WriteFile:\r\n    def write(self, s: bytes) -> None:\r\n        pass\r\n\r\n\r\n# works fine in mypy and pyright\r\ndef f(writer: Writer[bytes]):\r\n    pass\r\n\r\n\r\n# works fine in mypy and pyright\r\ndef g(writer: Writer[T]):\r\n    pass\r\n\r\n\r\n# works fine in mypy, fails in pyright\r\ndef h(writer: Writer[StrLike]):\r\n    pass\r\n\r\n\r\nw = WriteFile()\r\nf(w)\r\ng(w)\r\nh(w)\r\n```\r\n\r\n```\r\nC:\\p\\misc\\pyright_test\\pyright_test13 \r\n(py38) λ mypy test\\test.py                                                                                                                                                                                \r\nSuccess: no issues found in 1 source file\r\n\r\nC:\\p\\misc\\pyright_test\\pyright_test13 \r\n(py38) λ pyright --project .\r\nLoading configuration file at C:\\p\\misc\\pyright_test\\pyright_test13\\pyrightconfig.json\r\ntypingsPath C:\\p\\misc\\pyright_test\\pyright_test13\\typings is not a valid directory.\r\nSearching for source files\r\nFound 1 source file\r\nC:\\p\\misc\\pyright_test\\pyright_test13\\test\\test.py\r\n  37:3 - error: Argument of type 'WriteFile' cannot be assigned to parameter 'writer' of type 'Writer[StrLike]'\r\n  'write' is an incompatible type\r\n    Parameter 2 of type 'TypeVar['StrLike', str, bytes]' cannot be assigned to type 'bytes'\r\n1 error, 0 warnings\r\nCompleted in 1.23sec\r\n```\r\n\r\n**Expected behavior**\r\n\r\nI expected this to be not an error.\r\n\r\n**VS Code extension or command-line**\r\n\r\n```\r\npyright --version\r\npyright 1.1.5\r\n```\r\n"}}
{"actor":{"display_login":"cshesse"}}