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

mypy does not recognize collections within collections #305

Closed
Koraxtu opened this issue Jun 15, 2024 · 1 comment
Closed

mypy does not recognize collections within collections #305

Koraxtu opened this issue Jun 15, 2024 · 1 comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed

Comments

@Koraxtu
Copy link

Koraxtu commented Jun 15, 2024

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): 3.10
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): venv
  • Operating system (and version): Windows 10, current version
  • Version of tool extension you are using: current version of Mypy from a fresh install, no modifications

Behaviour

Expected Behavior

For no errors to be found.

Actual Behavior

I got an error and this is it:
"Sequence[Collection[str]]" has no attribute "append"Mypyattr-defined
(function) append: Any

Reproduction Steps:

  1. Create a new python file
  2. Create a collection that has another collection within that python file (eg: python list that contains a dictionary that contains a list)
  3. Write code that uses any built-in method on an double-nested collection

Example:

stores = [
    {
        "name": "My Store",
        "items": [
            {
                "name": "Chair",
                "price": 15.99
            }
        ]
    }
]

for store in stores:
    if store["name"] == "pie":
        new_item = {"name": "request_data", "price": "price"}
        store["items"].append(new_item)

On line 16 of the example, Mypy detects an error with using the append method on the list within stores[0]["items"], aka store["items"]. But store["items"] is a list and can use the append method, this code runs without issue.

Logs:

Click here for detailed logs 2024-06-15 00:12:13.849 [info] file:///c%3A/...etc.../app.py : c:\Users\...etc...\app.py:34:13:34:33: error: "Sequence[Collection[str]]" has no attribute "append" [attr-defined]

Extra Details

Other Python extensions: isort, Pylance, Python Debugger, Python
Project structure (square brackets represent folders):
[pycache]
[.mypy_cache]
[.venv]
app.py

@Koraxtu Koraxtu added the bug Issue identified by VS Code Team member as probable bug label Jun 15, 2024
@karthiknadig
Copy link
Member

This extension is a thin wrapper around mypy. This should be filed on https://github.com/python/mypy/issues

@karthiknadig karthiknadig closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed
Projects
None yet
Development

No branches or pull requests

2 participants