swansonk14 / typed-argument-parser

Typed argument parser for Python
MIT License
494 stars 40 forks source link

tapify help string order is random #121

Closed swansonk14 closed 10 months ago

swansonk14 commented 10 months ago

When tapify is used and run with -h, the arguments are printed in a random order. They should be printed in the same order as they are listed in the function or class (or docstring).

martinjm97 commented 10 months ago

Hi @swansonk14,

The help string order was deterministic in tapify.

However, some of your code returned a subclass of Tap that included the annotations information. Instantiating that class resulted in a help string with arguments that were randomly ordered. The randomness came from the unioning of dictionary keys, which downcasts the ordered data structure dict_keys data structure to an unordered set.

Instead, we now merge the dictionaries and then extract the keys. You can see the before and after here: https://github.com/swansonk14/typed-argument-parser/commit/70137fd810e715c1ae30c32e8c2ff5cd5f77aa98.

In the future, this means that we can incorporate code that separates out the creation of a subclass of Tap from its instantiation. This is useful when creating a large Tap comprising multiple other Tap objects added via add_parser.

--JK