mypy: Amend code & typing of integrations, to pass with strict-optional.

This commit is contained in:
neiljp (Neil Pilgrim) 2017-12-22 09:51:14 -08:00 committed by showell
parent 08bfe9d8c7
commit 33ccc04a32
6 changed files with 15 additions and 13 deletions

View file

@ -286,10 +286,10 @@ def run_mirror():
try:
sleepInterval = 1
while True:
events = make_api_call("activity")[::-1]
events = make_api_call("activity")
if events is not None:
sleepInterval = 1
for event in events:
for event in events[::-1]:
timestamp = event.get('event', {}).get('timestamp', '')
event_date = dateutil.parser.parse(timestamp)
if event_date > since:

View file

@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from typing import Dict, Text
from typing import Dict, Text, Optional
# Change these values to configure authentication for the plugin
ZULIP_USER = "git-bot@example.com"
@ -42,7 +42,7 @@ ZULIP_API_KEY = "0123456789abcdef0123456789abcdef"
# * topic "master"
# And similarly for branch "test-post-receive" (for use when testing).
def commit_notice_destination(repo, branch, commit):
# type: (Text, Text, Text) -> Dict[Text, Text]
# type: (Text, Text, Text) -> Optional[Dict[Text, Text]]
if branch in ["master", "test-post-receive"]:
return dict(stream = "commits",
subject = u"%s" % (branch,))

View file

@ -8,9 +8,11 @@ from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
from typing import Optional
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() # type: Optional[argparse.Namespace]
except ImportError:
flags = None

View file

@ -21,7 +21,7 @@
# THE SOFTWARE.
# https://github.com/python/mypy/issues/1141
from typing import Dict, Text
from typing import Dict, Text, Optional
# Change these values to configure authentication for the plugin
ZULIP_USER = 'openshift-bot@example.com'
@ -42,7 +42,7 @@ ZULIP_API_KEY = '0123456789abcdef0123456789abcdef'
# * topic "master"
# And similarly for branch "test-post-receive" (for use when testing).
def deployment_notice_destination(branch):
# type: (str) -> Dict[str, Text]
# type: (str) -> Optional[Dict[str, Text]]
if branch in ['master', 'test-post-receive']:
return dict(stream = 'deployments',
subject = u'%s' % (branch,))
@ -69,7 +69,7 @@ def format_deployment_message(
## If properly installed, the Zulip API should be in your import
## path, but if not, set a custom path below
ZULIP_API_PATH = None # type: str
ZULIP_API_PATH = None # type: Optional[str]
# Set this to your Zulip server's API URI
ZULIP_SITE = 'https://zulip.example.com'

View file

@ -11,10 +11,10 @@ import unicodedata
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'api'))
import zulip
from typing import Set
from typing import Set, Optional
def fetch_public_streams():
# type: () -> Set[bytes]
# type: () -> Optional[Set[bytes]]
public_streams = set()
try:

View file

@ -21,7 +21,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from __future__ import absolute_import
from typing import IO, Any, Dict, List, Text, Union, Set, Tuple
from typing import IO, Any, Dict, List, Text, Union, Set, Tuple, Optional
from types import FrameType
import sys
@ -309,7 +309,7 @@ def parse_zephyr_body(zephyr_data, notice_format):
return (zsig, body)
def parse_crypt_table(zephyr_class, instance):
# type: (Text, str) -> str
# type: (Text, str) -> Optional[str]
try:
crypt_table = open(os.path.join(os.environ["HOME"], ".crypt-table"))
except IOError:
@ -604,7 +604,7 @@ def send_unauthed_zephyr(zwrite_args, content):
return send_zephyr(zwrite_args + ["-d"], content)
def zcrypt_encrypt_content(zephyr_class, instance, content):
# type: (str, str, str) -> str
# type: (str, str, str) -> Optional[str]
keypath = parse_crypt_table(zephyr_class, instance)
if keypath is None:
return None