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

There are still some deficiencies in automatic completion

Open WiC-htao opened this issue 1 year ago • 10 comments

Environment data

  • Language Server version: Pylance async client (2024.3.2) started with python extension (2024.2.1)
  • OS and version: Ubuntu 20.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.10

Code Snippet

Repro Steps

  1. I want inherit a airflow class under airflow/sensor/filesystem.py which has init like this
class FileSensor(BaseSensorOperator):
    ........
    def __init__(
          self, 
          *,
          filepath, fs_conn_id="fs_default",
          recursive=False, 
          deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
          **kwargs,
    ):
   ...........

and i auto-complete init, and expected it will be this

class _FileSensor(FileSensor):
    ........
    def __init__(
          self, 
          *,
          filepath, fs_conn_id="fs_default",
          recursive=False, 
          deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
          **kwargs,
    ):
   ...........

but it is this

class _FileSensor(FileSensor):
    ........
    def __init__(
          self, 
          *,
          filepath, fs_conn_id="fs_default",
          recursive=False, 
          deferrable: bool = ...,
          **kwargs,
    ):
   ...........

default value of deferrable becomes '...'. i don't know if it is any grammar sugar of python, but airflow can not parse this in dag, and in my local interactive python the default value of deferrable in my subclass _FileSenor has been replaced by Ellipsis.

i found a similar issue #3374 and it looks like fixed. I don't know if this similar case depends on the default value inherited or it is an expected behavior, but it really bother me.

WiC-htao avatar Jun 20 '24 11:06 WiC-htao

it works as expected for me. what version of pylance are you using? can you try latest pylance?

also, it looks like you have misspelling in class _FileSensor(FileSenor):.

heejaechang avatar Jun 20 '24 17:06 heejaechang

it works as expected for me. what version of pylance are you using? can you try latest pylance?

also, it looks like you have misspelling in class _FileSensor(FileSenor):.

should i check the version in the side bar of Extensions?or in any other way? In the side bar, it shows v2024.3.2, and i didn't see a newer version. And in this version, I come across the same question once again after retry.

image

Can you indicate the misspelling more clearly? i didn't find it, but i'm really sorry for this.

WiC-htao avatar Jun 23 '24 14:06 WiC-htao

our latest version is 2023.6.1, you might not seeing it because your vscode or python extension are old and newer version doesn't support those versions you have anymore, can you check what versions of vscode and python extensions? and make sure you are on the latest versions?

and misspelling is

class FileSensor(BaseSensorOperator): it says FileSensor but class _FileSensor(FileSenor) says FileSenor which is missing s

heejaechang avatar Jun 24 '24 17:06 heejaechang

our latest version is 2023.6.1, you might not seeing it because your vscode or python extension are old and newer version doesn't support those versions you have anymore, can you check what versions of vscode and python extensions? and make sure you are on the latest versions?

and misspelling is

class FileSensor(BaseSensorOperator): it says FileSensor but class _FileSensor(FileSenor) says FileSenor which is missing s

Do you mean 2024.6.1? My vscode version is 1.83.1 and pylance is v2024.3.2.

Thanks for your pointing, i have fixed the misspelling.

WiC-htao avatar Jun 25 '24 02:06 WiC-htao

ah, sorry, ya, 2024.6.1

heejaechang avatar Jun 25 '24 18:06 heejaechang

20240701103125_rec_-convert

WiC-htao avatar Jul 01 '24 02:07 WiC-htao

@WiC-htao not sure what the gif is trying to tell. can you provide a bit more detail?

heejaechang avatar Jul 01 '24 17:07 heejaechang

I believe it's the original complaint?

The deferrable parameter isn't matching what the original code did.

It ends up like this:

deferrable: bool = ...,

when the user wanted this:

deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),

You can repro with this:

from airflow.sensors.filesystem import FileSensor

class MySensor(FileSensor):
    def __init__

If you look at the original class, it has this for the __init__

    def __init__(
        self,
        *,
        filepath,
        fs_conn_id="fs_default",
        recursive=False,
        deferrable: bool = conf.getboolean("operators", "default_deferrable", fallback=False),
        **kwargs,
    ):

rchiodo avatar Jul 01 '24 17:07 rchiodo

so, looked into code. this is currently by design. if default value expression is not simple expression and if overriding is not happening within the same module as the method it is overriding, then we use "..."

that said, if we just put the expression (and let them show errors such as missing name and etc) then it is easy to support, but if we want to properly do this case, it would be enhancement and a bit more complex to support since we need to figure out how to remove those errors such as adding imports.

  • just adding missing imports might be all we need to do. so might be simpler...

heejaechang avatar Jul 01 '24 18:07 heejaechang

so, looked into code. this is currently by design. if default value expression is not simple expression and if overriding is not happening within the same module as the method it is overriding, then we use "..."

that said, if we just put the expression (and let them show errors such as missing name and etc) then it is easy to support, but if we want to properly do this case, it would be enhancement and a bit more complex to support since we need to figure out how to remove those errors such as adding imports.

  • just adding missing imports might be all we need to do. so might be simpler...

Got it.

While, i think it is a little not friendly enough, for program will not crash but have unexpected behavior quietly when I don't properly handle '...' . This is not easy to debug, especially when i have too many args to check everyone inherit correctly.

WiC-htao avatar Jul 05 '24 03:07 WiC-htao