python / python/mypy

`dmypy recheck --update [file]` failed to detect very recent changes in [file]

Đang mở
#12,697 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug topic-daemon
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug Report

Hi, I'm trying to implement an interactive type checking environment where a (deep learning-based) type inference agent needs to repeatedly make small changes to a given source file and query mypy to figure out if the changes introduce any type error. I'm using the dmypy recheck --update command to reduce the type checking time since I need these queries to be as fast as possible. However, it seems that this command would fail to detect very recent file changes and report outdated results. Is there a way to explicitly tell dmypy that it should recheck a given file?

To Reproduce

Run the following script

from pathlib import Path
import subprocess
import time

# no type error
code_1 = '''
from typing import Any
def fib(n: int) -> int:
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fib(n-1) + fib(n-2)
'''

# incorrect return type
code_2 = '''
from typing import Any
def fib(n: int) -> str:
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fib(n-1) + fib(n-2)
'''

# changed return type to Any, should not error
code_3 = '''
from typing import Any
def fib(n: int) -> Any:
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fib(n-1) + fib(n-2)
'''

# this should be the dmypy path in the current virtual env
dmypy_path = '/home/jiayi/Projects/SPOT/.venv/bin/dmypy'

check_dir = Path("temp/type_check")
check_dir.mkdir(exist_ok=True, parents=True)
with open(check_dir / "code.py", "w") as f:
    f.write(code_1)
subprocess.run(['python', dmypy_path, 'restart', '--', '--follow-imports=skip'],cwd=check_dir)

print('---checking code_1---')
subprocess.run(['python', dmypy_path, 'check', '.'],cwd=check_dir)

with open(check_dir / "code.py", "w") as f:
    f.write(code_2)
print('---checking code_2---')
subprocess.run(['python', dmypy_path, 'recheck', "--update", "code.py"],cwd=check_dir)

with open(check_dir / "code.py", "w") as f:
    f.write(code_3)
print('---checking code_3---')
subprocess.run(['python', dmypy_path, 'recheck', "--update", "code.py"],cwd=check_dir)
print("test finished.")

print('---wait and check code_3 again---')
time.sleep(1.0)  # will not work if waiting time is shorter
with open(check_dir / "code.py", "w") as f:  # need this rewriting
    f.write(code_3)
subprocess.run(['python', dmypy_path, 'recheck', "--update", "code.py"],cwd=check_dir)
print("test finished.")

This produced the following result on my machine

Daemon stopped
Daemon started
---checking code_1---
Success: no issues found in 1 source file
---checking code_2---
code.py:5: error: Incompatible return value type (got "int", expected "str")
code.py:7: error: Incompatible return value type (got "int", expected "str")
Found 2 errors in 1 file (checked 2 source files)
---checking code_3---
code.py:5: error: Incompatible return value type (got "int", expected "str")
code.py:7: error: Incompatible return value type (got "int", expected "str")
Found 2 errors in 1 file (checked 2 source files)
test finished.
---wait and check code_3 again---
Success: no issues found in 2 source files
test finished.

Expected Behavior

The result for code_3 should contain no type error.

Actual Behavior

The result for code_3 without first waiting is incorrect and looks outdated (is the same as code_2).

(Write what happened.)

Your Environment

  • Mypy version used: 0.950
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files): empty
  • Python version used: Python 3.10.4
  • Operating system and version: Ubuntu 18.04.6 LTS

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy bản tái hiện Python được cung cấp với các lệnh dmypy restart, check và lặp lại recheck --update code.py. Theo dõi cách dmypy recheck --update [file] xử lý các lần ghi liên tiếp nhanh; hoàn thành khi bản cập nhật code_3 ngay lập tức báo không có lỗi mà không cần trì hoãn hoặc ghi lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
cli, tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.