{"action":"created","issue":{"url":"https://api.github.com/repos/fishman/ctags/issues/216","labels_url":"https://api.github.com/repos/fishman/ctags/issues/216/labels{/name}","comments_url":"https://api.github.com/repos/fishman/ctags/issues/216/comments","events_url":"https://api.github.com/repos/fishman/ctags/issues/216/events","html_url":"https://github.com/fishman/ctags/issues/216","id":55687243,"number":216,"title":"incorrect detection of private functions/methods in python","user":{"login":"gotyaoi","id":2141918,"avatar_url":"https://avatars.githubusercontent.com/u/2141918?v=3","gravatar_id":"","url":"https://api.github.com/users/gotyaoi","html_url":"https://github.com/gotyaoi","followers_url":"https://api.github.com/users/gotyaoi/followers","following_url":"https://api.github.com/users/gotyaoi/following{/other_user}","gists_url":"https://api.github.com/users/gotyaoi/gists{/gist_id}","starred_url":"https://api.github.com/users/gotyaoi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gotyaoi/subscriptions","organizations_url":"https://api.github.com/users/gotyaoi/orgs","repos_url":"https://api.github.com/users/gotyaoi/repos","events_url":"https://api.github.com/users/gotyaoi/events{/privacy}","received_events_url":"https://api.github.com/users/gotyaoi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"b4n","id":793526,"avatar_url":"https://avatars.githubusercontent.com/u/793526?v=3","gravatar_id":"","url":"https://api.github.com/users/b4n","html_url":"https://github.com/b4n","followers_url":"https://api.github.com/users/b4n/followers","following_url":"https://api.github.com/users/b4n/following{/other_user}","gists_url":"https://api.github.com/users/b4n/gists{/gist_id}","starred_url":"https://api.github.com/users/b4n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/b4n/subscriptions","organizations_url":"https://api.github.com/users/b4n/orgs","repos_url":"https://api.github.com/users/b4n/repos","events_url":"https://api.github.com/users/b4n/events{/privacy}","received_events_url":"https://api.github.com/users/b4n/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2015-01-27T22:54:45Z","updated_at":"2015-01-29T01:01:31Z","closed_at":null,"body":"The current chunk of code that controls whether a function is public or private is\r\n\r\n    /* If a function starts with __, we mark it as file scope.\r\n    * FIXME: What is the proper way to signal such attributes?\r\n    * TODO: What does functions/classes starting with _ and __ mean in python?\r\n    */\r\n    if (strncmp (vStringValue (function), \"__\", 2) == 0 &&\r\n        strcmp (vStringValue (function), \"__init__\") != 0)\r\n    {\r\n        tag.extensionFields.access = \"private\";\r\n        tag.isFileScope = TRUE;\r\n    }\r\n    else\r\n    {\r\n        tag.extensionFields.access = \"public\";\r\n    }\r\n\r\nThis is missing a few cases.\r\n\r\n* Any name that begins with a single underscore should be considered private. The interpreter does not enforce this, but it's a useful convention.\r\n* Any name inside a class that begins with two underscores but does not end with two underscores undergoes name mangling to _classname__name, to avoid conflicts with child classes using the same name. Double underscore should also be considered private.\r\n* Finally, names that begin two underscores and end with two underscores are \"magic\". They're used by the interpreter to implement various functionality. They should not be considered private.\r\n\r\nThe current implementation appears to mark any function/method that begins with two underscores but is not `__init__` as private. This leaves out names beginning with one underscore, and includes names that start with two underscores but also end with two underscores.\r\n\r\n`makeClassTag` and `makeVariableTag` do not include any logic to set the access extension field at all right now, as far as I can see."},"comment":{"url":"https://api.github.com/repos/fishman/ctags/issues/comments/71949716","html_url":"https://github.com/fishman/ctags/issues/216#issuecomment-71949716","issue_url":"https://api.github.com/repos/fishman/ctags/issues/216","id":71949716,"user":{"login":"gotyaoi","id":2141918,"avatar_url":"https://avatars.githubusercontent.com/u/2141918?v=3","gravatar_id":"","url":"https://api.github.com/users/gotyaoi","html_url":"https://github.com/gotyaoi","followers_url":"https://api.github.com/users/gotyaoi/followers","following_url":"https://api.github.com/users/gotyaoi/following{/other_user}","gists_url":"https://api.github.com/users/gotyaoi/gists{/gist_id}","starred_url":"https://api.github.com/users/gotyaoi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gotyaoi/subscriptions","organizations_url":"https://api.github.com/users/gotyaoi/orgs","repos_url":"https://api.github.com/users/gotyaoi/repos","events_url":"https://api.github.com/users/gotyaoi/events{/privacy}","received_events_url":"https://api.github.com/users/gotyaoi/received_events","type":"User","site_admin":false},"created_at":"2015-01-29T01:01:31Z","updated_at":"2015-01-29T01:01:31Z","body":"Yeah, the double underscore has no special meaning outside of classes, so it would just be considered the same as a name starting with a single underscore.\r\n\r\nI'm not sure protected is appropriate for python though. It's sort of a special case for inheritance that python disregards. I mean, you could say that a single underscore inside a class is protected and a double underscore inside a class is private, maybe? Certainly, at the module level things should just be private I think.\r\n\r\nI don't think variables inside functions are even tagged at all right now, which seems fine as they're not accessible from outside the function regardless, so probably no need to worry about that. On the other hand, nested functions are tagged, even though they're not accessible from the outside either..."}}