Skip to content

Commit 2de44c4

Browse files
committed
config: remove unnecessary code from Argument
The `processopt` callback currently doesn't update any fields, so this code is not needed. And since we definitely do not want to extend the use of `processopt`, it's fine to remove.
1 parent 88ec0d1 commit 2de44c4

File tree

2 files changed

+0
-32
lines changed

2 files changed

+0
-32
lines changed

src/_pytest/config/argparsing.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,6 @@ def names(self) -> list[str]:
335335
return self._short_opts + self._long_opts
336336

337337
def attrs(self) -> Mapping[str, Any]:
338-
# Update any attributes set by processopt.
339-
for attr in ("default", "dest", "help", self.dest):
340-
try:
341-
self._attrs[attr] = getattr(self, attr)
342-
except AttributeError:
343-
pass
344338
return self._attrs
345339

346340
def _set_opt_strings(self, opts: Sequence[str]) -> None:

testing/test_parseopt.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ def test_argument_type(self) -> None:
6363
)
6464
assert argument.type is str
6565

66-
def test_argument_processopt(self) -> None:
67-
argument = parseopt.Argument("-t", type=int)
68-
argument.default = 42
69-
argument.dest = "abc"
70-
res = argument.attrs()
71-
assert res["default"] == 42
72-
assert res["dest"] == "abc"
73-
7466
def test_group_add_and_get(self, parser: parseopt.Parser) -> None:
7567
group = parser.getgroup("hello")
7668
assert group.name == "hello"
@@ -191,24 +183,6 @@ def test_parse_split_positional_arguments(self, parser: parseopt.Parser) -> None
191183
assert args.R is True
192184
assert args.S is False
193185

194-
def test_parse_defaultgetter(self) -> None:
195-
def defaultget(option):
196-
if not hasattr(option, "type"):
197-
return
198-
if option.type is int:
199-
option.default = 42
200-
elif option.type is str:
201-
option.default = "world"
202-
203-
parser = parseopt.Parser(processopt=defaultget, _ispytest=True)
204-
parser.addoption("--this", dest="this", type=int, action="store")
205-
parser.addoption("--hello", dest="hello", type=str, action="store")
206-
parser.addoption("--no", dest="no", action="store_true")
207-
option = parser.parse([])
208-
assert option.hello == "world"
209-
assert option.this == 42
210-
assert option.no is False
211-
212186
def test_drop_short_helper(self) -> None:
213187
parser = argparse.ArgumentParser(
214188
formatter_class=parseopt.DropShorterLongHelpFormatter, allow_abbrev=False

0 commit comments

Comments
 (0)