argparsing: remove "map_long_option" Action attribute support
This feature was added in commit
007a77c2ba, but was never used in pytest
itself. A GitHub code search doesn't find any users either (only pytest
repo copies). It seems safe to clean up.
			
			
This commit is contained in:
		
							parent
							
								
									5b3867fd65
								
							
						
					
					
						commit
						51f9cd0e02
					
				| 
						 | 
					@ -409,8 +409,6 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
 | 
				
			||||||
    """shorten help for long options that differ only in extra hyphens
 | 
					    """shorten help for long options that differ only in extra hyphens
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    - collapse **long** options that are the same except for extra hyphens
 | 
					    - collapse **long** options that are the same except for extra hyphens
 | 
				
			||||||
    - special action attribute map_long_option allows suppressing additional
 | 
					 | 
				
			||||||
      long options
 | 
					 | 
				
			||||||
    - shortcut if there are only two options and one of them is a short one
 | 
					    - shortcut if there are only two options and one of them is a short one
 | 
				
			||||||
    - cache result on action object as this is called at least 2 times
 | 
					    - cache result on action object as this is called at least 2 times
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					@ -434,9 +432,6 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
 | 
				
			||||||
            action._formatted_action_invocation = orgstr
 | 
					            action._formatted_action_invocation = orgstr
 | 
				
			||||||
            return orgstr
 | 
					            return orgstr
 | 
				
			||||||
        return_list = []
 | 
					        return_list = []
 | 
				
			||||||
        option_map = getattr(action, "map_long_option", {})
 | 
					 | 
				
			||||||
        if option_map is None:
 | 
					 | 
				
			||||||
            option_map = {}
 | 
					 | 
				
			||||||
        short_long = {}  # type: Dict[str, str]
 | 
					        short_long = {}  # type: Dict[str, str]
 | 
				
			||||||
        for option in options:
 | 
					        for option in options:
 | 
				
			||||||
            if len(option) == 2 or option[2] == " ":
 | 
					            if len(option) == 2 or option[2] == " ":
 | 
				
			||||||
| 
						 | 
					@ -446,7 +441,6 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
 | 
				
			||||||
                    'long optional argument without "--": [%s]' % (option), self
 | 
					                    'long optional argument without "--": [%s]' % (option), self
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            xxoption = option[2:]
 | 
					            xxoption = option[2:]
 | 
				
			||||||
            if xxoption.split()[0] not in option_map:
 | 
					 | 
				
			||||||
            shortened = xxoption.replace("-", "")
 | 
					            shortened = xxoption.replace("-", "")
 | 
				
			||||||
            if shortened not in short_long or len(short_long[shortened]) < len(
 | 
					            if shortened not in short_long or len(short_long[shortened]) < len(
 | 
				
			||||||
                xxoption
 | 
					                xxoption
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -205,11 +205,11 @@ class TestParser:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        parser.add_argument(
 | 
					        parser.add_argument(
 | 
				
			||||||
            "-t", "--twoword", "--duo", "--two-word", "--two", help="foo"
 | 
					            "-t", "--twoword", "--duo", "--two-word", "--two", help="foo"
 | 
				
			||||||
        ).map_long_option = {"two": "two-word"}
 | 
					        )
 | 
				
			||||||
        # throws error on --deux only!
 | 
					        # throws error on --deux only!
 | 
				
			||||||
        parser.add_argument(
 | 
					        parser.add_argument(
 | 
				
			||||||
            "-d", "--deuxmots", "--deux-mots", action="store_true", help="foo"
 | 
					            "-d", "--deuxmots", "--deux-mots", action="store_true", help="foo"
 | 
				
			||||||
        ).map_long_option = {"deux": "deux-mots"}
 | 
					        )
 | 
				
			||||||
        parser.add_argument("-s", action="store_true", help="single short")
 | 
					        parser.add_argument("-s", action="store_true", help="single short")
 | 
				
			||||||
        parser.add_argument("--abc", "-a", action="store_true", help="bar")
 | 
					        parser.add_argument("--abc", "-a", action="store_true", help="bar")
 | 
				
			||||||
        parser.add_argument("--klm", "-k", "--kl-m", action="store_true", help="bar")
 | 
					        parser.add_argument("--klm", "-k", "--kl-m", action="store_true", help="bar")
 | 
				
			||||||
| 
						 | 
					@ -221,7 +221,7 @@ class TestParser:
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        parser.add_argument(
 | 
					        parser.add_argument(
 | 
				
			||||||
            "-x", "--exit-on-first", "--exitfirst", action="store_true", help="spam"
 | 
					            "-x", "--exit-on-first", "--exitfirst", action="store_true", help="spam"
 | 
				
			||||||
        ).map_long_option = {"exitfirst": "exit-on-first"}
 | 
					        )
 | 
				
			||||||
        parser.add_argument("files_and_dirs", nargs="*")
 | 
					        parser.add_argument("files_and_dirs", nargs="*")
 | 
				
			||||||
        args = parser.parse_args(["-k", "--duo", "hallo", "--exitfirst"])
 | 
					        args = parser.parse_args(["-k", "--duo", "hallo", "--exitfirst"])
 | 
				
			||||||
        assert args.twoword == "hallo"
 | 
					        assert args.twoword == "hallo"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue