Comments (5)
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.
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.
My message above however does have two issues.
- You still have to use a noinspect somewhere.
- 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.
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.
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)
- Async generators HOT 2
- Defining the amount of threads in use for sync functions HOT 3
- How to handle errors and exceptions? HOT 1
- Can't Import unsync on AWS Lambda HOT 5
- Cython support
- @unsync(cpu_bound=True) Windows 10 64 error HOT 1
- Any support or alternative for `asyncio.Semaphore`? HOT 4
- Calling nested results() on futures produces InvalidStateError HOT 1
- Unsync conda-forge recipe
- Python 3.9.x compatability? HOT 6
- Decorator problem HOT 1
- process_executor.py example on Windows 7 orphans the multiprocess kernels HOT 1
- Ability to limit concurrency? HOT 4
- Leftover debug? DERP HOT 2
- Continuation with cpu_bound functions HOT 2
- CPU Bound Decorator in Wrapped Functions HOT 1
- Using @unsync decorator in Jupyter results in error HOT 1
- max_workers HOT 3
- closing old processes HOT 3
- `BrokenProcessPool` error using function with `cpu_bound=True` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unsync.