Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0e53252
fix(deps): update dependency ty to v0.0.1a25
renovate[bot] Nov 7, 2025
2016eef
Initial plan
Copilot Nov 7, 2025
404c1dc
Fix type check errors for ty v0.0.1a25
Copilot Nov 7, 2025
810b8b6
Fix remaining type check errors for ty v0.0.1a25
Copilot Nov 7, 2025
2e58511
Improve comment clarity in open_id.py
Copilot Nov 7, 2025
ae20876
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2025
beb42bb
Replace _Base pattern with Protocol for type checking
Copilot Nov 7, 2025
53f0c87
Make mixins inherit from Protocol during TYPE_CHECKING
Copilot Nov 7, 2025
fc82ba8
Changes before error encountered
Copilot Nov 7, 2025
09630fa
Share OAuth2TestProtocol across all test files
Copilot Nov 7, 2025
6ee6663
Improve type annotations in OAuth2TestProtocol
Copilot Nov 10, 2025
a83cca2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 10, 2025
5164e4f
Fix cast() call broken by pre-commit autofix
Copilot Nov 10, 2025
eaf9c84
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 10, 2025
f137f4f
Fix cast() again and add noqa to prevent pre-commit changes
Copilot Nov 10, 2025
3600f1c
Revert to cast("Any", ...) - string form is correct
Copilot Nov 10, 2025
a7573b2
Replace cast() with type: ignore comment for Mock assignment
Copilot Nov 10, 2025
939725d
Remove Protocol inheritance from mixins to fix MRO issues
Copilot Nov 10, 2025
d66e21d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 10, 2025
99d802b
Use Protocol properly with TYPE_CHECKING conditional inheritance
Copilot Nov 10, 2025
7aa612b
fix(deps): update dependency ty to v0.0.1a26
renovate[bot] Nov 11, 2025
bf66726
Merge branch 'renovate/ty-0.x' into copilot/sub-pr-1382
nijel Nov 11, 2025
84ab57c
Add extra_settings and auth_handlers to OAuth2TestProtocol
Copilot Nov 11, 2025
34dfdd7
Add extra_data type annotation to TestUserSocialAuth
Copilot Nov 11, 2025
65dccf3
Remove extra_data override annotation from TestUserSocialAuth
Copilot Nov 12, 2025
c410943
Add assertion for extra_data type narrowing in tests
Copilot Nov 12, 2025
5de7184
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dev = [
"pytest-xdist==3.8.0",
"pytest==8.4.2",
"responses==0.25.8",
"ty==0.0.1a23",
"ty==0.0.1a25",
"types-defusedxml==0.7.0.20250822",
"types-oauthlib==3.3.0.20250822",
"types-requests-oauthlib==2.0.0.20250809",
Expand Down Expand Up @@ -84,7 +84,7 @@ dev = [
"pytest-xdist==3.8.0",
"pytest==8.4.2",
"responses==0.25.8",
"ty==0.0.1a23",
"ty==0.0.1a25",
"types-defusedxml==0.7.0.20250822",
"types-oauthlib==3.3.0.20250822",
"types-requests-oauthlib==2.0.0.20250809",
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def extra_data(
elif len(entry) == 3:
name, alias, discard = entry
elif len(entry) == 2:
name, alias = entry
name, alias = entry # type: ignore[misc]
elif len(entry) == 1:
name = alias = entry[0]
else:
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def refresh_token(self, token, *args, **kwargs):
method = self.REFRESH_TOKEN_METHOD
key = "params" if method == "GET" else "data"
request_args = {"headers": self.auth_headers(), "method": method, key: params}
request = self.request(url, **request_args)
request = self.request(url, **request_args) # type: ignore[arg-type]
return self.process_refresh_token_response(request, *args, **kwargs)

def refresh_token_url(self):
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/vk.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ def auth_complete(self, *args, **kwargs):
},
}
auth_data["response"].update(
json.loads(auth_data["request"]["api_result"])["response"][0]
json.loads(auth_data["request"]["api_result"])["response"][0] # type: ignore[index]
)
return self.strategy.authenticate(*args, **auth_data)
4 changes: 3 additions & 1 deletion social_core/backends/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def refresh_token(self, token, *args, **kwargs):
key = "params" if method == "GET" else "data"
request_args = {"headers": self.auth_headers(), "method": method, key: params}
request = self.request(
url, auth=HTTPBasicAuth(*self.get_key_and_secret()), **request_args
url,
auth=HTTPBasicAuth(*self.get_key_and_secret()),
**request_args, # type: ignore[arg-type]
)
return self.process_refresh_token_response(request, *args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion social_core/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def get_backend(
) -> BaseAuth:
"""Return a configured backend instance"""
Backend = self.get_backend_class(name)
return Backend(self, *args, redirect_uri=redirect_uri, **kwargs)
return Backend(self, *args, redirect_uri=redirect_uri, **kwargs) # type: ignore[misc]

# Implement the following methods on strategies sub-classes

Expand Down
4 changes: 4 additions & 0 deletions social_core/tests/backends/open_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def handle_starttag(self, tag, attrs) -> None:


class OpenIdTest(BaseBackendTest):
# These attributes must be defined by subclasses
discovery_body: str
server_response: str

def setUp(self) -> None:
responses.start()
Backend = module_member(self.backend_path)
Expand Down
20 changes: 16 additions & 4 deletions social_core/tests/backends/test_bitbucket_datacenter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# pyright: reportAttributeAccessIssue=false

import json
from typing import TYPE_CHECKING, Any, Protocol

import responses

from .oauth import OAuth2PkcePlainTest, OAuth2PkceS256Test

if TYPE_CHECKING:

class _OAuth2TestProtocol(Protocol):
"""Protocol for OAuth2Test methods used by mixins."""

def assertEqual(self, first: Any, second: Any, msg: Any = None) -> None: ...
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The return type annotation for assertEqual is incorrect. The unittest.TestCase's assertEqual method returns None, not Any. The signature should be:

def assertEqual(self, first: Any, second: Any, msg: Any = None) -> None: ...

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The assertEqual method already has the correct return type -> None in the current code (line 15 in test_bitbucket_datacenter.py). No changes needed.

def do_login(self) -> Any: ...
def do_refresh_token(self) -> Any: ...
@property
def name(self) -> str: ...


class BitbucketDataCenterOAuth2Mixin:
backend_path = "social_core.backends.bitbucket_datacenter.BitbucketDataCenterOAuth2"
Expand Down Expand Up @@ -61,14 +73,14 @@ class BitbucketDataCenterOAuth2Mixin:
)
expected_username = "erlich-bachman"

def extra_settings(self):
def extra_settings(self: "_OAuth2TestProtocol"): # type: ignore[misc]
settings = super().extra_settings()
settings.update(
{f"SOCIAL_AUTH_{self.name}_URL": "https://bachmanity.atlassian.net"}
)
return settings

def auth_handlers(self, start_url):
def auth_handlers(self: "_OAuth2TestProtocol", start_url): # type: ignore[misc]
target_url = super().auth_handlers(start_url)
responses.add(
responses.GET,
Expand All @@ -79,7 +91,7 @@ def auth_handlers(self, start_url):
)
return target_url

def test_login(self) -> None:
def test_login(self: "_OAuth2TestProtocol") -> None: # type: ignore[misc]
user = self.do_login()

self.assertEqual(len(user.social), 1)
Expand Down Expand Up @@ -108,7 +120,7 @@ def test_login(self) -> None:
self.assertEqual(social.extra_data["expires"], 3600)
self.assertEqual(social.extra_data["refresh_token"], "dummy_refresh_token")

def test_refresh_token(self) -> None:
def test_refresh_token(self: "_OAuth2TestProtocol") -> None: # type: ignore[misc]
_, social = self.do_refresh_token()

self.assertEqual(social.uid, "1")
Expand Down
14 changes: 12 additions & 2 deletions social_core/tests/backends/test_etsy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# pyright: reportAttributeAccessIssue=false

import json
from typing import TYPE_CHECKING, Any, Protocol

from .oauth import OAuth2PkceS256Test

if TYPE_CHECKING:

class _OAuth2PkceS256TestProtocol(Protocol):
"""Protocol for OAuth2PkceS256Test methods used by mixins."""

def assertEqual(self, first: Any, second: Any, msg: Any = None) -> None: ...
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The return type annotation for assertEqual is incorrect. The unittest.TestCase's assertEqual method returns None, not Any. The signature should be:

def assertEqual(self, first: Any, second: Any, msg: Any = None) -> None: ...

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The assertEqual method already has the correct return type -> None in the current code (line 13 in test_etsy.py). No changes needed.

def do_login(self) -> Any: ...
def do_refresh_token(self) -> Any: ...


class EtsyOAuth2Mixin:
backend_path = "social_core.backends.etsy.EtsyOAuth2"
Expand Down Expand Up @@ -36,7 +46,7 @@ class EtsyOAuth2Mixin:
)
expected_username = "dummy_user_id"

