mypy does not show error in excluded folder when PYTHONPATH set

Đang mở
#16,973 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.

Đánh giá

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

Hướng nghiên cứu

Bắt đầu với bố cục package được tái hiện, chứa excluded_folder/excluded.py và included_folder/included.py, sau đó so sánh hai lệnh mypy có và không có PYTHONPATH=. Theo dõi cách --exclude và các module được import được phát hiện. Được xem là hoàn tất khi lần gọi với PYTHONPATH=. báo cáo giá trị trả về không tương thích trong excluded.py, với một regression test bao phủ cả hai lệnh.

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

Mô tả

bug

Bug Report

As far as I understand, when I use the exclude setting for some folder mypy should still show errors in these packages when imported, because of the follow imports logic. However, if I set the PYTHONPATH to the current working directory, it does not show these errors anymore.

To Reproduce
Here is the folder structure:

src/
|--excluded_folder/
|           |-- excluded.py
|           |-- __init__.py
|--included_folder/
            |-- included.py
            |-- __init__.py

The contents of the file excluded.py are as follows:

def function() -> str:  # obviously wrong return type
        return 5

File included.py looks like so:

from excluded_folder.excluded import function

print(function)

Now, if i run mypy like so, with the setting to exclude the excluded folder, it reports this:

$ mypy --strict --exclude excluded_folder src                          
src/excluded_folder/excluded.py:3: error: Incompatible return value type (got "int", expected "str")  [return-value]
Found 1 error in 1 file (checked 2 source files)

This is what i would expect. It still shows the errors in the file, although excluded.

But if i run mypy with PYTHONPATH set to the current working directory, it does not show any error anymore:

% PYTHONPATH=. mypy --strict --exclude excluded_folder src
Success: no issues found in 2 source files

Expected Behavior
Mypy should also show the errors when the PYTHONPATH is set.

Actual Behavior
Mypy does not show the errors when the PYTHONPATH is set.

Your Environment

  • Mypy version used: mypy 1.8.0 (compiled: yes)
  • Mypy command-line flags: see commands above
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: Python 3.11.3
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
54

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.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

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.