Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3ae57b

Browse files
Fix --target-version flag for unit tests. (psf#4722)
1 parent 3a96e06 commit b3ae57b

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# flags: --minimum-version=3.12 --target-version=py312
2+
# this is invalid in versions below py312
3+
class ClassA[T: str]:
4+
def method1(self) -> T:
5+
...
6+
7+
# output
8+
# this is invalid in versions below py312
9+
class ClassA[T: str]:
10+
def method1(self) -> T: ...

tests/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def get_flags_parser() -> argparse.ArgumentParser:
236236
parser = argparse.ArgumentParser()
237237
parser.add_argument(
238238
"--target-version",
239-
action="append",
240-
type=lambda val: TargetVersion[val.upper()],
239+
action="store",
240+
type=lambda val: (TargetVersion[val.upper()],),
241241
default=(),
242242
)
243243
parser.add_argument("--line-length", default=DEFAULT_LINE_LENGTH, type=int)
@@ -258,7 +258,7 @@ def get_flags_parser() -> argparse.ArgumentParser:
258258
default=None,
259259
help=(
260260
"Minimum version of Python where this test case is parseable. If this is"
261-
" set, the test case will be run twice: once with the specified"
261+
" set, the test case will be run twice: once without the specified"
262262
" --target-version, and once with --target-version set to exactly the"
263263
" specified version. This ensures that Black's autodetection of the target"
264264
" version works correctly."

0 commit comments

Comments
 (0)