Lancetnik / FastDepends

FastDepends - FastAPI Dependency Injection system extracted from FastAPI and cleared of all HTTP logic. Async and sync modes are both supported.
https://lancetnik.github.io/FastDepends/
MIT License
245 stars 8 forks source link

Use globals of original(wrapped) function #97

Closed yuyupopo closed 1 month ago

yuyupopo commented 1 month ago

Fixes: https://github.com/airtai/faststream/issues/1492

The original issue happens because the function is wrapped with a decorator, and type annotation resolution is done in the the decorator's globals. The fix uses func.__module__ instead of func.__globals__

This is because wraps copies the __module__ of the wrapped function, but not the __globals__

Lancetnik commented 1 month ago

Thank you a lot for the PR! I'll take a look, what we can do with old versions this evening

Lancetnik commented 1 month ago

Also, it will be really glad, if you add a test for your case, that fails for current impl and passes with your changes

yuyupopo commented 1 month ago

Also, it will be really glad, if you add a test for your case, that fails for current impl and passes with your changes

could you briefly share where i should implement the test? can i make a tests/import_test folder and write the test there?

yuyupopo commented 1 month ago

Also, it will be really glad, if you add a test for your case, that fails for current impl and passes with your changes

I'll add the test somewhere and fix the code so it runs in 3.8 and 3.9 also.

Lancetnik commented 1 month ago

could you briefly share where i should implement the test? can i make a tests/import_test folder and write the test there?

You can just add a test to "tests/test_locals.py" case

yuyupopo commented 1 month ago

could you briefly share where i should implement the test? can i make a tests/import_test folder and write the test there?

You can just add a test to "tests/test_locals.py" case

I've added the test in tests/test_prebuild.py. Also added another tests/wrapper.py because the require a wrapper function that exists in different module.

yuyupopo commented 1 month ago

I've addressed your comment, and this time hopefully it will pass all the tests

Lancetnik commented 1 month ago

Yeah, thank you a lot for the fix!

yuyupopo commented 1 month ago

Would it be possible to release another version by the weekend?

Lancetnik commented 1 month ago

Would it be possible to release another version by the weekend?

I tried to release it yesterday already, but there are some troubles with dirty-equals and python3.8 tests. I have to fixed it before we can make a release

Lancetnik commented 1 month ago

@yuyupopo the job is done - you can update FastDepends to 2.4.4 - all should works fine

yuyupopo commented 1 month ago

@yuyupopo the job is done - you can update FastDepends to 2.4.4 - all should works fine

Thanks a lot!

Lancetnik commented 1 month ago

@yuyupopo the job is done - you can update FastDepends to 2.4.4 - all should works fine

Thanks a lot!

Thank your for the PR!