Skip to content
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

Fix py-thrift-namespace-clash-check type issue when logging with --no-strict mode #7864

Merged
merged 4 commits into from
Jun 6, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import os
import re
from builtins import zip
from builtins import str, zip

from pants.backend.codegen.thrift.python.python_thrift_library import PythonThriftLibrary
from pants.base.exceptions import TaskError
Expand Down Expand Up @@ -101,7 +101,7 @@ def _extract_all_python_namespaces(self, thrift_file_sources_by_target):
if self.get_options().strict:
raise error
else:
self.context.log.warn(error)
self.context.log.warn(str(error))
return py_namespaces_by_target

class ClashingNamespaceError(TaskError): pass
Expand Down Expand Up @@ -136,7 +136,7 @@ def _determine_clashing_namespaces(self, py_namespaces_by_target):
if self.get_options().strict:
raise error
else:
self.context.log.warn(error)
self.context.log.warn(str(error))
return namespaces_by_files

def execute(self):
Expand Down
11 changes: 9 additions & 2 deletions src/python/pants/reporting/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import threading
import time
from builtins import object
from builtins import bytes, object, str


class ReportingError(Exception):
Expand Down Expand Up @@ -100,8 +100,15 @@ def start_workunit(self, workunit):
def log(self, workunit, level, *msg_elements):
"""Log a message.

Each element of msg_elements is either a message string or a (message, detail) pair.
Each element of msg_elements is either a message or a (message, detail) pair, i.e. of type
Union[str, bytes, Tuple[str, str]].
"""
# TODO(6742): Once we have enough MyPy coverage, we can rely on MyPy to catch any issues for us,
# rather than this runtime check.
# TODO(6071): No longer allow bytes once Py2 is removed.
assert all(isinstance(element, (str, bytes, tuple)) for element in msg_elements), \
"At least one logged message element is not of type " \
"Union[str, bytes, Tuple[str, str]]:\n {}".format(msg_elements)
with self._lock:
for reporter in self._reporters.values():
reporter.handle_log(workunit, level, *msg_elements)
Expand Down