python / python/mypy

bug: strict = true is incompatible with per-module configuration

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

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

bug topic-configuration
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ả

To Reproduce

Create the following file structure:

my_module/__init__.py
tests/__init__.py
mypy.ini

Both my_module/__init__.py and tests/__init__.py contain:

def untyped():
    ...

Which should trigger an error when run with strict but otherwise pass.

In mypy.ini:

[mypy]
strict = true
[mypy-tests.*]
strict = false

That is, I want strict mode in my source code but not my tests.

Then I run this using mypy .

Expected Behavior

I expect to get an error for my source code but not my tests:

my_module/__init__.py:1: error: Function is missing a return type annotation
my_module/__init__.py:1: note: Use "-> None" if function does not return a value

Actual Behavior

I get an error for both my source code and tests.
It seems like strict = False in the per module section is ignored.

tests/__init__.py:1: error: Function is missing a return type annotation
tests/__init__.py:1: note: Use "-> None" if function does not return a value
my_module/__init__.py:1: error: Function is missing a return type annotation
my_module/__init__.py:1: note: Use "-> None" if function does not return a value

If I add an explicit allow_untyped_defs = True to the mypy-tests.* section:

[mypy]
strict = true
[mypy-tests.*]
strict = false
allow_untyped_defs = True

That seems to be processed fine (I now get no errors for my tests but still get errors for my source).
So I believe the config file is valid, mypy is picking up that the options only apply to tests.*.

I also tried flipping the enable/disable:

[mypy]
strict = false
[mypy-my_module.*]
strict = true

But I get the same result.

This also seems to be the case with pyproject.toml configs.

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

Tái hiện vấn đề với các cấu hình mypy.ini và pyproject.toml được cung cấp, sau đó theo dõi cách các tùy chọn strict và theo từng module được xử lý khi chạy mypy . Công việc được xem là hoàn tất khi strict áp dụng cho my_module.* trong khi tests.* chấp nhận các định nghĩa không có kiểu trong cả hai định dạng cấu hình được hỗ trợ.

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
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/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.