|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from pyupgrade._data import Settings |
| 6 | +from pyupgrade._main import _fix_plugins |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.parametrize( |
| 10 | + ('s',), |
| 11 | + ( |
| 12 | + pytest.param( |
| 13 | + 'from typing import Unpack\n' |
| 14 | + 'foo(Unpack())', |
| 15 | + id='Not a subscript', |
| 16 | + ), |
| 17 | + pytest.param( |
| 18 | + 'from typing import TypeVarTuple, Unpack\n' |
| 19 | + 'Shape = TypeVarTuple("Shape")\n' |
| 20 | + 'class Foo(Unpack[Shape]):\n' |
| 21 | + ' pass', |
| 22 | + id='Not inside a subscript', |
| 23 | + ), |
| 24 | + ), |
| 25 | +) |
| 26 | +def test_fix_pep646_noop(s): |
| 27 | + assert _fix_plugins(s, settings=Settings(min_version=(3, 11))) == s |
| 28 | + assert _fix_plugins(s, settings=Settings(min_version=(3, 10))) == s |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.parametrize( |
| 32 | + ('s', 'expected'), |
| 33 | + ( |
| 34 | + ( |
| 35 | + 'from typing import Generic, TypeVarTuple, Unpack\n' |
| 36 | + "Shape = TypeVarTuple('Shape')\n" |
| 37 | + 'class C(Generic[Unpack[Shape]]):\n' |
| 38 | + ' pass', |
| 39 | +
|
| 40 | + 'from typing import Generic, TypeVarTuple, Unpack\n' |
| 41 | + "Shape = TypeVarTuple('Shape')\n" |
| 42 | + 'class C(Generic[*Shape]):\n' |
| 43 | + ' pass', |
| 44 | + ), |
| 45 | + ( |
| 46 | + 'from typing import Generic, TypeVarTuple, Unpack\n' |
| 47 | + "Shape = TypeVarTuple('Shape')\n" |
| 48 | + 'class C(Generic[Unpack [Shape]]):\n' |
| 49 | + ' pass', |
| 50 | +
|
| 51 | + 'from typing import Generic, TypeVarTuple, Unpack\n' |
| 52 | + "Shape = TypeVarTuple('Shape')\n" |
| 53 | + 'class C(Generic[*Shape]):\n' |
| 54 | + ' pass', |
| 55 | + ), |
| 56 | + ), |
| 57 | +) |
| 58 | +def test_typing_unpack(s, expected): |
| 59 | + assert _fix_plugins(s, settings=Settings(min_version=(3, 11))) == expected |
| 60 | + assert _fix_plugins(s, settings=Settings(min_version=(3, 10))) == s |
0 commit comments