Version-gated early exits: `from copy import replace` is accepted but `copy.replace` is rejected

Đang mở
#5,593 0 bình luận 1 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
30/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, rust
Lĩnh vực
devtools

Hướng nghiên cứu

The repro is self-contained: with python_version 3.10, a sys.version_info < (3, 13) guard suppresses the error when the call sits in an else branch but not when the guard exits early via return. Start by finding where pyrefly applies version-gated narrowing to sys.version_info comparisons, likely in the binding/narrowing code under the type-checker crate, and compare how the early-return path and the else path propagate the refined flow. Done means both via_attribute and via_else from the report produce no missing-attribute, with a regression test covering the early-return form.

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

Mô tả

quansight scoping-control-flow
Describe the Bug

with python_version 3.10

import copy
import sys




def via_attribute(x: object) -> object:
    if sys.version_info < (3, 13):
        return x
    return copy.replace(x)  # No attribute `replace` in module `copy` [missing-attribute]


def via_else(x: object) -> object:
    if sys.version_info < (3, 13):
        return x
    else:
        return copy.replace(x)  # OK
ERROR sandbox.py:10:12-24: No attribute `replace` in module `copy` [[missing-attribute](https://pyrefly.org/en/docs/error-kinds/#missing-attribute)]
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.rZTPDoIwDMZfpQkHNBEWw834Bh70rombMnGJMMIGgbe3-yMGFC4aTmxt-Wh__aYss1_dshuvoXvMjBvBzkzrSlxqzRftNOg4XUyOfWdQ6k3CFhbJCtbJF-Ra33r3ZjTEFS8fDFFtlwABIgX9d4H6O2p4yGVa49ypSaJwzIVCzLOoj7Y-8FZviP6_8PGeTP7HfvdJUQAHdwB-IJiI-GU1ujRqiE9FgAbN4a51qTaEvNJllRFekFReFRlkEDALwxomrPcPy4G01Css-wu-oaM3nIM3NOzaiIgVHQbZruC5LY4Xs6A-AQ

(Only applicable for extension issues) IDE Information

No response

Ngôn ngữ chính
Rust
Star
7.2k
Fork
578
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

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 facebook/pyrefly

Tất cả issue của facebook/pyrefly

Issue tương tự

Thêm issue về Rust

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.