def test_login(self) -> None:
def test_login(self: "_OAuth2PkceS256TestProtocol") -> None: # type: ignore[misc]
user = self.do_login()
self.assertEqual(len(user.social), 1)

Expand All @@ -58,7 +68,7 @@ def test_login(self) -> None:
social.extra_data["refresh_token"], "dummy_user_id.dummy_refresh_token"
)

def test_refresh_token(self) -> None:
def test_refresh_token(self: "_OAuth2PkceS256TestProtocol") -> None: # type: ignore[misc]
_, social = self.do_refresh_token()

self.assertEqual(social.uid, "dummy_user_id")
Expand Down
14 changes: 12 additions & 2 deletions social_core/tests/backends/test_twitter_oauth2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pyright: reportAttributeAccessIssue=false

import json
from typing import TYPE_CHECKING, Any, Protocol

from social_core.exceptions import AuthException

Expand All @@ -11,6 +12,15 @@
OAuth2Test,
)

if TYPE_CHECKING:

class _OAuth2TestProtocol(Protocol):
"""Protocol for OAuth2Test methods used by mixins."""

def assertEqual(self, first: Any, second: Any, msg: Any = None) -> None: ...
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The return type annotation for assertEqual is incorrect. The unittest.TestCase's assertEqual method returns None, not Any. The signature should be:

