Skip to content

Simplify Handling of empty data in TO.de_json #4614

@Bibo-Joshi

Description

@Bibo-Joshi

We currenty have clauses like

if data is None:
return None

and

if not data:
return ()

These sometimes make difficulties for classes that have no required arguments such that {} is valid input for de_json. Moreover, classes with subclasses (BotCommandScope & sim), where de_json calls the de_json method of a subclass, need to take care of this as well.

AFAIK the main use case for the emtyp-data handling is calling other classes de_json. E.g. Update.de_json calls

data["message"] = Message.de_json(data.get("message"), bot)

and data.get("message") might be None.

Neither TO.de_json nor TO.de_list documents how empty data ({}) or None is handled. Note that the type hints do give something away, but they are explicitly excluded from our stability policy.

To simplify internal logic, I propose to

  • switch to uniform if data is None: return None
  • optionally even remove that and think of a clean way to handle the Message.de_json(data.get("message"), bot) case

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions