First, please verify that the bug is not already filled: https://github.com/PyCQA/pylint/issues/ Then create a new crash issue: https://github.com/PyCQA/pylint/issues/new?assignees=&labels=crash%2Cneeds+triage&template=BUG-REPORT.yml Issue title: Crash ``Parsing Python code failed: EOL while scanning string literal (, line 10)`` (if possible, be more specific about what made pylint crash) Content: When parsing the following file: ```python import random import math from typing import Union, List, Dict, NewType from enum import Enum import numpy as np from pydantic import BaseModel, root_validator, NonNegativeInt, NonNegativeFloat class RangeType(Enum): """ This class represents the types of parameter ranges """ STEP = 'step' MULTIPLE = 'muliple' LOGARITHMIC = 'logarithmic' POWER = 'power' class RangeBase: def __getitem__(self, t): # Not quite sure how to get the "is this an int" out of the PositiveInt and PositiveFloat # types from pydantic, so we just get the string representation of the type and look for # 'int' if 'int' in str(t).lower(): step_type = NonNegativeInt else: step_type = NonNegativeFloat class GenericRange(BaseModel): min: t max: t = None step: step_type range_type: RangeType = RangeType.STEP @root_validator(allow_reuse=True) def validate_range(cls, values): # pylint: disable=no-self-argument max_val = values.get('max') min_val = values.get('min') if max_val is None: values['max'] = min_val else: if max_val < min_val: raise ValueError('Max val for a range must be >= to the min val') if values.get('step') == 0 and values.get('range_type') == RangeType.MULTIPLE.value: raise ValueError(f'step of 0 is not value with {values.get("range_type")} type') return values RetType = NewType(f'IntRange_{t}', Union[t, List[t], GenericRange]) return RetType ParameterRange = RangeBase() ``` pylint crashed with a ``AstroidSyntaxError`` and with the following stacktrace: ``` Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/inference_tip.py", line 28, in _inference_tip_cached result = _cache[func, node] KeyError: (, ) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 181, in _data_build node, parser_module = _parse_string(data, type_comments=True) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 461, in _parse_string parsed = parser_module.parse(data + "\n", type_comments=type_comments) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/_ast.py", line 45, in parse return parse_func(string) File "/usr/lib/python3.8/ast.py", line 47, in parse return compile(source, filename, mode, flags, File "", line 10 class f'IntRange_{t}(metaclass=Meta): ^ SyntaxError: EOL while scanning string literal The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1034, in _check_files self._check_file(get_ast, check_astroid_module, file) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1069, in _check_file check_astroid_module(ast_node) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1203, in check_astroid_module retval = self._check_astroid_module( File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1250, in _check_astroid_module walker.walk(node) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk self.walk(child) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk self.walk(child) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk callback(astroid) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/checkers/classes.py", line 2186, in visit_functiondef inferred = _safe_infer_call_result(node, node) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/checkers/classes.py", line 441, in _safe_infer_call_result value = next(inferit) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 1976, in infer_call_result yield from returnnode.value.infer(context) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/node_ng.py", line 150, in infer yield from self._infer(context, **kwargs) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 142, in raise_if_nothing_inferred yield next(generator) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 111, in wrapped for res in _func(node, context, **kwargs): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/bases.py", line 157, in _infer_stmts for inf in stmt.infer(context=context): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/node_ng.py", line 164, in infer for i, result in enumerate(generator): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 142, in raise_if_nothing_inferred yield next(generator) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 111, in wrapped for res in _func(node, context, **kwargs): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/bases.py", line 157, in _infer_stmts for inf in stmt.infer(context=context): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/node_ng.py", line 140, in infer results = list(self._explicit_inference(self, context, **kwargs)) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/inference_tip.py", line 30, in _inference_tip_cached result = _cache[func, node] = list(func(*args, **kwargs)) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/brain/brain_typing.py", line 132, in infer_typing_typevar_or_newtype node = extract_node(TYPING_TYPE_TEMPLATE.format(typename)) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 438, in extract_node tree = parse(code, module_name=module_name) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 296, in parse return builder.string_build(code, modname=module_name, path=path) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 155, in string_build module = self._data_build(data, modname, path) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 183, in _data_build raise AstroidSyntaxError( astroid.exceptions.AstroidSyntaxError: Parsing Python code failed: EOL while scanning string literal (, line 10) ``` Issue title: Crash ``Parsing Python code failed: EOL while scanning string literal (, line 10)`` (if possible, be more specific about what made pylint crash) Content: When parsing the following file: ```python import random import math from typing import Union, List, Dict, NewType from enum import Enum import numpy as np from pydantic import BaseModel, root_validator, NonNegativeInt, NonNegativeFloat class RangeType(Enum): """ This class represents the types of parameter ranges """ STEP = 'step' MULTIPLE = 'muliple' LOGARITHMIC = 'logarithmic' POWER = 'power' class RangeBase: def __getitem__(self, t): # Not quite sure how to get the "is this an int" out of the PositiveInt and PositiveFloat # types from pydantic, so we just get the string representation of the type and look for # 'int' if 'int' in str(t).lower(): step_type = NonNegativeInt else: step_type = NonNegativeFloat class GenericRange(BaseModel): min: t max: t = None step: step_type range_type: RangeType = RangeType.STEP @root_validator(allow_reuse=True) def validate_range(cls, values): # pylint: disable=no-self-argument max_val = values.get('max') min_val = values.get('min') if max_val is None: values['max'] = min_val else: if max_val < min_val: raise ValueError('Max val for a range must be >= to the min val') if values.get('step') == 0 and values.get('range_type') == RangeType.MULTIPLE.value: raise ValueError(f'step of 0 is not value with {values.get("range_type")} type') return values RetType = NewType(f'Range_{t}', Union[t, List[t], GenericRange]) return RetType ParameterRange = RangeBase() ``` pylint crashed with a ``AstroidSyntaxError`` and with the following stacktrace: ``` Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/inference_tip.py", line 28, in _inference_tip_cached result = _cache[func, node] KeyError: (, ) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 181, in _data_build node, parser_module = _parse_string(data, type_comments=True) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 461, in _parse_string parsed = parser_module.parse(data + "\n", type_comments=type_comments) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/_ast.py", line 45, in parse return parse_func(string) File "/usr/lib/python3.8/ast.py", line 47, in parse return compile(source, filename, mode, flags, File "", line 10 class f'Range_{t}(metaclass=Meta): ^ SyntaxError: EOL while scanning string literal The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1034, in _check_files self._check_file(get_ast, check_astroid_module, file) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1069, in _check_file check_astroid_module(ast_node) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1203, in check_astroid_module retval = self._check_astroid_module( File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1250, in _check_astroid_module walker.walk(node) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk self.walk(child) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk self.walk(child) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk callback(astroid) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/checkers/classes.py", line 2186, in visit_functiondef inferred = _safe_infer_call_result(node, node) File "/home/ubuntu/.local/lib/python3.8/site-packages/pylint/checkers/classes.py", line 441, in _safe_infer_call_result value = next(inferit) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 1976, in infer_call_result yield from returnnode.value.infer(context) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/node_ng.py", line 150, in infer yield from self._infer(context, **kwargs) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 142, in raise_if_nothing_inferred yield next(generator) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 111, in wrapped for res in _func(node, context, **kwargs): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/bases.py", line 157, in _infer_stmts for inf in stmt.infer(context=context): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/node_ng.py", line 164, in infer for i, result in enumerate(generator): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 142, in raise_if_nothing_inferred yield next(generator) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/decorators.py", line 111, in wrapped for res in _func(node, context, **kwargs): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/bases.py", line 157, in _infer_stmts for inf in stmt.infer(context=context): File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/nodes/node_ng.py", line 140, in infer results = list(self._explicit_inference(self, context, **kwargs)) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/inference_tip.py", line 30, in _inference_tip_cached result = _cache[func, node] = list(func(*args, **kwargs)) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/brain/brain_typing.py", line 132, in infer_typing_typevar_or_newtype node = extract_node(TYPING_TYPE_TEMPLATE.format(typename)) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 438, in extract_node tree = parse(code, module_name=module_name) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 296, in parse return builder.string_build(code, modname=module_name, path=path) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 155, in string_build module = self._data_build(data, modname, path) File "/home/ubuntu/.local/lib/python3.8/site-packages/astroid/builder.py", line 183, in _data_build raise AstroidSyntaxError( astroid.exceptions.AstroidSyntaxError: Parsing Python code failed: EOL while scanning string literal (, line 10) ```