def assertEqual(self, first: Any, second: Any, msg: Any = None) -> None: ...

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The assertEqual method already has the correct return type -> None in the current code (line 20 in test_twitter_oauth2.py). No changes needed.

def do_login(self) -> Any: ...
def do_partial_pipeline(self) -> Any: ...


class TwitterOAuth2Mixin:
backend_path = "social_core.backends.twitter_oauth2.TwitterOAuth2"
Expand Down Expand Up @@ -80,7 +90,7 @@ class TwitterOAuth2Mixin:

expected_username = "twitter_username"

def test_login(self) -> None:
def test_login(self: "_OAuth2TestProtocol") -> None: # type: ignore[misc]
user = self.do_login()

self.assertEqual(len(user.social), 1)
Expand All @@ -106,7 +116,7 @@ def test_login(self) -> None:
self.assertEqual(social.extra_data["public_metrics"]["tweet_count"], 40)
self.assertEqual(social.extra_data["public_metrics"]["listed_count"], 7)

def test_partial_pipeline(self) -> None:
def test_partial_pipeline(self: "_OAuth2TestProtocol") -> None: # type: ignore[misc]
user = self.do_partial_pipeline()
self.assertEqual(len(user.social), 1)

Expand Down
5 changes: 3 additions & 2 deletions social_core/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import unittest
from typing import Any, cast
from unittest.mock import Mock

from social_core.backends.base import BaseAuth
Expand Down Expand Up @@ -199,8 +200,8 @@ def _backend(self, session_kwargs=None):
class GetKeyAndSecretBasicAuthTest(unittest.TestCase):
def setUp(self) -> None:
self.backend = BaseAuth(strategy=Mock())
self.backend.setting = Mock(
side_effect=lambda x: "test_key" if x == "KEY" else "test_secret"
self.backend.setting = cast(
Any, Mock(side_effect=lambda x: "test_key" if x == "KEY" else "test_secret")
)

def test_basic_auth_returns_bytes(self) -> None:
Expand Down
Loading