typeddjango/pytest-mypy-plugins

Error formatting hangs indefinitely with `regex: true`

antonagestam opened this issue · 1 comments

I'm running into case where the plugin seems to hang indefinitely. I did a little digging and inspected with breakpoint().

This case reproduces the forever loop, I didn't manage to reduce this further, it seems it depends somewhat on producing notes with asterisks (*) in them and I'm not entirely sure of what the logic within mypy is for that (it seems to vary when disable_cache: true isn't given ...).

- case: repro
  disable_cache: true
  regex: true
  main: |
    from predicates import is_valid_name
    reveal_type(is_valid_name)
    is_valid_name(1)
  out: |
    main:2: note: Revealed type is "def \(builtins\.str.?\) -> builtins\.bool.?"
    main:3: error: Argument 1 has incompatible type "int"; expected "str"  [arg-type]
  files:
    - path: compose.py
      content: |
        from typing import TypeVar, Callable
        AA = TypeVar("AA")
        AR = TypeVar("AR")
        BA = TypeVar("BA")
        def compose2(a: Callable[[AA], AR], b: Callable[[BA], AA]) -> Callable[[BA], AR]:
            ...
    - path: predicates.py
      content: |
        from typing import Callable
        from compose import compose2
        Predicate = Callable[[object], bool]
        as_parts: Callable[[str], list[str]] = ...
        is_valid_parts: Predicate[list[str]] = ...
        is_valid_name = compose2(is_valid_parts, as_parts)

This is the loop that keeps running forever, because it's given two identical strings:

while s1[:30] == s2[:30]:

I think this might not be a high-priority issue, because I think the pattern might not make sense, nevertheless, it seems sensible to have a guard in place at some level.

Good catch! Thanks for the report!