From 8dba310bee94e09831e9d298e37aad08b954b6df Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 22 Feb 2017 16:06:04 -0800 Subject: [PATCH] messages: Remove some unnecessary zephyr code paths. The comments explain why this change is correct. This change is useful because it's better to not have dead code paths, both because it makes our life easier for coverage analysis, and because the else statement provided the illusion that it could actually happen. If the analysis in that comment is wrong, we'd rather have a 500 error so we fix the bug than things silently sorta working. --- zerver/views/messages.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/zerver/views/messages.py b/zerver/views/messages.py index 5458bce95c..61f2759304 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -173,10 +173,10 @@ class NarrowBuilder(object): # MIT users expect narrowing to "social" to also show messages to /^(un)*social(.d)*$/ # (unsocial, ununsocial, social.d, etc) m = re.search(r'^(?:un)*(.+?)(?:\.d)*$', stream.name, re.IGNORECASE) - if m: - base_stream_name = m.group(1) - else: - base_stream_name = stream.name + # Since the regex has a `.+` in it and "" is invalid as a + # stream name, this will always match + assert(m is not None) + base_stream_name = m.group(1) matching_streams = get_active_streams(self.user_profile.realm).filter( name__iregex=r'^(un)*%s(\.d)*$' % (self._pg_re_escape(base_stream_name),)) @@ -195,10 +195,9 @@ class NarrowBuilder(object): # MIT users expect narrowing to topic "foo" to also show messages to /^foo(.d)*$/ # (foo, foo.d, foo.d.d, etc) m = re.search(r'^(.*?)(?:\.d)*$', operand, re.IGNORECASE) - if m: - base_topic = m.group(1) - else: - base_topic = operand + # Since the regex has a `.*` in it, this will always match + assert(m is not None) + base_topic = m.group(1) # Additionally, MIT users expect the empty instance and # instance "personal" to be the same.