Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

using inspect.unwrap on `maurix.types.Obj` places the object into a state where serializing raises a RecursionError

Đang mở
#176 1 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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/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
backend

Hướng nghiên cứu

Bắt đầu tại mautrix/types/util/obj.py, đặc biệt là getattr và serialize(), rồi tái hiện ví dụ inspect.unwrap(mautrix.types.Obj()) từ issue. Kiểm tra để bảo đảm các tên dunder hoặc sunder không tồn tại không được tạo động, trong khi các thuộc tính thông thường không tồn tại vẫn giữ nguyên hành vi hiện có. Hoàn tất khi ví dụ không còn khiến đối tượng có thể được serialize đệ quy và chỉ phát sinh lỗi unwrap như mong đợi.

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

Mô tả

bug
>>> import mautrix.types
>>> import inspect
>>> inspect.unwrap(mautrix.types.Obj())
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    inspect.unwrap(mautrix.types.Obj())
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/lily/.pyenv/versions/3.13.2/lib/python3.13/inspect.py", line 791, in unwrap
    raise ValueError('wrapper loop when unwrapping {!r}'.format(f))
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 36, in __repr__
    return repr(self.serialize())
                ~~~~~~~~~~~~~~^^
  File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 62, in serialize
    k: v.serialize() if isinstance(v, Serializable) else v
       ~~~~~~~~~~~^^
  File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 62, in serialize
    k: v.serialize() if isinstance(v, Serializable) else v
       ~~~~~~~~~~~^^
  File "/home/lily/Documents/matrix-codecrimes/.venv/lib/python3.13/site-packages/mautrix/types/util/obj.py", line 62, in serialize
    k: v.serialize() if isinstance(v, Serializable) else v
       ~~~~~~~~~~~^^
  [Previous line repeated 986 more times]
RecursionError: maximum recursion depth exceeded

this appears to be caused because inspect.wrapper attempts to access .__wrapped__ which causes the __getattr__ to create it, which is bad.

maybe it would be a good idea not to create __dunder__ and _sunder_ names? so something like:

def __getattr__(self, name):
    if name.startswith("_") and name.endswith("_"):
        raise AttributeError(name)
    ...

just to prevent brainfarts: this wont prevent access to defined dunders since __getattr__ is only called when the name cannot be found through other means.

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

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 mautrix/python

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

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.