Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive on function call with walrus operator #17377

Open
mixilchenko opened this issue Jun 13, 2024 · 0 comments
Open

False positive on function call with walrus operator #17377

mixilchenko opened this issue Jun 13, 2024 · 0 comments
Labels
bug mypy got something wrong topic-pep-572 PEP 572 (walrus operator)

Comments

@mixilchenko
Copy link

Bug Report

In our codebase we chose specific way of working with pytest.mark.parametrize.
It is hard to look at tests which names are autogenerated from parameters list. To improve this we use parametrize(ids=) argument.
Unfortunately maintainability/readability of tests decreases if test cases and ids are written separately.
To resolve this issue we add some description to test cases and reuse it in ids with walrus operator.
For instance

class TestA:
    @pytest.mark.parametrize(
        'desc,a,b',
        _test_cases := (('a != b', 1, 2),), 
        ids=[desc for desc, *_ in _test_cases],
    )
    def test_func(self, desc: str, a: int, b: int) -> None:
        assert a == b, desc

Mypy says here that _test_cases does not exist which is incorrect

To Reproduce

I have created simple playground without pytest dependency to reproduce the error
https://mypy-play.net/?mypy=master&python=3.12&flags=check-untyped-defs&gist=8f98cbc918fbf8053a14f58c8011e375

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

main.py:11: error: Name "my_call_vars" is not defined [name-defined]

Your Environment

  • Mypy version used: 1.10.0 and master
  • Mypy command-line flags: no specific flags needed
  • Mypy configuration options from mypy.ini (and other config files): no specific configurations
  • Python version used: 3.10, 3.12
@mixilchenko mixilchenko added the bug mypy got something wrong label Jun 13, 2024
@JelleZijlstra JelleZijlstra added the topic-pep-572 PEP 572 (walrus operator) label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-pep-572 PEP 572 (walrus operator)
Projects
None yet
Development

No branches or pull requests

2 participants