Change reference type name

Issue #11 resolved
Randle Taylor repo owner created an issue

ref_type and task_type should probably be renamed to type for consistency with other models.

Comments (4)

  1. Darcy Mason

    I agree with the consistency, but since `type` is a built-in in python, it would be better to avoid using that word. Sometimes people use `type_` or similar -- I don't like it much, but I can't think of a good alternative.

  2. Randle Taylor reporter

    Normally I'd avoid using `type` as well, but I think I'm okay with it in this particular situation.

    In a situation like this you are only likely to use `type` qualified by the self namespace or as an object attribute e.g.

    class MyModel(models.Model):
        type = models.CharField()
    
        def do_something(self):
            if self.type == "bar":
                print "baz"
    
    my_model = MyModel()
    my_model.type = "bar"
    my_model.do_something() 
    

    So you don't need to worry about clobbering the built in `type`

    The main situation I can think of where you'd have to be careful is something like

    class MyModel(models.Model):
        type = models.CharField()
        number = models.IntegerField()
    
        def __init__(self,type,name):
            self.type = type
    
            if type(number) == str:
                number = int(number)
            self.number = number
    
    my_model = MyModel("foo","100") #Throws a TypeError: 'str' object is not callable exception
    

    But I think that is rare enough that we can safely ignore it rather than have to use `type_` all over the place.

    Thoughts?

  3. Randle Taylor reporter

    I've changed the 'ref_type' & 'task_type' fields to just be 'type' in the models in the reorg branch and I'm going to mark this as resolved for now.

    Darcy, if you feel strongly enough that we shouldn't use 'type' here then please feel free to re-open this issue and we'll come up with a different solution.

  4. Log in to comment