typeddjango / pytest-mypy-plugins

pytest plugin for testing mypy types, stubs, and plugins
https://pypi.org/project/pytest-mypy-plugins/
MIT License
99 stars 26 forks source link

Error formatting hangs indefinitely with `regex: true` #95

Closed antonagestam closed 2 years ago

antonagestam commented 2 years ago

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: https://github.com/typeddjango/pytest-mypy-plugins/blob/337d8048fe02cbf68df7de69337999ee61af05d3/pytest_mypy_plugins/utils.py#L148

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.

sobolevn commented 2 years ago

Good catch! Thanks for the report!