omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Autocomplete question

    Pythonista
    3
    8
    3588
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • frank
      frank last edited by

      Hi, I'm just getting started with Pythonista and I have a basic question on autocompletion:

      If I do the following, either in the console or an editor window:

      obj = MyObject()

      Then when I type "obj." it will offer to autocomplete with the members of MyObject. But if I do this:

      def foo(obj: MyObject):
      ... Here, "obj." does not autocomplete.

      I'm used to using Pycharm which will autocomplete if you give it type hints like in the declaration above, so I'm just wondering if I'm missing something simple to get Pythonista to do the same thing?

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        Pythonista uses a library called jedi to get autocompletion suggestions in the editor. Most likely it doesn't support Python 3 type annotations and ignores them. I don't think there's another way to tell jedi "this variable has this type", so I think for now you'll have to do without autocompletion for function arguments.

        1 Reply Last reply Reply Quote 0
        • frank
          frank last edited by

          Thanks!! Although now I'm more curious because after a little searching I found this:

          https://jedi.readthedocs.io/en/latest/docs/features.html#type-hinting

          Which seems to say that PEP 484 type hinting works. But now that I know about jedi, I'll go back and play with it some more to see if I can get it to work with some other examples. Maybe I'm doing something wrong with my type hinting.

          1 Reply Last reply Reply Quote 0
          • dgelessus
            dgelessus last edited by

            If it matters, Pythonista uses version 0.9.0 of jedi (see jedi.__version__), and the latest version is 0.10.0.

            1 Reply Last reply Reply Quote 0
            • frank
              frank last edited by

              That could be it too! It's weird, I can get it to work perfectly sometimes but not others. It might have to do with MyObject being defined in the same file versus a separate file. I'm going to keep experimenting ... If I figure out something reproducible I'll post it. Thanks again for the info!

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by

                One factor, I am not sure how the path is set for jedi -- and by default in pythonista, the current folder is NOT on sys.path, until you run a script in that folder. So, it might not be able to find your class if the external file is not explictly on sys.path.

                1 Reply Last reply Reply Quote 0
                • frank
                  frank last edited by frank

                  Ah!!! That did it! I switched over to the console, did os.chdir() to get to the correct path and did sys.path.append(os.getcwd()) and full completions are working now. Thank you!!

                  I'm not sure WHY the folder was not already in sys.path since I have clicked the Run button many times thinking that could be what was needed. But this workaround is perfect at any rate!

                  [I posted a follow up with what appeared to be a bug but I think I had a typo in my sample code because everything is working just fine now.]

                  1 Reply Last reply Reply Quote 0
                  • frank
                    frank last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors