Skip to content

Crash on older versions of Python for a slice in a type subscript #17679

Closed as not planned
@VictorSizov

Description

@VictorSizov

Crash Report

Validating of my python module causes "INTERNAL ERROR"

Traceback

version: 1.11.1
Traceback (most recent call last):
File "/home/sizov/Documents/root/venv/bin/mypy", line 8, in
sys.exit(console_entry())
File "mypy/build.py", line 2069, in wrap_context
File "mypy/build.py", line 2176, in parse_file
File "mypy/build.py", line 841, in parse_file
File "mypy/parse.py", line 27, in parse
File "mypy/fastparse.py", line 234, in parse
File "mypy/fastparse.py", line 401, in visit
File "mypy/fastparse.py", line 860, in visit_Module
File "mypy/fastparse.py", line 475, in translate_stmt_list
File "mypy/fastparse.py", line 401, in visit
File "mypy/fastparse.py", line 873, in visit_FunctionDef
File "mypy/fastparse.py", line 890, in do_func_def
File "mypy/fastparse.py", line 1072, in transform_args
File "mypy/fastparse.py", line 1115, in make_argument
File "mypy/fastparse.py", line 1877, in visit
File "mypy/fastparse.py", line 2086, in visit_Subscript
File "mypy/fastparse.py", line 1877, in visit
File "mypy/fastparse.py", line 2065, in visit_Subscript
AttributeError: 'NoneType' object has no attribute 'col_offset'
parser.py: : note: use --pdb to drop into pdb

To Reproduce

write stand-alone example to disk as python file:


from typing import Dict, Optional, Union, List

def copy_attrs(src: Dict[str, Union[str, List[str]]], attr_filter: Optional[List[:str]] = None):
    # копируем только str/int и списки str/int
    def check_add_attr(dest, key, val):
        if isinstance(val, list):
            if not val:
                raise Exception("Empty index")
            val_res = list()
            for sub_val in val:
                if isinstance(sub_val, str):
                    sub_val = sub_val.lower()
                elif not isinstance(sub_val, int):
                    return
                val_res.append(sub_val)
            dest[key] = val_res
            return
        elif isinstance(val, str):
            val = val.lower()
        elif not isinstance(val, int):
            return
        dest[key] = val

    dest = dict()
    for key, val in list(src.items()):
        if attr_filter and key not in attr_filter:
            continue
        check_add_attr(dest, key, val)
        del src[key]
    return dest

and call "mypy <stand-alone example>"

My Environment

  • Mypy version used: 1.11.1
  • Mypy command-line flags: --show-traceback
  • Python version used: 3.10.12, 3.8.19
  • Operating system and version: Ubuntu 22.04.4 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions