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

[FR] MissionDonation 클래스에 nickname, user_id, totalPayAmount 등 추가 #37

Closed
ywj515 opened this issue Jan 9, 2025 · 3 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@ywj515
Copy link

ywj515 commented Jan 9, 2025

미션 발생 시 데이터에 nickname, user_id, totalPayAmount 등이 포함되어 있으나
클래스에서 접근할 수 없는 문제가 있습니다.
더 많은 데이터를 사용할 수 있도록 추가 부탁드립니다.

@ywj515 ywj515 added the enhancement New feature or request label Jan 9, 2025
@gunyu1019
Copy link
Owner

chzzkpy에서 구성되는 데이터클래스는 chzzkpy.BaseModel.ModelConfig 에 따라 구성되었습니다.
BaseModel의 구성되는 값은 아래와 같습니다.

class ChzzkModel(BaseModel):
    model_config = ConfigDict(
        alias_generator=to_camel,
        frozen=True,
       extra=Extra.allow  # Extra enumeration had deprecated.
    )
    ...

pydantic의 공식문서에 따르면 ModelConfig에 extra 값을 "allow"로 설정하면, 정의된 Attribute(구성)외에 추가적인 데이터가 들어왔을 때에도 접근할 수 있도록 설정할 수 있습니다.

예를 들면 다음과 같습니다.

MissionDonation 데이터 클래스에는 totalPayAmount의 속성이 사전에 정의되어 있지 않습니다.
다만, 웹소켓에서 응답받은 값에 포함되어 있을 경우 아래와 같이 사용할 수 있습니다.

MissionDonation.total_pay_amount
추가로 model_dump를 통해 dictionary 값을 불러온다면, total_pay_amount 키가 있는 것을 확인하실 수 있습니다.

totalPayAmount가 아닌 total_pay_amount인 이유는 PEP8 규칙에 따르면, Attribute(속성)의 이름은 반드시 lower case로 정의되어야 하기 때문입니다. 따라서, alias_generator를 통해서 camel case로 정의된 속성 이름을 lower_case에 따르도록 수정됩니다.

누락된 속성에 대해서는 데이터클래스에 추가함으로서, 적절하게 대응할 예정입니다.
다만 클래스에서 접근을 할 수 없는 문제는 아닙니다.

@gunyu1019 gunyu1019 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2025
@gunyu1019 gunyu1019 added the wontfix This will not be worked on label Jan 10, 2025
gunyu1019 added a commit that referenced this issue Jan 10, 2025
@gunyu1019
Copy link
Owner

말씀하신 속성(Attribute)에 대해서는 MissionDonation 데이터클래스에 추가하였습니다.
예제 데이터가 부족한 이상 누락된 속성(Attribute)가 있을 수도 있습니다.

@ywj515
Copy link
Author

ywj515 commented Jan 10, 2025

자세한 답변 감사합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants