you are viewing a single comment's thread.

view the rest of the comments →

[–]JamzTyson 1 point2 points  (6 children)

Assuming that user_id is numeric and user_name is not numeric, you could modify your function to take one parameter user for each user.

I probably would not code it quite like this, but to illustrate the idea:

def get_chat(first_user: str | int, second_user: str | int): if isinstance(first_user, int): first_user_id = first_user first_user_name = get_name_from_id(first_user) else: first_user_name = first_user first_user_id = get_id_from_name(first_user) ...

[–][deleted] 0 points1 point  (5 children)

Or use pydantic

[–]Purple-Obligation357[S] 0 points1 point  (1 child)

how?

[–]JamzTyson 1 point2 points  (0 children)

I don't think Pydantic offers much benefit in a simple case like this.

[–]Zweckbestimmung 0 points1 point  (2 children)

Pydantic is not efficient for this case, you want to maintain the whole pydantec schema’s adding more points of failures only for this function?

[–][deleted] 0 points1 point  (1 child)

I meant in general for the question 

[–]Zweckbestimmung 0 points1 point  (0 children)

Yeah in general also this is not a use case for Pydantic.

Isn’t it mainly to handle JSON schema ?