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

Unclear error message when annotating implements with something else than a Name #3297

Closed
trocher opened this issue Feb 21, 2023 · 0 comments · Fixed by #3304
Closed

Unclear error message when annotating implements with something else than a Name #3297

trocher opened this issue Feb 21, 2023 · 0 comments · Fixed by #3304
Labels
bug - typechecker issue with typechecker

Comments

@trocher
Copy link
Contributor

trocher commented Feb 21, 2023

Version Information

  • vyper Version (output of vyper --version): 0.3.8+commit.7ff8f307
  • OS: OSX
  • Python Version (output of python --version): 3.8.0

What's your issue about?

When improperly using implements and passing it something else than a Name as an annotation, the compiler outputs an unclear error as the UnexpectedNodeType it tries to raise is constructed with 2 arguments instead of 1.

vyper/vyper/ast/nodes.py

Lines 1404 to 1405 in 0a64906

if not isinstance(self.annotation, Name):
raise UnexpectedNodeType("not an identifier", self.annotation)

Additionally, UnexpectedNodeType is an exception used to notify the user that what happened is an unhandled internal compiler error while it does not seem to be the case here.

The following code outputs the given error:

implements: self.x
Traceback (most recent call last):
  File "/Users/trocher/Documents/thesis/vyper/venv/bin/vyper", line 11, in <module>
    load_entry_point('vyper==0.3.8', 'console_scripts', 'vyper')()
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 57, in _parse_cli_args
    return _parse_args(sys.argv[1:])
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 154, in _parse_args
    compiled = compile_files(
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 298, in compile_files
    interface_codes=get_interface_codes(root_path, contract_sources),
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/vyper_compile.py", line 200, in get_interface_codes
    interface_codes = extract_file_interface_imports(code)
  File "/Users/trocher/Documents/thesis/vyper/vyper/cli/utils.py", line 30, in extract_file_interface_imports
    ast_tree = vy_ast.parse_to_ast(code)
  File "/Users/trocher/Documents/thesis/vyper/vyper/ast/utils.py", line 54, in parse_to_ast
    return vy_ast.get_node(py_ast)  # type: ignore
  File "/Users/trocher/Documents/thesis/vyper/vyper/ast/nodes.py", line 92, in get_node
    return vy_class(parent=parent, **ast_struct)
  File "/Users/trocher/Documents/thesis/vyper/vyper/ast/nodes.py", line 274, in __init__
    value = [_to_node(i, self) for i in value]
  File "/Users/trocher/Documents/thesis/vyper/vyper/ast/nodes.py", line 274, in <listcomp>
    value = [_to_node(i, self) for i in value]
  File "/Users/trocher/Documents/thesis/vyper/vyper/ast/nodes.py", line 141, in _to_node
    return get_node(obj, parent)
  File "/Users/trocher/Documents/thesis/vyper/vyper/ast/nodes.py", line 92, in get_node
    return vy_class(parent=parent, **ast_struct)
  File "/Users/trocher/Documents/thesis/vyper/vyper/ast/nodes.py", line 1404, in __init__
    raise UnexpectedNodeType("not an identifier", self.annotation)
TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - typechecker issue with typechecker
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants