python / python/mypy

Semantic analyzer confuses a function with a module

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

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

bug false-positive priority-0-high semantic-analyzer
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ả

The following code creates a package structure that demonstrates what I think is a bug in mypy's new semantic analyzer.

from os import makedirs

makedirs('src/core')
makedirs('src/stuff')

open('src/__init__.py', 'w').write("""
# nothing here
""")

open('src/core/__init__.py', 'w').write("""
from .run import config
""")

open('src/core/run.py', 'w').write("""
from ..stuff import somefunction

config = None

somefunction()
""")

open('src/stuff/__init__.py', 'w').write("""
from .somemore import more
from .somefunction import somefunction
""")

open('src/stuff/somefunction.py', 'w').write("""
def somefunction():
    print("Hello, World!")
""")

open('src/stuff/somemore.py', 'w').write("""
def more():
    from ..core import config
""")

When checking the created src package with mypy 0.720 and Python 3.7, I get the following error:

src/core/run.py:6: error: Module not callable

What mypy thinks is a module is actually a function. It just has the same name as its containing module.

When I check with --no-new-semantic-analyzer, I do not get this error.

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ạo lại gói src được sinh từ nội dung issue và chạy mypy 0.720 có và không có --no-new-semantic-analyzer, tập trung vào src/core/run.py và src/stuff/somefunction.py. Truy tìm lý do somefunction được phân giải thành một module thay vì một hàm có thể gọi; hoàn tất khi semantic analyzer mới chấp nhận lời gọi và hành vi này được bao phủ bởi một regression test.

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
compilers
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
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.