Skip to content

Commit a7af812

Browse files
committed
Make optional argument use an immutable set for the default value
in no-commit-to-branch. Make other sets immutable to satisfy type-checking and be consistent
1 parent 6568414 commit a7af812

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pre_commit_hooks/no_commit_to_branch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import argparse
44
import re
5+
from typing import FrozenSet
56
from typing import Optional
67
from typing import Sequence
7-
from typing import Set
88

99
from pre_commit_hooks.util import CalledProcessError
1010
from pre_commit_hooks.util import cmd_output
1111

1212

13-
def is_on_branch(protected, patterns=set()):
14-
# type: (Set[str], Set[str]) -> bool
13+
def is_on_branch(protected, patterns=frozenset()):
14+
# type: (FrozenSet[str], FrozenSet[str]) -> bool
1515
try:
1616
ref_name = cmd_output('git', 'symbolic-ref', 'HEAD')
1717
except CalledProcessError:
@@ -33,13 +33,13 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
3333
'-p', '--pattern', action='append',
3434
help=(
3535
'regex pattern for branch name to disallow commits to, '
36-
'May be specified multiple times'
36+
'may be specified multiple times'
3737
),
3838
)
3939
args = parser.parse_args(argv)
4040

41-
protected = set(args.branch or ('master',))
42-
patterns = set(args.pattern or ())
41+
protected = frozenset(args.branch or ('master',))
42+
patterns = frozenset(args.pattern or ())
4343
return int(is_on_branch(protected, patterns))
4444

4545

0 commit comments

Comments
 (0)