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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy