8000 [change] API - Add type annotations to api module by vgerak · Pull Request #2754 · Flexget/Flexget · GitHub
[go: up one dir, main page]

Skip to content

[change] API - Add type annotations to api module #2754

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
Nov 28, 2020

Conversation

vgerak
Copy link
Contributor
@vgerak vgerak commented Oct 17, 2020

Motivation for changes:

Continuation of #2751, api module

Detailed changes:

  • Added type annotations to api module
  • Changed "rel" links generation in pagination_headers() (equivalent results, obviously). To me, it's more readable compared to the template parameter replacement method, but, as it's just my opinion, I can revert it if you wish
  • TypedDict usage is wrapped inside if TYPE_CHECKING blocks, as it's available on versions >= 3.8.
  • Adding Session annotation for API methods introduced "new" mypy warnings like the following (previously ignored, as inferred type was Any cause of missing annotations):
    Item "None" of "Optional[Session]" has no attribute "query"
    Should all go away when typing decorators that mess with the arguments is implemented. Relevant issues: Allow variadic generics python/typing#193 , Support function decorators excellently python/mypy#3157
  • Changed some try: ... except Exception: pass to use contextlib.suppress instead

Log and/or tests output (preferably both):

============== 1317 passed, 28 skipped, 4 xfailed, 5 xpassed, 59 warnings in 188.89s (0:03:08) ===============

@vgerak vgerak force-pushed the develop-typings-api branch 4 times, most recently from c665aa6 to d186330 Compare October 19, 2020 14:31
Copy link
Member
@liiight liiight left a comment

Choose a reason for hiding this comment

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

Holy crap dude, you put in a TON of work on this, thank you!
I wonder if we should add type testing to the CI/pre-commit.
@gazpachoking @paranoidi WDYT?

@@ -81,7 +97,7 @@ class PluginsAPI(APIResource):
@api.response(BadRequest)
@api.response(NotFoundError)
@api.doc(parser=plugins_parser)
def get(self, session=None):
def get(self, session: None = None) -> Response:
Copy link
Member

Choose a reason for hiding this comment

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

type shouldn't be None, it's Session. last one i'll mention :)

@vgerak vgerak force-pushed the develop-typings-api branch from d186330 to f64856d Compare November 6, 2020 07:57
@vgerak vgerak force-pushed the develop-typings-api branch from f64856d to a899fba Compare November 28, 2020 09:51
@vgerak vgerak force-pushed the develop-typings-api branch from a899fba to 9e68a29 Compare November 28, 2020 09:51
@vgerak vgerak requested a review from liiight November 28, 2020 09:55
@vgerak
Copy link
Contributor Author
vgerak commented Nov 28, 2020

branch rebased to latest develop, requested changes performed

@liiight liiight changed the title Add type annotations to api module [change] API - Add type annotations to api module Nov 28, 2020
@liiight liiight merged commit db6ecb5 into Flexget:develop Nov 28, 2020
@liiight
Copy link
Member
liiight commented Nov 28, 2020

Absolutely amazing work on this @vgerak !!!

@mrahtz
Copy link
mrahtz commented Feb 20, 2021

@vgerak I noticed you referenced python/typing#193 on variadic generics in this thread. Heads up that we've been working on a draft of a PEP for this in PEP 646. If this is something you still care about, take a read and let us know any feedback in this thread in typing-sig. Thanks!

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.

4 participants
0