Coder Social home page Coder Social logo

Typing about unsync HOT 5 OPEN

alex-sherman avatar alex-sherman commented on May 12, 2024
Typing

from unsync.

Comments (5)

alex-sherman avatar alex-sherman commented on May 12, 2024

Agreed, that would actually be awesome. I'm looking into how that would be possible and I believe there is currently not support for decorators modifying the return type of their functions within the Python typing specification.

If there are any examples of this being done, I would be more than happy to look further into it, but for the time being I think there is nothing I can do to support this.

from unsync.

Luttik avatar Luttik commented on May 12, 2024

The code in this commit works if you use python 3.5 or high. Makes the issue less severe, since you can then type the response of your method as future manually. This way you only need to disallow type inspection at the point where you return the response of the method. And the IDE knows that .result() is a method of the response of test_dict() and that result() now returns a dict.

@unsync
def test_dict() -> Unfuture[dict]:
    # noinspection PyTypeChecker
    return {'x': 1}


def use_dict():
    _dict = test_dict().result()
    _dict.get('x')

from unsync.

Luttik avatar Luttik commented on May 12, 2024

My message above however does have two issues.

  1. You still have to use a noinspect somewhere.
  2. It will not work for python < 3.5 (I guess there are options to fix this but I never build stuff for python < 3.7 so I don't have experience in this area)

from unsync.

EliseAv avatar EliseAv commented on May 12, 2024

The way I solve this problem is an assert isinstance after the call that returns unfuture. Not ideal either, but grants me full inspection.

from unsync.

alex-sherman avatar alex-sherman commented on May 12, 2024

I think this library cannot target Python < 3.5 anyway because it uses the async keyword, so I'm OK with including things that require >=3.5. @Luttik I actually really like the idea of supporting typing inside Unfuture at, if you open a pull request with that commit I'm happy to accept it unless you think there is some reason not to include that. It doesn't fully solve the problem but at least it's a step in the right direction.

from unsync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.