pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Extract variable and method on arguments of decorator which precedes function definition doesn't create required definitions.

Open IntoLighter opened this issue 2 years ago • 6 comments

Type: Bug

Behaviour

Expected vs. Actual

Expected: Select value that I would like to extract, press extract. Values that were selected move to a definition statement, and I am given opportunity to rename the extracted component.

Actual: Value of selection substitutes by default extraction component name. No statements are created.

Steps to reproduce:

Create a function with decorator and pass it some argument, then extract this argument. Function for example:

@staticmethod(5) def a(): pass

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.5
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Output doesn't contain anything related to issue. And there is no way to paste anything to issue reporter.
User Settings


languageServer: "Pylance"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true

Extension version: 2022.12.0 VS Code version: Code 1.70.0 (Universal) (da76f93349a72022ca4670c1b84860304616aaa2, 2022-08-04T04:38:55.829Z) OS version: Darwin arm64 21.6.0 Modes:

System Info
Item Value
CPUs Apple M1 (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 3, 2
Memory (System) 16.00GB (0.06GB free)
Process Argv --crash-reporter-id 6c731971-c05a-4f5a-9769-babf9ff05d06
Screen Reader no
VM 0%

IntoLighter avatar Aug 06 '22 10:08 IntoLighter

I'm see this... can you provide an example of what you expect?

def new_func():
    return 5

@staticmethod(new_func())
def a():
 pass

do you expect to see a new variable introduced?

i = 4

@staticmethod(i)
def a():
 pass

bschnurr avatar Aug 08 '22 20:08 bschnurr

@bschnurr, I'm expecting to see what you have written for both cases. If you didn't understand, I get now:

@staticmethod(new_func())
def a():
 pass
@staticmethod(new_var)
def a():
 pass

IntoLighter avatar Aug 09 '22 10:08 IntoLighter

so you get new_func() but not the definition def new_func(): pass ?

bschnurr avatar Aug 09 '22 17:08 bschnurr

@bschnurr, yes. This is the problem of the issue.

IntoLighter avatar Aug 11 '22 04:08 IntoLighter

what platform?

i can't seem to repo the issue. i thought there might be a problem when its the first line of code in a file but it seems to be working for me.

bschnurr avatar Aug 11 '22 17:08 bschnurr

I see it now. 'extract variable'

bschnurr avatar Aug 15 '22 23:08 bschnurr