Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageSegment 加法會使變量被改變 #51

Open
cleoold opened this issue Apr 29, 2021 · 2 comments
Open

MessageSegment 加法會使變量被改變 #51

cleoold opened this issue Apr 29, 2021 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@cleoold
Copy link
Member

cleoold commented Apr 29, 2021

问题描述
title

复现方法
Paste code below

期望的行为

日志信息
...

相关代码

In [19]: msg1=MessageSegment.text('seg1')

In [20]: msg2=MessageSegment.text('seg2')

In [21]: msg1 + msg2
Out[21]: [{'type': 'text', 'data': {'text': 'seg1seg2'}}]

In [22]: msg1
Out[22]: {'type': 'text', 'data': {'text': 'seg1seg2'}}  # changed

In [23]: msg2
Out[23]: {'type': 'text', 'data': {'text': 'seg2'}}

In [24]:

运行环境

  • aiocqhttp 版本:master
  • Python 版本:3.7

MessageSegment 因爲繼承了 dict,所以是可變類型。不過對於這個問題還要討論,歡迎給出建議。

@stdrc
Copy link
Member

stdrc commented Apr 29, 2021

居然还有这问题

似乎应该在 Message.__init__ 里面 extendappend 的时候做深拷贝

@stdrc
Copy link
Member

stdrc commented Apr 29, 2021

主要问题在于 Message.reduce 会合并 text 消息段,而 MessageSegment 又直接 append 到了 Message 的里,没有拷贝

@stdrc stdrc mentioned this issue Apr 29, 2021
@cleoold cleoold added the help wanted Extra attention is needed label Sep 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Development

No branches or pull requests

2 participants