Skip to content

Commit

Permalink
🐛 fix config copy and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Dec 12, 2024
1 parent 2c3c3bd commit c2dbafb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions githubkit/config.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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())


Expand Down Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions tests/test_auth/test_auth_switch.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c2dbafb

Please sign in to comment.