from typing import Any
import ast


def _is_lexical_match(matched: Any) -> bool:
  """Returns whether the match can be a lexical one.

  Its not well documented what ast objects return token information and
  which ones don't, and there are known instances of the token information
  being wrong in certain cases.

  Args:
    matched: the matched object.

  Returns:
    whether it can be a LexicalASTMatch or not.
  """
  first_token = getattr(matched, 'first_token', None)
  last_token = getattr(matched, 'last_token', None)
  if not (first_token and last_token):
    return False

  if isinstance(matched, ast.arguments):
    # When there are no args, then the offsets are wrong.
    return bool(matched.args)
  if isinstance(matched, ast.alias):
    # The offsets correspond to the "import" keyword instead of the alias name.
    return False
  return True