That is a Pylance error.

You can create a pyrightconfig.json file at the root of your workspace and define the files to be exclude-d from analysis or completely ignore-d:

{
    "ignore": [
        "**/*.ipynb",
    ],
}

You can even list up specific filenames:

{
    "ignore": [
        "notimportant.ipynb",
        "test.ipynb",
    ],
}

Historical Notes:

It initially didn't work for Jupyter Notebooks (.ipynb):
https://github.com/microsoft/pylance-release/issues/2135

This happens because pyright doesn't see the file as a "*.ipynb". The file is being preprocessed (to combine all of the cells) in the notebook by the VS Code Python extension, and the resulting combined file is then passed to pyright for analysis.

The pylance team is actively working on changing the way this works. I'm going to transfer this bug to the pylance-release repo so it gets the attention it deserves.

That Github issue has since been resolved the fix was deployed as part of pylance 2022.8.51: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2022851-31-august-2022-prerelease

Notable changes:

  • ...
  • Bug Fix: Ignoring *.ipynb files does not work (pylance-release#2135)

If it somehow still does not work, check the version of pylance on your VS Code.

Answer from Gino Mempin on Stack Overflow
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2512
Type: ignore for a block of code? · Issue #2512 · microsoft/pylance-release
March 27, 2022 - I don't want to append # type: ignore to every line in that block, is it possible to add a feature that disables type checking between a # type: ignore start and a type: ignore end?
Author   tddschn
🌐
GitHub
github.com › microsoft › pylance-release › issues › 196
Allow line level suppression of specific errors · Issue #196 · microsoft/pylance-release
August 3, 2020 - When using PyLint i can put a comment after an import to ignore an import failure of that specific import as below: from airflow.models import BaseOperator # pylint: disable=import-error I can't find a way to do the same using PyLance. I...
Author   MrJoosh
🌐
GitHub
github.com › microsoft › pylance-release › blob › main › docs › settings › python_analysis_ignore.md
pylance-release/docs/settings/python_analysis_ignore.md at main · microsoft/pylance-release
1 month ago - This can occur with third-party libraries, generated files, or code that intentionally deviates from standard practices. To manage this, Pylance provides the python.analysis.ignore setting, allowing you to suppress diagnostics for specified paths.
Author   microsoft
🌐
Reddit
reddit.com › r/learnpython › disable python type checking
r/learnpython on Reddit: Disable Python Type Checking
July 8, 2025 -

I coach a robotics team of middle school kids and it is important that all of the laptops are configured the same. When we clone our repo, VS Code will prompt them to enable type checking. I'd rather keep type checking off for now, so I really much prefer the warning to not come up at all. The kids are kind of quick to hit the default "Yes", which enables type checking. I have in my pyproject.toml

```

[tool.pyright]
typeCheckingMode = "off"

```

And that is included in the repo. And even so, I still get the warning/suggestion

"Pylance has detected type annotations in your code and recommends enabling type checking. Would you like to change this setting?"

Sure, I can click "No" at that point, and it seems to keep pylance happy and it doesn't ask again, but I'd rather it not ask at all in the first place. Ideally I'd like to figure out a way to suppress the warning at the project level, so I can push the setting to everyone as part of the repo.

🌐
Pydantic
docs.pydantic.dev › latest › integrations › visual_studio_code
Visual Studio Code - Pydantic Validation
that way Pylance and mypy will interpret the variable age_str as if they didn’t know its type, instead of knowing it has a type of str when an int was expected (and then showing the corresponding error). Pros: errors will be ignored only for a specific value, and you will still see any additional errors for the other arguments.
Find elsewhere
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Pylance - Visual Studio Marketplace
2 weeks ago - Extension for Visual Studio Code - A performant, feature-rich language server for Python in VS Code
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2167
Comment `# type: ignore` stopped to work · Issue #2167 · microsoft/pylance-release
December 12, 2021 - Pylance will show that "a" is not defined. This is uncorrected, because we "imported" this variable via %run command. Create new cell at the start of notebook2.ipynb and type in it:
Author   sindzicat
🌐
GitHub
github.com › microsoft › pylance-release › issues › 108
Failure on `# type: ignore[code]' comments · Issue #108 · microsoft/pylance-release
July 14, 2020 - # type: ignore[code] treated same as # type: ignore (or, at least, does not generate its own error)
Author   algorythmic
Top answer
1 of 4
96

There are many ways of forcing a type-checker to accept this.



  1. Use assert:

    from typing import Union
    
    def do_something(var: Union[T, None]):
        assert var is not None
        var.foo()
    

  2. Raise some other exception:

    from typing import Union
    
    def do_something(var: Union[T, None]):
        if var is None:
            raise RuntimeError("NO")
        var.foo()
    

  3. Use an if statement:

    from typing import Union
    
    def do_something(var: Union[T, None]):
        if var is not None:
            var.foo()
    

  4. Use typing.cast, a function that does nothing at runtime but forces a type-checker to accept that a variable is of a certain type:

    from typing import Union, cast
    
    def do_something(var: Union[T, None]):
        var = cast(T, var)
        var.foo()
    

  5. Switch off the type-checker for that line:

    from typing import Union
    
    def do_something(var: Union[T, None]):
        var.foo()  # type: ignore
    


Note also that, while it makes no difference to how your type annotation is interpreted by a type-checker (the two are semantically identical), you can also write typing.Union[T, None] as typing.Optional[T], which is arguably slightly nicer syntax. In Python >=3.10 (or earlier if you have from __future__ import annotations at the top of your code), you can even write Union types with the | operator, i.e. T | None.

2 of 4
20

Please don't use blanket # type: ignore. Instead be specific on what linting error you want to ignore:

myOptionalVar.foo()         # pyright: ignore[reportOptionalMemberAccess]

Above works in VSCode default linter Pylance which uses Pyright.

If you are using MyPy, you can use the less specific error-code:

myOptionalVar.foo()         # type: ignore[attr-defined]
🌐
GitHub
github.com › microsoft › pylance-release › issues › 7220
Suggest inserting `# pyright: ignore` without `enableTypeIgnoreComments` · Issue #7220 · microsoft/pylance-release
May 15, 2025 - After #4494 quick actions now have an option to insert # pyright: ignore[xxx] instead of generic # type: ignore, which is very useful, especially combined with reportUnnecessaryTypeIgnoreComment = true, so each comment basically becomes a direct typing test.
Published   May 15, 2025
Author   Andrej730
Top answer
1 of 3
13

Pylance supports PEP 484

A number of existing or potential use cases for function annotations exist, which are incompatible with type hinting. These may confuse a static type checker. However, since type hinting annotations have no runtime behavior (other than evaluation of the annotation expression and storing annotations in the _annotations_ attribute of the function object), this does not make the program incorrect -- it just may cause a type checker to emit spurious warnings or errors.

To mark portions of the program that should not be covered by type hinting, you can use one or more of the following:

a # type: ignore comment;
a @no_type_check decorator on a class or function;
a custom class or function decorator marked with @no_type_check_decorator.

Alternatively you can create a pyrightconfig.json for Pyright (as that's what Pylance is using underneath) or a pyproject.toml in project's root directory, and specify which types of errors to ignore. You can see the error type in the hover widget where error messages appear.

pyrightconfig.json example:

{
        "reportGeneralTypeIssues": false,
}

pyproject.toml example:

[tool.pyright]
reportGeneralTypeIssues = false

See Type Check Diagnostics Settings for more.

2 of 3
11

The top-voted answer is great but it may not solve the problem (it just ignores the type checker, right?). My answer does not solve the problem either, but I think it's helpful.

I suggest you modify your .vscode/settings.json (Workspace settings or User settings) as described here and here and shown below. (Notice the use of "none" instead of false)

(Maybe this is preferable if you already have Workspace settings and you don't want to add another settings file as shown in the top-voted answer (like pyrightconfig.json or pyproject.toml))

{
  "python.analysis.typeCheckingMode": "basic",
  "python.analysis.diagnosticSeverityOverrides": {
    "reportGeneralTypeIssues": "none"
  }
}

I think the OP is correct with this comment, this error is not a reportGeneralTypeIssues type issue.

I've tried both solutions but the error still exists. Maybe it's not a reportGeneralTypeIssues?

If you reset your Pylance settings (flag all diagnostic codes as errors (remove settings.json, or use the "error" diagnostic setting)), and you type the OP's code below

def example() -> [str]:
    return ["hi"]

VSCode/Pylance/Pyright shows an error squiggly, and when you hover it lists two error reasons.

  • The first error says "List expression not allowed in type annotation Use List[T]..." and is tagged only as "Pylance" (no diagnostic code)
  • The second error says "Expected type expression but received "list[Type[str]]" and is tagged as Pylance(reportGeneralTypeIssues), (note there is a diagnostic code)

If you modify your settings.json as described above:

...

  "python.analysis.diagnosticSeverityOverrides": {
    "reportGeneralTypeIssues": "none"
  }
...

... then the second Pylance(reportGeneralTypeIssues) type error goes away, but the original Pylance error (without the diagnostic code) is still there:

The top-voted answerer suggests trying other diagnostic codes, but it seems like this error is more a "core error" than any diagnostic code describes?

I think it's tempting to blame the editor (VSCode), but I don't think it's VSCode's fault, VSCode is just using Pylance, and Pylance is just trying to implement the Python standards/PEPs, right?

I still think [str] is invalid/nonstandard type hinting syntax, as this commenter said .

I agree with OP, [str] is "shorter and does the trick", but it's not standard is it? Not defined in any PEP? Not in PEP 484, not in PEP 585. Doesn't this mean PyCharm is supporting something nonstandard?

🌐
Pydantic
pydantic.dev › docs › validation › latest › integrations › dev-tools › visual_studio_code
Visual Studio Code | Pydantic Docs
that way Pylance and mypy will interpret the variable age_str as if they didn’t know its type, instead of knowing it has a type of str when an int was expected (and then showing the corresponding error). Pros: errors will be ignored only for a specific value, and you will still see any additional errors for the other arguments.
🌐
Readthedocs
micropython-stubs.readthedocs.io › en › main › 22_vscode.html
Configuring VSCode, Pylance or Pyright — Micropython-Stubs 1.23.0 documentation
Therefore it makes sense to ignore these warnings. To suppress these warnings add the following to your VSCode configuration. ... Pylance (and Pyright) do not by default allow you to override the stdlib stubs. This is possible but needs to be configured explicitly in the settings. The VSCode configuration for this is shown below. ... The python.analysis.typeshedPaths setting is a list of paths to search for typeshed stubs.