microsoft / pyright

Static Type Checker for Python
Other
13.09k stars 1.4k forks source link

A type error is being reported even though "type checking mode" is set to "off" #8453

Closed theroggy closed 1 month ago

theroggy commented 1 month ago

Environment data

Code Snippet

from numpy.typing import NDArray
from shapely.geometry.base import BaseGeometry

def simplify_topo(test: NDArray[BaseGeometry]):
    return

Repro Steps

NDArray[BaseGeometry] in the above snippet will be highlighted as having an error.

Expected behavior

No type errors, as "type checking mode" is set to "off".

Actual behavior

This type error is shown:

Could not specialize type "NDArray[_ScalarType_co@NDArray]"
  Type "BaseGeometry" is incompatible with type "generic"
    "BaseGeometry" is incompatible with "generic"

Logs

No significant logging is being written...

erictraut commented 1 month ago

This is a bug in the core type checker. Could someone from the pylance team please transfer this to the pyright project? Thanks!

erictraut commented 1 month ago

I did a full pass over all diagnostics emitted by the type evaluator and made sure that every one had an associated diagnostic rule. This allows the severity of all type evaluator diagnostics to be under user control. This will be addressed in the next release of pyright.

erictraut commented 1 month ago

This is addressed in pyright 1.1.373.

Cnly commented 1 week ago

Hmmm, I wonder if there's a regression? I'm using coc-pyright and I think I'm seeing this on 1.1.37{6,7,8}. Rolling pyright back to 1.1.375 solved the problem.

erictraut commented 1 week ago

@Cnly, an intentional change was made in 1.1.376 that explains this. You probably have a config file (either a pyrightconfig.json or a pyproject.toml with a [tool.pyright] section) in your project. If so, that takes precedence over any language server settings that affect type checking behaviors. If you want to change the type checking mode, you should do so in your config file rather than in your language server settings. Or you should delete your config file and use only the language server settings to specify your type checking behaviors.

Cnly commented 1 week ago

@erictraut Thank you for the rapid reply and detailed explanation! I indeed have a pyrightconfig.json in my project. Adding "typeCheckingMode": "off" to the file fixed the problem on 1.1.378.