Imgur / imgurpython

Official Imgur python client library (deprecated)
MIT License
546 stars 116 forks source link

Replace id variables with non-keyword variable #24

Closed ueg1990 closed 9 years ago

ueg1990 commented 10 years ago

It may be better to replace all variables named id because id is a keyword/function in python. For example in account.py, if you look at the code below:

class Account:

def __init__(self, id, url, bio, reputation, created, pro_expiration):
    self.id = id
    self.url = url
    self.bio = bio
    self.reputation = reputation
    self.created = created
    self.pro_expiration = pro_expiration

In self.id = id, id (not self.id) is the keyword that I am suggesting to replace. I have read somewhere that in some practices the variable name pk is used. Another alternative is _id. Hopefully only some files will need to be changed under imgur/models. Let me know what you think.

jacobgreenleaf commented 10 years ago

Closest language I can find is in PEP 8:

If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss . (Perhaps better is to avoid such clashes by using a synonym.)

:+1:

ueg1990 commented 10 years ago

that sounds good to me. i think the reason people use pk in place of id was because its short for primary key. but i dont know why the underscore is appended in the end instead of the beginning of the variable? is it because _id would make it a private variable?