leotrs opened a new issue, #28430: URL: https://github.com/apache/beam/issues/28430
### What would you like to happen? Each instance of `PipelineOptions` contains a member called `parser`, which in turn is an instance of `_BeamArgumentParser` (which is a subclass of stdlib's `ArgumentParser`). Currently there is no way to affect the initialization of `parser`, as its class is hard-coded. For example, I wanted to change the way that `parser` resolves conflicting CLI options. As per [official docs](https://docs.python.org/3/library/argparse.html#conflict-handler), this is done by supplying the argument `conflict_handler=...` to the `ArgumentParser` constructor. Since there is no way for the user to affect the initialization of `parser`, this cannot currently be done. Changing `conflict_handler` after initialization, e.g. by doing `options.parser.conflict_handler = ...`, does not work since `PipelineOptions` objects may create other parser objects down the road, and CLI options are generally processed multiple times, so there is no guarantee that one is changing the `conflict_handler` *before* any options are processed. A simple solution would be to abstract out the class of `parser`: ```python3 class PipelineOptions(...): parserclass = _BeamArgumentParser def __init__(self, ...): parser = self.parserclass() ... ``` In this way, the user may subclass `_BeamArgumentParser` in order to affect any initialization behavior: ```python3 class MyAwesomeArgumentParser(_BeamArgumentParser): def __init__(self, *args, **kwargs): super().__init__(conflict_handler="resolve", *args, **kwargs) PipelineOptions.parserclass = MyAwesomeArgumentParser ``` ### Issue Priority Priority: 3 (nice-to-have improvement) ### Issue Components - [X] Component: Python SDK - [ ] Component: Java SDK - [ ] Component: Go SDK - [ ] Component: Typescript SDK - [ ] Component: IO connector - [ ] Component: Beam examples - [ ] Component: Beam playground - [ ] Component: Beam katas - [ ] Component: Website - [ ] Component: Spark Runner - [ ] Component: Flink Runner - [ ] Component: Samza Runner - [ ] Component: Twister2 Runner - [ ] Component: Hazelcast Jet Runner - [ ] Component: Google Cloud Dataflow Runner -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
