Python/Django: synonym for field "type" in database model (reserved built-in symbol) Python/Django: synonym for field "type" in database model (reserved built-in symbol) python python

Python/Django: synonym for field "type" in database model (reserved built-in symbol)


  1. It's always a bad idea to have a variable name that shadows one ofpython's built-ins. It will confuse people reading your code, who expect type to mean something specific. Less important than readability to other users it can also throw off syntax highlighting.
  2. Rename the variable. (really it's the best thing to do - you could leave it, but rename now while it's easy)
  3. There are lots of potential options, perhaps classification or category. I know you said you don't like category, but I can't see what's not generic about it?

It might be that it would be overkill for your specific application (would need to know more), but django does support model inheritance.


I disagree with the other answers. There's no need to change this.

In my opinion, there is little risk of confusion, as you will never access the attribute except via an instance. my_vehicle.type is not easy to confuse with (eg) type(my_vehicle).


Well, warning or error, i'd avoid always to risk a situation like yours :) The better thing in my opinion you can do is change the variable name without losing any meaning nor cohesion. You could call it "v_type" meaning vehicle type in a shortened way, if it's used only for that particular class. If you'll extend that class, you'll extend it with another vehicle type, so in your case "v_type" would fit.