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

Crash 'Values' object has no attribute 'additional_builtins' #6408

Closed
mh21 opened this issue Apr 20, 2022 · 4 comments
Closed

Crash 'Values' object has no attribute 'additional_builtins' #6408

mh21 opened this issue Apr 20, 2022 · 4 comments
Labels
Crash 💥 A bug that makes pylint crash
Milestone

Comments

@mh21
Copy link

mh21 commented Apr 20, 2022

Bug description

When parsing the following file:

"""YAML CLI tools for miscellaneous operations not supported by shyaml."""
import argparse
import re
import sys
import typing

import yaml


def split_dot(data: str) -> typing.List[str]:
    """Split string on dots, but ignore backslash+dot."""
    return list(t.replace(r'\.', '.') for t in re.split(r'(?<!\\)\.', data))


def set_value(data: typing.Any, key_path: str, value: typing.Any) -> None:
    """Implement the set-value command."""
    target = data
    keys = split_dot(key_path)
    key: typing.Union[str, int]
    for index, key in enumerate(keys):
        if isinstance(target, list):
            key = int(key)
        if index < len(keys) - 1:
            target = target[key]
        else:
            target[key] = yaml.safe_load(value)


def delete(data: typing.Any, key_path: str) -> None:
    """Implement the del command."""
    target = data
    keys = split_dot(key_path)
    key: typing.Union[str, int]
    for index, key in enumerate(keys):
        if isinstance(target, list):
            key = int(key)
        if index < len(keys) - 1:
            target = target[key]
        else:
            del target[key]


def main(args: typing.Sequence[str]) -> None:
    """Run CLI YAML tool."""
    parser = argparse.ArgumentParser(description='Miscellaneous YAML operations')

    parser.add_argument('action', choices=('set-value', 'del'), help='Action to perform')
    parser.add_argument('key', help='Target for the action')
    parser.add_argument('value', nargs='?', help='YAML-formatted value')
    parsed_args = parser.parse_args(args)

    data = yaml.safe_load(sys.stdin)

    if parsed_args.action == 'set-value':
        set_value(data, parsed_args.key, parsed_args.value)
    elif parsed_args.action == 'del':
        delete(data, parsed_args.key)
    else:
        raise Exception(f'Unknown action {parsed_args.action}')

    yaml.safe_dump(data, stream=sys.stdout)


if __name__ == '__main__':
    main(sys.argv[1:])

pylint crashed with a AttributeError and with the following stacktrace:

Traceback (most recent call last):
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1111, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1146, in _check_file
    check_astroid_module(ast_node)
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1298, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1345, in _check_astroid_module
    walker.walk(node)
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 76, in walk
    self.walk(child)
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 76, in walk
    self.walk(child)
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 76, in walk
    self.walk(child)
  [Previous line repeated 3 more times]
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 73, in walk
    callback(astroid)
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/checkers/variables.py", line 1377, in visit_name
    self._undefined_and_used_before_checker(node, stmt)
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/checkers/variables.py", line 1419, in _undefined_and_used_before_checker
    action, nodes_to_consume = self._check_consumer(
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/checkers/variables.py", line 1680, in _check_consumer
    elif self._is_only_type_assignment(node, defstmt):
  File "/home/mh21/git/cki/cki-tools/.direnv/python-3.8.10/lib/python3.8/site-packages/pylint/checkers/variables.py", line 2072, in _is_only_type_assignment
    if node.name in self.linter.config.additional_builtins or utils.is_builtin(
AttributeError: 'Values' object has no attribute 'additional_builtins'

Configuration

No response

Command used

pylint cki/cki_tools/yaml.py

Pylint output

see above

Expected behavior

no crash

Pylint version

$ pylint --version
pylint 2.13.6
astroid 2.11.3
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0]


### OS / Environment

Ubuntu 20.04 LTS

### Additional dependencies

_No response_
@mh21 mh21 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 20, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 20, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.7 milestone Apr 20, 2022
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue, it look like we cherry-picked a commit that we could not cherry-pick.

@DanielNoord
Copy link
Collaborator

DanielNoord commented Apr 20, 2022

@Pierre-Sassoulas we might want to yank 2.13.6 asap. That build is broken.

Faulty commit is ddca4dd.

L2072 with self.linter.config.additional_builtins doesn't work.

Edit: To make it work on a non-argparse-ready build I think it should be self.config.additional_builtins.

@mbyrnepr2
Copy link
Member

I don't see the crash happening on latest main:

pylint 2.14.0-dev0
astroid 2.11.3
Python 3.10.0b2

Can reproduce with 2.13.6 as reported.

@Pierre-Sassoulas
Copy link
Member

we might want to yank 2.13.6 asap.

Yeah, the issue is that I don't have managing right. Let's release 2.13.7 after #6410

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

No branches or pull requests

4 participants