Skip to content

Fix type hinting #5

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

Merged
merged 1 commit into from
Sep 24, 2022
Merged

Fix type hinting #5

merged 1 commit into from
Sep 24, 2022

Conversation

mjpieters
Copy link
Contributor

This PR fixes the type hinting issue #4.

  • Use a ParamSpec to capture the wrapped function arguments and a
    separate TypeVar for the return type, so that the annotation can
    accurately wrap just the return value in a Coroutine annotation.
  • Add explicit type hints for functions that use @overload (which
    are not compatible with ParamSpec).
  • Add typing-extensions as a dependency (used for ParamSpec on older
    Python versions)
  • Add a few simple tests to verify that type hints now are producing
    correct output.

Note that I switched to using Coroutine[Any, Any, ...] here, it's the more
accurate type hint.

@mjpieters
Copy link
Contributor Author

The test failures here will be fixed once #7 is merged and I've rebased this on top of that PR.

@codecov-commenter
Copy link

codecov-commenter commented Sep 22, 2022

Codecov Report

Merging #5 (509c481) into master (92c5744) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master        #5   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           39        45    +6     
=========================================
+ Hits            39        45    +6     
Impacted Files Coverage Δ
aioshutil/__init__.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@mjpieters
Copy link
Contributor Author

Right, so the tests should now pass, because the mypy typechecks are skipped on anything other than 3.10. That's because mypy refuses to acknowledge the backported ParamSpec object for now on anything other than 3.10; I think python/mypy#12011 may be related there. This is a mypy bug, so I'm not taking the hints out again. :-)

Copy link
Owner

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I have left some comments and there is a conflict, after you have fixed those then this is ready to go in.

@mjpieters
Copy link
Contributor Author

Bah, humbug. I'll have to fix the PR push.

I was trying to do this via GitHub codespaces on a mobile phone as I am travelling.

- Use a `ParamSpec` to capture the wrapped function arguments and a
  separate `TypeVar` for the return type, so that the annotation can
  accurately wrap just the return value in a `Coroutine` annotation.
- Add explicit type hints for functions that use @overload (which
  are not compatible with ParamSpec).
- Add typing-extensions as a dependency (used for ParamSpec on older
  Python versions)
- Add a few simple tests to verify that type hints now are producing
  correct output.
Copy link
Owner

@kumaraditya303 kumaraditya303 left a comment

Choose a reason for hiding this comment

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

LGTM Thanks!

@kumaraditya303 kumaraditya303 merged commit b70f4a0 into kumaraditya303:master Sep 24, 2022
@mjpieters mjpieters deleted the type_hinting_fixes branch September 24, 2022 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants