Skip to content

Commit

Permalink
move pep563 rewrite to py311
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Apr 20, 2021
1 parent 4502861 commit 55fa535
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,18 +506,6 @@ Availability:
```


### remove quoted annotations

Availability:
- File imports `from __future__ import annotations`
- `--py310-plus` is passed on the commandline.

```diff
-def f(x: 'queue.Queue[int]') -> C:
+def f(x: queue.Queue[int]) -> C:
```


### pep 604 typing rewrites

Availability:
Expand All @@ -536,3 +524,15 @@ Availability:
+def f() -> int | str:
...
```


### remove quoted annotations

Availability:
- File imports `from __future__ import annotations`
- `--py311-plus` is passed on the commandline.

```diff
-def f(x: 'queue.Queue[int]') -> C:
+def f(x: queue.Queue[int]) -> C:
```
4 changes: 4 additions & 0 deletions pyupgrade/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,10 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
'--py310-plus',
action='store_const', dest='min_version', const=(3, 10),
)
parser.add_argument(
'--py311-plus',
action='store_const', dest='min_version', const=(3, 11),
)
args = parser.parse_args(argv)

ret = 0
Expand Down
2 changes: 1 addition & 1 deletion pyupgrade/_plugins/typing_pep563.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def _supported_version(state: State) -> bool:
return (
state.settings.min_version >= (3, 10) or
state.settings.min_version >= (3, 11) or
'annotations' in state.from_imports['__future__']
)

Expand Down
7 changes: 6 additions & 1 deletion tests/features/typing_pep563_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'from typing import Literal\n'
'x: "str"\n',
(2, 7),
id='not python 3.10+',
id='not python 3.11+',
),
pytest.param(
'from __future__ import annotations\n'
Expand Down Expand Up @@ -346,6 +346,11 @@ def test_fix_typing_pep563(s, expected):
assert ret == expected


def test_replaced_for_minimum_version():
ret = _fix_plugins('x: "int"', settings=Settings(min_version=(3, 11)))
assert ret == 'x: int'


@pytest.mark.xfail(
sys.version_info < (3, 8),
reason='posonly args not available in Python3.7',
Expand Down

0 comments on commit 55fa535

Please sign in to comment.