Skip to content

mypy: Improve 'type: ignore' annotations. #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zulip/integrations/google/google-calendar
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def populate_events():
event_timezone = pytz.timezone(event["start"]["timeZone"])
# pytz timezones include an extra localize method that's not part
# of the tzinfo base class.
start = event_timezone.localize(start) # type: ignore
start = event_timezone.localize(start)
except KeyError:
# All-day events can have only a date.
start_naive = dateutil.parser.parse(event["start"]["date"])
Expand All @@ -138,7 +138,7 @@ def populate_events():
calendar_timezone = pytz.timezone(feed["timeZone"])
# pytz timezones include an extra localize method that's not part
# of the tzinfo base class.
start = calendar_timezone.localize(start_naive) # type: ignore
start = calendar_timezone.localize(start_naive)

try:
events.append((event["id"], start, event["summary"]))
Expand Down
2 changes: 1 addition & 1 deletion zulip/integrations/jabber/jabber_mirror_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def config_error(msg):
const=logging.DEBUG,
default=logging.INFO)

jabber_group = optparse.OptionGroup(parser, "Jabber configuration") # type: ignore # https://github.com/python/typeshed/pull/1248
jabber_group = optparse.OptionGroup(parser, "Jabber configuration")
jabber_group.add_option(
'--jid',
default=None,
Expand Down
4 changes: 2 additions & 2 deletions zulip/zulip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def custom_error_handling(self, message):
# type: (Any, str) -> None
self.print_help(sys.stderr)
self.exit(2, '{}: error: {}\n'.format(self.prog, message))
parser.error = types.MethodType(custom_error_handling, parser) # type: ignore
parser.error = types.MethodType(custom_error_handling, parser) # type: ignore # patching function

if allow_provisioning:
parser.add_argument('--provision',
Expand Down Expand Up @@ -181,7 +181,7 @@ def generate_option_group(parser, prefix=''):
is now deprecated. We recommend migrating to argparse and
using zulip.add_default_arguments instead.""")

group = optparse.OptionGroup(parser, 'Zulip API configuration') # type: ignore # https://github.com/python/typeshed/pull/1248
group = optparse.OptionGroup(parser, 'Zulip API configuration')
group.add_option('--%ssite' % (prefix,),
dest="zulip_site",
help="Zulip server URI",
Expand Down
8 changes: 4 additions & 4 deletions zulip_bots/generate_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def run(self):
# type: () -> None
if self.release:
generate_release_manifest()
self.announce( # type: ignore # error: "GenerateManifest" has no attribute "announce"
self.announce( # type: ignore # https://github.com/zulip/python-zulip-api/issues/142
'Generating a MANIFEST for a PyPA release of zulip_bots.',
level=distutils.log.INFO # type: ignore # error: Module has no attribute "INFO"
level=distutils.log.INFO # type: ignore # https://github.com/zulip/python-zulip-api/issues/142
)
else:
generate_dev_manifest()
self.announce( # type: ignore
self.announce( # type: ignore # https://github.com/zulip/python-zulip-api/issues/142
'Generating a MANIFEST for zulip_bots\' development.',
level=distutils.log.INFO # type: ignore
level=distutils.log.INFO # type: ignore # https://github.com/zulip/python-zulip-api/issues/142
)

def get_test_fixtures():
Expand Down
2 changes: 1 addition & 1 deletion zulip_bots/zulip_bots/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_config_info(self, bot_name, optional=False):
config = configparser.ConfigParser()
try:
with open(conf_file_path) as conf:
config.readfp(conf) # type: ignore
config.readfp(conf) # type: ignore # readfp->read_file in python 3, so not in stubs
except IOError:
if optional:
return dict()
Expand Down
16 changes: 9 additions & 7 deletions zulip_botserver/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any
from zulip_botserver import server
from .server_test_lib import BotServerTestCase
import six

class BotServerTests(BotServerTestCase):
class MockMessageHandler(object):
Expand Down Expand Up @@ -48,13 +49,14 @@ def test_wrong_bot_credentials(self, mock_LoggingError):
'site': 'http://localhost',
}
}
# This complains about mismatching argument types, yet they are all correct?
# We should investigate and file an issue in mypy.
self.assertRaisesRegexp(ImportError, # type: ignore
"Bot \"nonexistent-bot\" doesn't exists. Please "
"make sure you have set up the flaskbotrc file correctly.",
lambda: self.assert_bot_server_response(available_bots=available_bots,
bots_config=bots_config))
# TODO: The following passes mypy, though the six stubs don't match the
# unittest ones, so we could file a mypy bug to improve this.
six.assertRaisesRegex(self,
ImportError,
"Bot \"nonexistent-bot\" doesn't exists. Please "
"make sure you have set up the flaskbotrc file correctly.",
lambda: self.assert_bot_server_response(available_bots=available_bots,
bots_config=bots_config))

if __name__ == '__main__':
unittest.main()