diff --git a/README.md b/README.md index 5de6f613..3a507b6e 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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: +``` diff --git a/pyupgrade/_main.py b/pyupgrade/_main.py index ca1542fb..d8e359dc 100644 --- a/pyupgrade/_main.py +++ b/pyupgrade/_main.py @@ -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 diff --git a/pyupgrade/_plugins/typing_pep563.py b/pyupgrade/_plugins/typing_pep563.py index 33c05ab0..e16da37a 100644 --- a/pyupgrade/_plugins/typing_pep563.py +++ b/pyupgrade/_plugins/typing_pep563.py @@ -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__'] ) diff --git a/tests/features/typing_pep563_test.py b/tests/features/typing_pep563_test.py index 1196d0c3..e7b82d93 100644 --- a/tests/features/typing_pep563_test.py +++ b/tests/features/typing_pep563_test.py @@ -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' @@ -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',