python / python/cpython

configparser: BasicInterpolation raises TypeError interpolating a value-less option

Đang mở
#153,855 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.

stdlib type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug report

Bug description:

With allow_no_value=True and the default BasicInterpolation, interpolating a reference to a value-less option raises TypeError instead of resolving or raising a configparser error. ExtendedInterpolation treats the missing value as empty in the same situation.

import configparser
cfg = configparser.ConfigParser(allow_no_value=True)
cfg.read_string("[s]\na\nb = x%(a)sy\n")
cfg.get("s", "b")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    cfg.get("s", "b")
    ~~~~~~~^^^^^^^^^^
  File "../Lib/configparser.py", line 855, in get
    return self._interpolation.before_get(self, section, option, value,
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                          d)
                                          ^^
  File "../Lib/configparser.py", line 433, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "../Lib/configparser.py", line 474, in _interpolate_some
    if "%" in v:
      ^^^^^^^^
TypeError: argument of type 'NoneType' is not a container or iterable

The same pattern with ExtendedInterpolation (b = x${s:a}y) returns "xy".

ExtendedInterpolation._interpolate_some guards this (if v is None: continue, added in gh-130941); BasicInterpolation._interpolate_some does not and reaches if "%" in v: with v set to None (Lib/configparser.py).

Observed on 3.16.0a0.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-153857

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 tại Lib/configparser.py, trong BasicInterpolation._interpolate_some, và so sánh cách xử lý của nó với ExtendedInterpolation._interpolate_some, như được mô tả trong báo cáo. Xác nhận rằng trường hợp tùy chọn không có giá trị không còn gây ra TypeError và tuân theo hành vi nội suy dự kiến; PR được liên kết gh-153857 cho biết công việc đã được tiến hành.

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
backend
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
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
25/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.