HuangFuSL / Werewolf

The final project of Computer Network in 2020A
MIT License
1 stars 3 forks source link

关于client_subthread.py文件 #9

Closed HuangFuSL closed 3 years ago

HuangFuSL commented 3 years ago

client_subthread.py文件中出现了如下形式的代码:

def comPack2(seat) -> ChunckedData:
    """
    compress the return packet of -1,
    whose packetType number is 2
    """
    ret = ChunckedData(2, chosenSeat=seat)
    return ret

我看不出来把构造函数再wrap一层的必要性,而且如果真的要写成函数,用lambda表达式似乎更好

comPack2 = lambda seat : ChunckedData(2, chosenSeat=seat)

这个函数在程序的这个地方调用:

    if (type == -1):
        """
        -1是服务器发出的建立连接的信息
        """
        print("%d seat(s) remained and the seats you can choose are :" %
              (ret.content['playerRemaining']))
        for x in ret.content['playerSeats']:
            print(x, end=' ')
        print("Please enter the number of seat you choose: ")
        chosenSeat = input()

        return comPack2(chosenSeat)

既然只是return comPack2(chosenSeat),代码里又没有对这些东西做额外的操作,为什么不直接return新对象呢?

return ChunckedData(2, chosenSeat=chosenSeat)
HuangFuSL commented 3 years ago

以及 不要再出现函数后面不加冒号的情况了。。。