{"action":"closed","issue":{"url":"https://api.github.com/repos/amontalenti/elements-of-python-style/issues/12","labels_url":"https://api.github.com/repos/amontalenti/elements-of-python-style/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/amontalenti/elements-of-python-style/issues/12/comments","events_url":"https://api.github.com/repos/amontalenti/elements-of-python-style/issues/12/events","html_url":"https://github.com/amontalenti/elements-of-python-style/issues/12","id":124801684,"number":12,"title":"Avoid numeric literals in code body (suggestion)","user":{"login":"glenfant","id":703389,"avatar_url":"https://avatars.githubusercontent.com/u/703389?v=3","gravatar_id":"","url":"https://api.github.com/users/glenfant","html_url":"https://github.com/glenfant","followers_url":"https://api.github.com/users/glenfant/followers","following_url":"https://api.github.com/users/glenfant/following{/other_user}","gists_url":"https://api.github.com/users/glenfant/gists{/gist_id}","starred_url":"https://api.github.com/users/glenfant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenfant/subscriptions","organizations_url":"https://api.github.com/users/glenfant/orgs","repos_url":"https://api.github.com/users/glenfant/repos","events_url":"https://api.github.com/users/glenfant/events{/privacy}","received_events_url":"https://api.github.com/users/glenfant/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-04T17:26:27Z","updated_at":"2016-01-08T12:14:53Z","closed_at":"2016-01-08T12:14:53Z","body":"Numeric literals, other than -1, 0 and 1 should never appear in the code body. Use constants, preferably from a `config.py` like module if you're in a big package, or values used in various modules.\r\n\r\nThis is not Python specific but I have lost so much time fixing bugs this ugly stuff yields...\r\n\r\n```python\r\n# Bad\r\ndef is_adult(person):\r\n    return person.age() >= 18\r\n\r\ndef years_of_adult(person):\r\n    if is_adult(person):\r\n        return person.age() - 18\r\n    return 0\r\n\r\n# Good\r\nfrom config import ADULT_LOW_AGE\r\n\r\ndef is_adult(person):\r\n    return person.age() >= ADULT_LOW_AGE\r\n\r\ndef years_of_adult_state(person):\r\n    if is_adult(person):\r\n        return person.age() - ADULT_LOW_AGE\r\n    return 0\r\n```\r\n"}}