diff --git a/githubkit/config.py b/githubkit/config.py index c475b51a2..8ec15b4c4 100644 --- a/githubkit/config.py +++ b/githubkit/config.py @@ -1,4 +1,4 @@ -from dataclasses import asdict, dataclass +from dataclasses import dataclass, fields from typing import Any, Optional, Union from typing_extensions import Self @@ -24,9 +24,11 @@ class Config: rest_api_validate_body: bool def dict(self) -> dict[str, Any]: - return asdict(self) + """Return the config as a dictionary without copy values.""" + return {field.name: getattr(self, field.name) for field in fields(self)} def copy(self) -> Self: + """Return a shallow copy of the config.""" return self.__class__(**self.dict()) @@ -107,6 +109,7 @@ def get_config( auto_retry: Union[bool, RetryDecisionFunc] = True, rest_api_validate_body: bool = True, ) -> Config: + """Build the configs from the given options.""" return Config( build_base_url(base_url), build_accept(accept_format, previews), diff --git a/tests/test_auth/test_auth_switch.py b/tests/test_auth/test_auth_switch.py new file mode 100644 index 000000000..f5593831d --- /dev/null +++ b/tests/test_auth/test_auth_switch.py @@ -0,0 +1,9 @@ +from githubkit import GitHub, UnauthAuthStrategy + + +def test_auth_switch(g: GitHub): + new_auth = UnauthAuthStrategy() + + new_g = g.with_auth(new_auth) + assert new_g.auth is new_auth + assert new_g.config == g.config