Использование @property и @ attribute.setter помогает не только использовать «pythonic» способ, но также проверять правильность атрибутов при создании объекта и при его изменении.
class Person(object):
def __init__(self, p_name=None):
self.name = p_name
@property
def name(self):
return self._name
@name.setter
def name(self, new_name):
if type(new_name) == str: #type checking for name property
self._name = new_name
else:
raise Exception("Invalid value for name")
Таким образом, вы фактически скрываете атрибут _name от разработчиков-клиентов, а также выполняете проверки типа свойства имени. Обратите внимание, что, следуя этому подходу даже во время инициализации, вызывающий сеттер. Итак:
p = Person(12)
приведет к:
Exception: Invalid value for name
Но:
>>>p = person('Mike')
>>>print(p.name)
Mike
>>>p.name = 'George'
>>>print(p.name)
George
>>>p.name = 2.3 # Causes an exception
With modern git you always fetch all branches (as remote-tracking branches into refs/remotes/origin/*
namespace, visible with git branch -r
or git remote show origin
).
By default (see documentation of push.default
config variable) you push matching branches, which means that first you have to do git push origin branch
for git to push it always on git push
.
If you want to always push all branches, you can set up push refspec. Assuming that the remote is named origin
you can either use git config:
$ git config --add remote.origin.push '+refs/heads/*:refs/heads/*'
$ git config --add remote.origin.push '+refs/tags/*:refs/tags/*'
or directly edit .git/config
file to have something like the following:
[remote "origin"] url = user@example.com:/srv/git/repo.git fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/tags/*:refs/tags/* push = +refs/heads/*:refs/heads/* push = +refs/tags/*:refs/tags/*