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

Parsing of commented code throws 'misplaced type annotation' #708

Closed
Flamefire opened this issue Oct 18, 2019 · 1 comment
Closed

Parsing of commented code throws 'misplaced type annotation' #708

Flamefire opened this issue Oct 18, 2019 · 1 comment

Comments

@Flamefire
Copy link

Steps to reproduce

  1. Try to parse e.g. tensorflow_core/python/ops/gen_resource_variable_ops.py

Alternatively the code that triggers this:

def _InitOpDefLibrary(op_list_proto_bytes):
  op_list = _op_def_pb2.OpList()
  op_list.ParseFromString(op_list_proto_bytes)
  _op_def_registry.register_op_list(op_list)
  op_def_lib = _op_def_library.OpDefLibrary()
  op_def_lib.add_op_list(op_list)
  return op_def_lib
# op {
#   name: "AssignAddVariableOp"
#   input_arg {
#     name: "resource"
#     type: DT_RESOURCE
#   }
#   input_arg {
#     name: "value"
#     type_attr: "dtype"
#   }
#   attr {
#     name: "dtype"
#     type: "type"
#   }
#   is_stateful: true
# }

Current behavior

Exception thrown (SyntaxError)

Expected behavior

Exception/Error ignored (as there is none)

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.3.1

Note that this happens when parsing tensorflow e.g. for pylint, so this is a real use case, although with presumptly generated code.

@PCManticore
Copy link
Contributor

Thanks for submitting an issue! The problem was caused by typed_ast which we use to parse the source code for retrieving type comments. Unfortunately whenever it finds an invalid type comment, it fails with a SyntaxError. In your example it was treating the # type: comments as type comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants