Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ParamSpec for callables. #6353

Merged
merged 2 commits into from
May 13, 2024
Merged

Conversation

wRAR
Copy link
Member

@wRAR wRAR commented May 11, 2024

I also changed most of addCallbacks() to addCallback()/addErrback(), as the official docs say the former has worse type hints (the ones I kept need to stay for various reasons).

I plan to add parameter specifications to more generics as separate PRs.

Comment on lines +86 to +110
@overload
def mustbe_deferred(
f: Callable[_P, Deferred[_T]], *args: _P.args, **kw: _P.kwargs
) -> Deferred[_T]: ...


@overload
def mustbe_deferred(
f: Callable[_P, Coroutine[Deferred[Any], Any, _T]],
*args: _P.args,
**kw: _P.kwargs,
) -> Deferred[_T]: ...


@overload
def mustbe_deferred(
f: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs
) -> Deferred[_T]: ...


def mustbe_deferred(
f: Callable[_P, Union[Deferred[_T], Coroutine[Deferred[Any], Any, _T], _T]],
*args: _P.args,
**kw: _P.kwargs,
) -> Deferred[_T]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied from maybeDeferred

Copy link

codecov bot commented May 11, 2024

Codecov Report

Attention: Patch coverage is 81.57895% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 84.86%. Comparing base (180bc9b) to head (fb63130).
Report is 6 commits behind head on master.

❗ Current head fb63130 differs from pull request most recent head 1c69ccf. Consider uploading reports for the commit 1c69ccf to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6353      +/-   ##
==========================================
- Coverage   85.00%   84.86%   -0.14%     
==========================================
  Files         161      161              
  Lines       11962    11996      +34     
  Branches     1872     1877       +5     
==========================================
+ Hits        10168    10181      +13     
- Misses       1512     1529      +17     
- Partials      282      286       +4     
Files Coverage Δ
scrapy/cmdline.py 67.40% <100.00%> (-1.25%) ⬇️
scrapy/core/downloader/handlers/ftp.py 98.63% <100.00%> (+0.05%) ⬆️
scrapy/core/engine.py 86.69% <100.00%> (ø)
scrapy/core/scraper.py 86.17% <100.00%> (ø)
scrapy/core/spidermw.py 99.44% <100.00%> (+<0.01%) ⬆️
scrapy/utils/python.py 88.12% <100.00%> (+0.22%) ⬆️
scrapy/utils/reactor.py 71.71% <100.00%> (+0.58%) ⬆️
scrapy/pipelines/files.py 73.05% <50.00%> (+1.06%) ⬆️
scrapy/mail.py 77.08% <0.00%> (-0.82%) ⬇️
scrapy/pipelines/media.py 97.70% <81.81%> (-1.49%) ⬇️
... and 3 more

... and 3 files with indirect coverage changes

@Gallaecio
Copy link
Member

I also changed most of addCallbacks() to addCallback()/addErrback(), as the official docs say the former has worse type hints (the ones I kept need to stay for various reasons).

And in all cases readability improved, in my opinion. Nice!

@Gallaecio Gallaecio merged commit 4ed5c5a into scrapy:master May 13, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants