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

Allow string unpacking again. #13823

Open
JulienPalard opened this issue Oct 6, 2022 · 2 comments · May be fixed by #15511
Open

Allow string unpacking again. #13823

JulienPalard opened this issue Oct 6, 2022 · 2 comments · May be fixed by #15511
Labels
bug mypy got something wrong

Comments

@JulienPalard
Copy link
Member

String unpacking has been disallowed in #6406, where some comments ask for it to be allowed again. I'm opening an issue to track this better than comments in a closed issue.

Bug Report

I think mypy should allow string unpacking, as it's normal Python semantic.

To Reproduce

QUOTE_PAIRS = [
    "''",
    '""',
    "<>",
    "()",
    "[]",
    "{}",
]

for opening, closing in QUOTE_PAIRS:
    print(opening, closing)

Expected Behavior

I expected this to pass.

Actual Behavior

$ mypy pairs.py 
pairs.py:10: error: Unpacking a string is disallowed
pairs.py:11: error: Cannot determine type of "opening"
pairs.py:11: error: Cannot determine type of "closing"
Found 3 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 0.971 (compiled: yes)
  • Mypy command-line flags: ø
  • Mypy configuration options from mypy.ini (and other config files): ø
  • Python version used: irrelevant, but reproduced in 3.9, 3.10, 3.11.
@JulienPalard JulienPalard added the bug mypy got something wrong label Oct 6, 2022
@hauntsaninja
Copy link
Collaborator

At a minimum it should have its own error code, so you can do --disable-error-code string-unpacking. Maybe the thing that should have a special case error is multi-assignment to a dict[str, something]

@sfc-gh-tteixeira
Copy link

At the core of this feature request is the question: Is MyPy a type-checker, or a combination of type-checker and linter?

If it's purely a type-checker (as I assume), then I agree with the @JulienPalard 's post: String unpacking is valid Python code, and it's a perfectly well-defined operation in terms of typing.

If MyPy is both a type-checker and a linter, then it becomes a matter of taste.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Jun 24, 2023
@hauntsaninja hauntsaninja linked a pull request Jun 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants