Skip to content

AttributeError (StringQuoteChecker.config) with release of pylint==3.0.0 #1

@4nds

Description

@4nds

Bug description

When parsing the following utils.py:

"""Utilities for the example project."""


def do_something():
    '''Does something.'''
    return 'something'


def do_something_else():
    '''Does something else.

    Returns:
        str: A string of some sort.
    '''
    return "string1 " + 'string2'

The following error occurs with newer Pylint (>=3.0.0):

Traceback (most recent call last):
  File "d:\Python\Python311\Lib\site-packages\pylint\lint\pylinter.py", line 788, in _lint_file
    check_astroid_module(module)
  File "d:\Python\Python311\Lib\site-packages\pylint\lint\pylinter.py", line 1017, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\Python\Python311\Lib\site-packages\pylint\lint\pylinter.py", line 1067, in _check_astroid_module
    token_checker.process_tokens(tokens)
  File "d:\Python\Python311\Lib\site-packages\pylint_quotes\checker.py", line 263, in process_tokens
    self._process_string_token(token, start_row, start_col)
  File "d:\Python\Python311\Lib\site-packages\pylint_quotes\checker.py", line 289, in _process_string_token
    preferred_quote = SMART_QUOTE_OPTS.get(self.config.string_quote)
                                           ^^^^^^^^^^^
AttributeError: 'StringQuoteChecker' object has no attribute 'config'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "d:\Python\Python311\Lib\site-packages\pylint\lint\pylinter.py", line 752, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "d:\Python\Python311\Lib\site-packages\pylint\lint\pylinter.py", line 790, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Pylint version

pylint 3.0.3
astroid 3.0.3
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]

OS / Environment

win32 (Windows)

Script used

I used the following script to produce the error for debugging purposes, but the same error occurs when running Pylint in command line or using Pylint extension in Visual Studio Code:

"""File for testing pylint."""

import pylint.lint


def check_file(file_path: str) -> int:
    """Function checking file with pylint."""
    if not file_path.endswith('.py'):
        return 0

    pylint_opts = [
        "--load-plugins=pylint_quotes",
        "--string-quote=single-avoid-escape",
        "--triple-quote=single",
        "--docstring-quote=double",
    ]
    runner = pylint.lint.Run(pylint_opts + [file_path], exit=False)
    return runner.linter.msg_status


check_file(r'pylint-quotes/example/foo/utils.py')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions