Skip to content

Conversation

Spider84pr
Copy link
Contributor

I have added five annotation in Authlib
Not sure how to annotate returning request function of AsyncOAuth1Mixin class
It seem returning Response object from request library. I am not sure how to annotate it correctly
Can I write it like this?
async def request(self, method, url: str, token: dict[str, Any] | None =None, **kwargs): -> Response ...

This comment has been minimized.

@Spider84pr
Copy link
Contributor Author

Spider84pr commented Sep 27, 2025

I am especially doubting if i must import Request?

@Spider84pr
Copy link
Contributor Author

I have look in existing stubs and I found how to do it. Hopefully it is correct.
If something wrong - please teIll me - I will fix it

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Spider84pr
Copy link
Contributor Author

Some tests failed I have googled and added to Response import # type: ignore[import-untyped]
Now all test are passed but I dont know is this trick a legal one

from logging import Logger
from typing import Any

import requests # type: ignore[import-untyped]
Copy link
Member

Choose a reason for hiding this comment

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

if you are importing a 3rd-party lib, you need to add types-requests as a dependency: https://github.com/python/typeshed/blob/main/stubs/Authlib/METADATA.toml

Copy link
Contributor Author

@Spider84pr Spider84pr Sep 30, 2025

Choose a reason for hiding this comment

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

@sobolevn I must do it like so?

Metadata. toml
dependencies = [
"types-httpx",
]

Sorry, I've faced it first time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Spider84pr requires = ["types-requests"] should be correct. See for example stubs/pysftp/METADATA.toml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@srittau I have added required section and changed the library as we discussed with @sobolevn in the below, but the most test failed
I don't know what to do

async def request(self, method, url, token=None, **kwargs): ...
async def create_authorization_url(self, redirect_uri=None, **kwargs): ...
async def fetch_access_token(self, request_token=None, **kwargs): ...
async def request(self, method: str, url: str, token: dict[str, Any] | None = None, **kwargs) -> requests.Response: ...
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that this is not httpx.Response? requests is not an async lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Willl check it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I've made mistake - will fix it

This comment has been minimized.

This comment has been minimized.

from logging import Logger
from typing import Any

import httpx
Copy link
Member

Choose a reason for hiding this comment

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

async def create_authorization_url(self, redirect_uri=None, **kwargs): ...
async def fetch_access_token(self, redirect_uri=None, **kwargs): ...
async def load_server_metadata(self) -> dict[str, Any]: ...
async def request(self, method: str, url: str, token: dict[str, Any] | None = None, **kwargs) -> httpx.Response: ...
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to type **kwargs if your touching this function. The same applies for all others.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Spider84pr
Copy link
Contributor Author

Hello.
I have problems that I cannot solve myself for getting two remaining test to work.

Authlib requires cryptography for work. I have installed if on my local machine and all tests runs OK. I have googled and it reccomended to put it in /requirements-tests.txt Tried to do it in PR - this test are passed but appeared a lot of other error in other stub files. I thought that it was bad idea and removed it back from requirements-tests.
I dont know where to put it correctly. In requirements-tests.txt there is no similar libraries and i think iiit is not the right place

As previously mentioned tests found many errors in other files. After this PR I can try work, on it.
Sorry for many commit and large post.

@sobolevn
Copy link
Member

sobolevn commented Oct 3, 2025

Just add new errors to https://github.com/python/typeshed/blob/main/stubs/Authlib/%40tests/stubtest_allowlist.txt with a TODO comment that they need to be handled later (you can do this in the next PR).

@srittau can you please help with the stub_uploader failed job? I've submitted a PR with httpx addition :)

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Oct 4, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Spider84pr
Copy link
Contributor Author

@sobolevn I've added entries in stubtest_allowlist.txt and I will work it in next PR but I cannot resolve the remaining two test. Must I just wait?
I am also tried te setup this tests on local machine but without success. Is it possible?

@Spider84pr
Copy link
Contributor Author

@sobolevn thanks for corrected me.Also I have succesfully setup stub_ uploader on local machine. Hopefully it will help me in future PRs.

Copy link
Contributor

github-actions bot commented Oct 5, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Spider84pr
Copy link
Contributor Author

@sobolevn now only one test remains failing. It is very strange because your commit is merged several days ago. I have looked in source of this test - it trying to find requires_dist in the Authlib sources not in stubs that we can edit.
I really dfont'know what to do

@Spider84pr
Copy link
Contributor Author

Maybe I need to to a PR to Authlib to as them to add this dependency to metadata?

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