io_wrapped_python = StringIO(python)
for token in tokenize.generate_tokens(io_wrapped_python.readline):
if token[1] == "import":
line_being_tokenized = token[4]
if self._build_file_imports_behavior == "warn":
logger.warning("{} tried to import - import statements should be avoided ({})".format(
filepath,
line_being_tokenized
))
elif self._build_file_imports_behavior == "error":
raise ParseError(
"import statements have been banned, but tried to import: {}".format(
line_being_tokenized
)
)
else:
raise ParseError(
"Didn"t know what to do for build_file_imports_behavior value {}".format(
self._build_file_imports_behavior
)
)
return list(self._parse_context._storage.objects)
After Change
io_wrapped_python = StringIO(python)
for token in tokenize.generate_tokens(io_wrapped_python.readline):
token_str = token[1]
lineno, _ = token[2]
self.check_for_deprecated_globs_usage(token_str, filepath, lineno)