GH:624 - added mode keyword to DataFrame.to_json by ramvikrams · Pull Request #684 · pandas-dev/pandas-stubs (original) (raw)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit tricky. You have to put the 2 overloads for orient = Literal["records"] first, but without the "= ..." . The first two overloads would then have lines: Literal[True] and mode: Literal["a"] . This may need an * in the right places (see DataFrame.to_dict() for an example). Then you add another pair of overloads with orient: Literal["records"] and lines: Literal[False] = ..., mode: Literal["w"] = .... Then you have the 2 overloads that are there where mode: Literal["w"] = ... is allowed.

You also have to fix the overloads in series.pyi.

For the tests, you should test the valid and invalid combinations, using TYPE_CHECKING_INVALID_USAGE for the invalid ones, with appropriate ignore statements.