-
Notifications
You must be signed in to change notification settings - Fork 765
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
The signature help information shown to users for class constructors in Pylance version v2024.8.1 is less useful that in Pylance version v2024.7.1. This also breaks parameter code completion for those methods. #6286
Comments
Thanks for the issue. I can reproduce. Definitely a regression. |
I think this is being caused by a change in Pyright. This code here is returning false when checking if the type returned by function shouldSkipInitEvaluation(evaluator: TypeEvaluator, classType: ClassType, newMethodReturnType: Type): boolean {
const returnType = evaluator.makeTopLevelTypeVarsConcrete(newMethodReturnType);
let skipInitCheck = false;
doForEachSubtype(returnType, (subtype) => {
if (isUnknown(subtype)) {
return;
}
if (isClassInstance(subtype)) {
const inheritanceChain: InheritanceChain = [];
const isDerivedFrom = ClassType.isDerivedFrom(subtype, classType, inheritanceChain);
if (!isDerivedFrom) {
skipInitCheck = true;
}
return;
}
skipInitCheck = true;
});
return skipInitCheck;
} |
This is due to a bug in the The behavior that you're seeing from pyright is dictated by Python typing spec in the chapter on Constructors. This chapter was recently updated to clarify the proper behavior for static type analyzers, and pyright complies with the new rules. That explains why you are seeing a different behavior from earlier versions of pyright and pylance. I recommend reporting the issue to the maintainers of the |
Specifically changing this line in def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "Model": # pylint: disable=unused-argument <-- This return type should say Self
# we know the last three classes in mro are going to be 'Model', 'dict', and 'object'
mros = cls.__mro__[:-3][::-1] # ignore model, dict, and object parents, and reverse the mro order
attr_to_rest_field: typing.Dict[str, _RestField] = { # map attribute name to rest_field property
k: v for mro_class in mros for k, v in mro_class.__dict__.items() if k[0] != "_" and hasattr(v, "_type")
} |
@erictraut for the other issue tied to this one: User is calling the
Internally that AFAICT, the |
#6297 is a different issue, although I can see why you might think they're related. You're correct that the |
Closing as design. |
Thanks @rchiodo and @erictraut for investigating and identifying the real issue. FYI we followed up with the lseg_analytics package authors, and they traced the issue back to a problem in autorest.python which they use to generate their Python package. Apparently the change in Pyright caused a breaking change in autorest.python which has now been fixed. |
Type: Bug
Behaviour
Code completion for class constructors is broken in Pylance v2024.8.1 (was working in v2024.7.1), and the method signature pop-up displayed to the end user for a class constructor is unhelpful.
Pylance v2024.8.1:
Pylance v2024.7.1:
Steps to reproduce:
Given the following class:
FxForwardCurveDefinition
Defined in: https://pypi.org/project/lseg-analytics/
Installed via:
pip install lseg-analytics==1.0.0b2
Attempt to obtain code completion for the constructor of
FxForwardCurveDefinition
using Pylance v2024.8.1 and Pylance v2024.7 using the following snippet:Diagnostic data
Output for
Python
in theOutput
panel - when Pylance v2024.8.1 is installedOutput for
Python
in theOutput
panel - when Pylance v2024.7.1 is installedExtension version: 2024.8.1
VS Code version: Code 1.92.2 (fee1edb8d6d72a0ddff41e5f71a671c23ed924b9, 2024-08-14T17:29:30.058Z)
OS version: Windows_NT x64 10.0.19045
Modes:
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
opengl: disabled_off
rasterization: disabled_software
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software
webgpu: unavailable_software
webnn: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: