Skip to content

Support py38-style starred expressions in return statement#1121

Merged
JelleZijlstra merged 5 commits intopsf:masterfrom
vemel:py38-star-return
Jan 18, 2020
Merged

Support py38-style starred expressions in return statement#1121
JelleZijlstra merged 5 commits intopsf:masterfrom
vemel:py38-star-return

Conversation

@vemel
Copy link
Contributor

@vemel vemel commented Oct 30, 2019

Goal

#1091

Support py38 starred expressions in return and yield statements. Bug description

def starred_return():
    my_list = ["value2", "value3"]
    return "value1", *my_list

Investigation

Event the newest plib2to3 grammar does not support starred expressions in return statements, so switching to a new version will not solve the issue.

The idea is to use return_stmt: 'return' [testlist_star_expr] in Grammar.txt to support both old and new return statements.

Changes

  • Accept starred expressions in return_stmt
  • Accept starred expressions in yield_stmt
  • Add test test_python38

Not done

  • I did not add it as a new Feature so it does not require --target-version=py38, as it is more of a bug

@vemel
Copy link
Contributor Author

vemel commented Oct 30, 2019

Fixed flake8 warning.

@JelleZijlstra JelleZijlstra merged commit be49ac7 into psf:master Jan 18, 2020
blueyed added a commit to blueyed/pytest that referenced this pull request Jan 23, 2020
Note: black cannot parse `return *active_fixture_argnames,
*self.argnames` yet (fixed in master, psf/black#1121).

Tested manually using:
```python
@pytest.fixture(scope="session")
def xdist_suffix(request):
    print("\nxdist_suffix")
    suffixes.append("xdist")

@pytest.fixture(scope="session")
def parallel_suffix(tox_suffix, xdist_suffix):
    pass

def test_suffix(parallel_suffix):
    assert suffixes == ["tox", "xdist"]
```

When using a set there the order is not deterministic, i.e. the test is
flaky.
blueyed added a commit to blueyed/pytest that referenced this pull request Jan 25, 2020
Note: black cannot parse `return *active_fixture_argnames,
*self.argnames` yet (fixed in master, psf/black#1121).

Tested manually using:
```python
@pytest.fixture(scope="session")
def xdist_suffix(request):
    print("\nxdist_suffix")
    suffixes.append("xdist")

@pytest.fixture(scope="session")
def parallel_suffix(tox_suffix, xdist_suffix):
    pass

def test_suffix(parallel_suffix):
    assert suffixes == ["tox", "xdist"]
```

When using a set there the order is not deterministic, i.e. the test is
flaky.
blueyed added a commit to blueyed/pytest that referenced this pull request Mar 9, 2020
Note: black cannot parse `return *active_fixture_argnames,
*self.argnames` yet (fixed in master, psf/black#1121).

Tested manually using:
```python
@pytest.fixture(scope="session")
def xdist_suffix(request):
    print("\nxdist_suffix")
    suffixes.append("xdist")

@pytest.fixture(scope="session")
def parallel_suffix(tox_suffix, xdist_suffix):
    pass

def test_suffix(parallel_suffix):
    assert suffixes == ["tox", "xdist"]
```

When using a set there the order is not deterministic, i.e. the test is
flaky.
blueyed added a commit to blueyed/pytest that referenced this pull request Mar 31, 2020
Note: black cannot parse `return *active_fixture_argnames,
*self.argnames` yet (fixed in master, psf/black#1121).

Tested manually using:
```python
@pytest.fixture(scope="session")
def xdist_suffix(request):
    print("\nxdist_suffix")
    suffixes.append("xdist")

@pytest.fixture(scope="session")
def parallel_suffix(tox_suffix, xdist_suffix):
    pass

def test_suffix(parallel_suffix):
    assert suffixes == ["tox", "xdist"]
```

When using a set there the order is not deterministic, i.e. the test is
flaky.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants