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
diff --git a/pre_commit_hooks/no_commit_to_branch.py b/pre_commit_hooks/no_commit_to_branch.py
index 585eadc..a1015f4 100644
--- a/pre_commit_hooks/no_commit_to_branch.py
+++ b/pre_commit_hooks/no_commit_to_branch.py
@@ -2,16 +2,16 @@
import argparse
import re
+from typing import FrozenSet
from typing import Optional
from typing import Sequence
-from typing import Set
from pre_commit_hooks.util import CalledProcessError
from pre_commit_hooks.util import cmd_output
-def is_on_branch(protected, patterns=set()):
- # type: (Set[str], Set[str]) -> bool
+def is_on_branch(protected, patterns=frozenset()):
+ # type: (FrozenSet[str], FrozenSet[str]) -> bool
try:
ref_name = cmd_output('git', 'symbolic-ref', 'HEAD')
except CalledProcessError:
@@ -33,13 +33,13 @@
'-p', '--pattern', action='append',
help=(
'regex pattern for branch name to disallow commits to, '
- 'May be specified multiple times'
+ 'may be specified multiple times'
),
)
args = parser.parse_args(argv)
- protected = set(args.branch or ('master',))
- patterns = set(args.pattern or ())
+ protected = frozenset(args.branch or ('master',))
+ patterns = frozenset(args.pattern or ())
return int(is_on_branch(protected, patterns))