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.


    Typed Python interface stubs for editing Pythonista code on the desktop

    Pythonista
    2
    7
    4550
    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.
    • hmartin
      hmartin last edited by

      I sometimes prefer working on larger Pythonista projects in my desktop IDE. However, imports of Pythonista iOS APIs look broken, autocomplete can't work, and static checking is useless. To solve these problems, I've started working a set of typed Python interface stubs. Please check it out and let me know problems and suggestions!
      https://github.com/hbmartin/pythonista-stubs

      1 Reply Last reply Reply Quote 4
      • Olaf
        Olaf last edited by

        Very welcome initiative!

        I may contribute a module or two that I'm comfortable with.
        In the style guide, you state "no Union[] return annotations"; does that also imply "no Optional[] return annotations"? The Pythonista modules have some.

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

          @Olaf Union[] generally indicates an anti-pattern because a method should be relied on to return a single type. That said, given that we don't control the underlying API it may be necessary at some point.

          To answer your specific question, I definitely encourage using Optional[] where the method has documentation stating it might. For example, in the reminders interface there is def get_calendar(calendar_id: str) -> Optional[Calendar]: ... since we're not guaranteed to find a given ID.

          It would be great to get some help and I'm happy to collaborate on typing syntax. I just hesitate to write interfaces for APIs that I haven't personally used, seems like an easy way to get things wrong :)

          (For background reading on Union issues see here: https://github.com/python/mypy/issues/1693 )

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

            After some discussion with the author, pygenstub now supports generic module interface generation. (Unlike the more well known stubgen, no C compilation required.)

            This means that in StaSh we can run something like python3 pygenstub.py -p appex -o out --generic to get a stub for appex. It needs cleanup (like replacing all the Anys and removing private things) but it's a great running start.

            1 Reply Last reply Reply Quote 1
            • Olaf
              Olaf last edited by Olaf

              Okay, I'll try my luck at some parts of scene

              Well, no luck :-(
              pygenstub will not install (pip install) at my iPad with File Not Found Error.
              pip successfully downloads the .whl from pythonhosted.org, but on installing the wheel stops at an error
              Version 1.2 (current version is 1.4) installs

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

                @Olaf I'd recommend copying over the pygenstub.py file from the repo instead of installing with pip

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

                  thanks. works after pip docutils

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors