{"action":"created","comment":{"url":"https://api.github.com/repos/python/typeshed/pulls/comments/78857004","id":78857004,"diff_hunk":"@@ -0,0 +1,89 @@\n+# Stubs for fractions\n+# See https://docs.python.org/3/library/fractions.html\n+\n+from typing import Optional, TypeVar, Union, overload\n+from numbers import Complex, Rational\n+from decimal import Decimal\n+import sys\n+\n+_TComplex = TypeVar('_TComplex', bound=Complex)\n+_TOtherNum = TypeVar('_TOtherNum', int, float, Decimal)\n+_TNum = TypeVar('_TNum', int, float, Decimal, Complex)\n+\n+@overload\n+def gcd(a: _TComplex, b: _TComplex) -> _TComplex: ...","path":"stdlib/2and3/fractions.pyi","position":14,"original_position":14,"commit_id":"b8e56bfa1d6b36e8a6f899c018689b282d158ec4","original_commit_id":"b8e56bfa1d6b36e8a6f899c018689b282d158ec4","user":{"login":"Michael0x2a","id":1424628,"avatar_url":"https://avatars.githubusercontent.com/u/1424628?v=3","gravatar_id":"","url":"https://api.github.com/users/Michael0x2a","html_url":"https://github.com/Michael0x2a","followers_url":"https://api.github.com/users/Michael0x2a/followers","following_url":"https://api.github.com/users/Michael0x2a/following{/other_user}","gists_url":"https://api.github.com/users/Michael0x2a/gists{/gist_id}","starred_url":"https://api.github.com/users/Michael0x2a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Michael0x2a/subscriptions","organizations_url":"https://api.github.com/users/Michael0x2a/orgs","repos_url":"https://api.github.com/users/Michael0x2a/repos","events_url":"https://api.github.com/users/Michael0x2a/events{/privacy}","received_events_url":"https://api.github.com/users/Michael0x2a/received_events","type":"User","site_admin":false},"body":"Hmm, so it looks like the return type of gcd here ultimately depends on what the type of `a % b` is, which makes the gcd function more complicated then I was originally expecting.\r\n\r\nSome things I observed:\r\n\r\n- `numbers.Complex` does not have any kind of dunder methods related to mods, so shouldn't be a legal input type in either Python 2 or Python 3.\r\n- However, the builtins `complex` type _does_ allow you to take the mod in Python 2, but NOT in Python 3.\r\n- If one argument is a complex number, and the other is any other type, the gcd function will either throw a TypeError or will enter an infinite loop (!!).\r\n\r\nI also found the full matrix of allowable parameters to return types is this (not taking into account whatever any custom number subclasses might do):\r\n\r\n```\r\n            | int          float        Fraction     Decimal      complex\r\n------------+ -----------  -----------  -----------  -----------  -----------\r\nint         | int          float        Fraction     Decimal      Inf. Loop\r\nfloat       | float        float        float        TypeError    Inf. Loop\r\nFraction    | Fraction     float        Fraction     TypeError    TypeError\r\nDecimal     | Decimal      TypeError    TypeError    Decimal      TypeError\r\ncomplex     | Inf. Loop    Inf. Loop    TypeError    TypeError    complex\r\n```\r\n\r\nThankfully, the diagonal (where both parameters are the same type) appear to be relatively sane.\r\n\r\nSo, given all of the above, and given that `fractions.gcd` is a deprecated function anyways as of Python 3 (people are supposed to use math.gcd instead, which accepts only ints), would you rather I:\r\n\r\n- Attempt to come up with a system of overloads to handle the full matrix.\r\n- Attempt to handle the case where both parameters are the same type, and just provide separate annotations for Python 2 and 3 to handle complex numbers.\r\n- Just disallow allowing complex numbers as parameters completely on the grounds that nobody is actually going to do that/they're going to be using cmath instead.\r\n- Don't bother providing a type signature, and just make the input and output types Any.\r\n- Something else?\r\n","created_at":"2016-09-14T22:37:30Z","updated_at":"2016-09-14T22:37:30Z","html_url":"https://github.com/python/typeshed/pull/544#discussion_r78857004","pull_request_url":"https://api.github.com/repos/python/typeshed/pulls/544","_links":{"self":{"href":"https://api.github.com/repos/python/typeshed/pulls/comments/78857004"},"html":{"href":"https://github.com/python/typeshed/pull/544#discussion_r78857004"},"pull_request":{"href":"https://api.github.com/repos/python/typeshed/pulls/544"}}},"pull_request":{"url":"https://api.github.com/repos/python/typeshed/pulls/544","id":85166426,"html_url":"https://github.com/python/typeshed/pull/544","diff_url":"https://github.com/python/typeshed/pull/544.diff","patch_url":"https://github.com/python/typeshed/pull/544.patch","issue_url":"https://api.github.com/repos/python/typeshed/issues/544","number":544,"state":"open","locked":false,"title":"Add partial stubs for fractions","user":{"login":"Michael0x2a","id":1424628,"avatar_url":"https://avatars.githubusercontent.com/u/1424628?v=3","gravatar_id":"","url":"https://api.github.com/users/Michael0x2a","html_url":"https://github.com/Michael0x2a","followers_url":"https://api.github.com/users/Michael0x2a/followers","following_url":"https://api.github.com/users/Michael0x2a/following{/other_user}","gists_url":"https://api.github.com/users/Michael0x2a/gists{/gist_id}","starred_url":"https://api.github.com/users/Michael0x2a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Michael0x2a/subscriptions","organizations_url":"https://api.github.com/users/Michael0x2a/orgs","repos_url":"https://api.github.com/users/Michael0x2a/repos","events_url":"https://api.github.com/users/Michael0x2a/events{/privacy}","received_events_url":"https://api.github.com/users/Michael0x2a/received_events","type":"User","site_admin":false},"body":"This commit adds some incomplete stubs for the fractions module.\r\n\r\nIn particular, this pull request is basically a less complete version of https://github.com/python/typeshed/pull/94 -- this pull request punts on adding type signatures to functions like `__add__` and just sticks with annotating the more obvious functions and methods. This isn't ideal, but does allow us to move forward with creating stubs for the statistics module.\r\n\r\nThis pull request requires https://github.com/python/typeshed/pull/545 to first be merged and accepted. (For some reason, the stubs for `decimal` in Python 3 are relatively complete, but the stubs for Python 2 are not, which is causing the current test failure).\r\n\r\nHowever, this pull request can be reviewed and accepted independently from my other recent pull request that [refines numbers.pyi](https://github.com/python/typeshed/pull/543). Once that other pull request is accepted, I'm planning on following up with another pull request that adds the `__hash__` function to the `Fractions` class.","created_at":"2016-09-14T04:48:14Z","updated_at":"2016-09-14T22:37:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c42bfdbda36547ac522c006111973719fce609e5","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/python/typeshed/pulls/544/commits","review_comments_url":"https://api.github.com/repos/python/typeshed/pulls/544/comments","review_comment_url":"https://api.github.com/repos/python/typeshed/pulls/comments{/number}","comments_url":"https://api.github.com/repos/python/typeshed/issues/544/comments","statuses_url":"https://api.github.com/repos/python/typeshed/statuses/b8e56bfa1d6b36e8a6f899c018689b282d158ec4","head":{"label":"Michael0x2a:add-partial-fractions","ref":"add-partial-fractions","sha":"b8e56bfa1d6b36e8a6f899c018689b282d158ec4","user":{"login":"Michael0x2a","id":1424628,"avatar_url":"https://avatars.githubusercontent.com/u/1424628?v=3","gravatar_id":"","url":"https://api.github.com/users/Michael0x2a","html_url":"https://github.com/Michael0x2a","followers_url":"https://api.github.com/users/Michael0x2a/followers","following_url":"https://api.github.com/users/Michael0x2a/following{/other_user}","gists_url":"https://api.github.com/users/Michael0x2a/gists{/gist_id}","starred_url":"https://api.github.com/users/Michael0x2a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Michael0x2a/subscriptions","organizations_url":"https://api.github.com/users/Michael0x2a/orgs","repos_url":"https://api.github.com/users/Michael0x2a/repos","events_url":"https://api.github.com/users/Michael0x2a/events{/privacy}","received_events_url":"https://api.github.com/users/Michael0x2a/received_events","type":"User","site_admin":false},"repo":{"id":57080209,"name":"typeshed","full_name":"Michael0x2a/typeshed","owner":{"login":"Michael0x2a","id":1424628,"avatar_url":"https://avatars.githubusercontent.com/u/1424628?v=3","gravatar_id":"","url":"https://api.github.com/users/Michael0x2a","html_url":"https://github.com/Michael0x2a","followers_url":"https://api.github.com/users/Michael0x2a/followers","following_url":"https://api.github.com/users/Michael0x2a/following{/other_user}","gists_url":"https://api.github.com/users/Michael0x2a/gists{/gist_id}","starred_url":"https://api.github.com/users/Michael0x2a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Michael0x2a/subscriptions","organizations_url":"https://api.github.com/users/Michael0x2a/orgs","repos_url":"https://api.github.com/users/Michael0x2a/repos","events_url":"https://api.github.com/users/Michael0x2a/events{/privacy}","received_events_url":"https://api.github.com/users/Michael0x2a/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Michael0x2a/typeshed","description":"Collection of library stubs for Python, with static types","fork":true,"url":"https://api.github.com/repos/Michael0x2a/typeshed","forks_url":"https://api.github.com/repos/Michael0x2a/typeshed/forks","keys_url":"https://api.github.com/repos/Michael0x2a/typeshed/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Michael0x2a/typeshed/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Michael0x2a/typeshed/teams","hooks_url":"https://api.github.com/repos/Michael0x2a/typeshed/hooks","issue_events_url":"https://api.github.com/repos/Michael0x2a/typeshed/issues/events{/number}","events_url":"https://api.github.com/repos/Michael0x2a/typeshed/events","assignees_url":"https://api.github.com/repos/Michael0x2a/typeshed/assignees{/user}","branches_url":"https://api.github.com/repos/Michael0x2a/typeshed/branches{/branch}","tags_url":"https://api.github.com/repos/Michael0x2a/typeshed/tags","blobs_url":"https://api.github.com/repos/Michael0x2a/typeshed/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Michael0x2a/typeshed/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Michael0x2a/typeshed/git/refs{/sha}","trees_url":"https://api.github.com/repos/Michael0x2a/typeshed/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Michael0x2a/typeshed/statuses/{sha}","languages_url":"https://api.github.com/repos/Michael0x2a/typeshed/languages","stargazers_url":"https://api.github.com/repos/Michael0x2a/typeshed/stargazers","contributors_url":"https://api.github.com/repos/Michael0x2a/typeshed/contributors","subscribers_url":"https://api.github.com/repos/Michael0x2a/typeshed/subscribers","subscription_url":"https://api.github.com/repos/Michael0x2a/typeshed/subscription","commits_url":"https://api.github.com/repos/Michael0x2a/typeshed/commits{/sha}","git_commits_url":"https://api.github.com/repos/Michael0x2a/typeshed/git/commits{/sha}","comments_url":"https://api.github.com/repos/Michael0x2a/typeshed/comments{/number}","issue_comment_url":"https://api.github.com/repos/Michael0x2a/typeshed/issues/comments{/number}","contents_url":"https://api.github.com/repos/Michael0x2a/typeshed/contents/{+path}","compare_url":"https://api.github.com/repos/Michael0x2a/typeshed/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Michael0x2a/typeshed/merges","archive_url":"https://api.github.com/repos/Michael0x2a/typeshed/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Michael0x2a/typeshed/downloads","issues_url":"https://api.github.com/repos/Michael0x2a/typeshed/issues{/number}","pulls_url":"https://api.github.com/repos/Michael0x2a/typeshed/pulls{/number}","milestones_url":"https://api.github.com/repos/Michael0x2a/typeshed/milestones{/number}","notifications_url":"https://api.github.com/repos/Michael0x2a/typeshed/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Michael0x2a/typeshed/labels{/name}","releases_url":"https://api.github.com/repos/Michael0x2a/typeshed/releases{/id}","deployments_url":"https://api.github.com/repos/Michael0x2a/typeshed/deployments","created_at":"2016-04-25T22:21:53Z","updated_at":"2016-04-25T22:21:56Z","pushed_at":"2016-09-14T16:47:15Z","git_url":"git://github.com/Michael0x2a/typeshed.git","ssh_url":"git@github.com:Michael0x2a/typeshed.git","clone_url":"https://github.com/Michael0x2a/typeshed.git","svn_url":"https://github.com/Michael0x2a/typeshed","homepage":null,"size":1297,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"python:master","ref":"master","sha":"748428d8a4b957afebd22f4a11f8608a5e0ddab5","user":{"login":"python","id":1525981,"avatar_url":"https://avatars.githubusercontent.com/u/1525981?v=3","gravatar_id":"","url":"https://api.github.com/users/python","html_url":"https://github.com/python","followers_url":"https://api.github.com/users/python/followers","following_url":"https://api.github.com/users/python/following{/other_user}","gists_url":"https://api.github.com/users/python/gists{/gist_id}","starred_url":"https://api.github.com/users/python/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/python/subscriptions","organizations_url":"https://api.github.com/users/python/orgs","repos_url":"https://api.github.com/users/python/repos","events_url":"https://api.github.com/users/python/events{/privacy}","received_events_url":"https://api.github.com/users/python/received_events","type":"Organization","site_admin":false},"repo":{"id":31696383,"name":"typeshed","full_name":"python/typeshed","owner":{"login":"python","id":1525981,"avatar_url":"https://avatars.githubusercontent.com/u/1525981?v=3","gravatar_id":"","url":"https://api.github.com/users/python","html_url":"https://github.com/python","followers_url":"https://api.github.com/users/python/followers","following_url":"https://api.github.com/users/python/following{/other_user}","gists_url":"https://api.github.com/users/python/gists{/gist_id}","starred_url":"https://api.github.com/users/python/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/python/subscriptions","organizations_url":"https://api.github.com/users/python/orgs","repos_url":"https://api.github.com/users/python/repos","events_url":"https://api.github.com/users/python/events{/privacy}","received_events_url":"https://api.github.com/users/python/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/python/typeshed","description":"Collection of library stubs for Python, with static types","fork":false,"url":"https://api.github.com/repos/python/typeshed","forks_url":"https://api.github.com/repos/python/typeshed/forks","keys_url":"https://api.github.com/repos/python/typeshed/keys{/key_id}","collaborators_url":"https://api.github.com/repos/python/typeshed/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/python/typeshed/teams","hooks_url":"https://api.github.com/repos/python/typeshed/hooks","issue_events_url":"https://api.github.com/repos/python/typeshed/issues/events{/number}","events_url":"https://api.github.com/repos/python/typeshed/events","assignees_url":"https://api.github.com/repos/python/typeshed/assignees{/user}","branches_url":"https://api.github.com/repos/python/typeshed/branches{/branch}","tags_url":"https://api.github.com/repos/python/typeshed/tags","blobs_url":"https://api.github.com/repos/python/typeshed/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/python/typeshed/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/python/typeshed/git/refs{/sha}","trees_url":"https://api.github.com/repos/python/typeshed/git/trees{/sha}","statuses_url":"https://api.github.com/repos/python/typeshed/statuses/{sha}","languages_url":"https://api.github.com/repos/python/typeshed/languages","stargazers_url":"https://api.github.com/repos/python/typeshed/stargazers","contributors_url":"https://api.github.com/repos/python/typeshed/contributors","subscribers_url":"https://api.github.com/repos/python/typeshed/subscribers","subscription_url":"https://api.github.com/repos/python/typeshed/subscription","commits_url":"https://api.github.com/repos/python/typeshed/commits{/sha}","git_commits_url":"https://api.github.com/repos/python/typeshed/git/commits{/sha}","comments_url":"https://api.github.com/repos/python/typeshed/comments{/number}","issue_comment_url":"https://api.github.com/repos/python/typeshed/issues/comments{/number}","contents_url":"https://api.github.com/repos/python/typeshed/contents/{+path}","compare_url":"https://api.github.com/repos/python/typeshed/compare/{base}...{head}","merges_url":"https://api.github.com/repos/python/typeshed/merges","archive_url":"https://api.github.com/repos/python/typeshed/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/python/typeshed/downloads","issues_url":"https://api.github.com/repos/python/typeshed/issues{/number}","pulls_url":"https://api.github.com/repos/python/typeshed/pulls{/number}","milestones_url":"https://api.github.com/repos/python/typeshed/milestones{/number}","notifications_url":"https://api.github.com/repos/python/typeshed/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/python/typeshed/labels{/name}","releases_url":"https://api.github.com/repos/python/typeshed/releases{/id}","deployments_url":"https://api.github.com/repos/python/typeshed/deployments","created_at":"2015-03-05T04:51:28Z","updated_at":"2016-09-13T19:01:03Z","pushed_at":"2016-09-14T21:55:06Z","git_url":"git://github.com/python/typeshed.git","ssh_url":"git@github.com:python/typeshed.git","clone_url":"https://github.com/python/typeshed.git","svn_url":"https://github.com/python/typeshed","homepage":null,"size":1740,"stargazers_count":231,"watchers_count":231,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":124,"mirror_url":null,"open_issues_count":74,"forks":124,"open_issues":74,"watchers":231,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/python/typeshed/pulls/544"},"html":{"href":"https://github.com/python/typeshed/pull/544"},"issue":{"href":"https://api.github.com/repos/python/typeshed/issues/544"},"comments":{"href":"https://api.github.com/repos/python/typeshed/issues/544/comments"},"review_comments":{"href":"https://api.github.com/repos/python/typeshed/pulls/544/comments"},"review_comment":{"href":"https://api.github.com/repos/python/typeshed/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/python/typeshed/pulls/544/commits"},"statuses":{"href":"https://api.github.com/repos/python/typeshed/statuses/b8e56bfa1d6b36e8a6f899c018689b282d158ec4"}}}}
{"actor":{"display_login":"Michael0x2a"}}