Skip to content
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

TypeError in cass.get_version() due to datetime.date and Arrow type mismatch in Patch.from_date() #462

Open
sdkim96 opened this issue Nov 2, 2024 · 0 comments

Comments

@sdkim96
Copy link

sdkim96 commented Nov 2, 2024

Hello,

When I use the cass.get_version() method, I noticed that the date parameter in the function has a type hint of datetime.date. Based on that, I wrote the following code:

async def _get_patch_version(self, target_date: Optional[Union[str, datetime.date]] = None) -> str:
    """Date format: %y%m%d"""
    
    if target_date is None:
        target_date = datetime.date.today()
    elif isinstance(target_date, str):
        try:
            target_date = datetime.datetime.strptime(target_date, "%y%m%d").date()
        except ValueError:
            raise ValueError("Date format should be YYMMDD, e.g., '240508' for 2024-05-08.")
    
    return await asyncio.to_thread(cass.get_version, date=target_date, region=self.region)

When I use the above function and pass a datetime.date type as the date parameter to cass.get_version(), I encounter a type error in Patch.from_date() if I specify a date other than today.

.venv/lib/python3.12/site-packages/cassiopeia/cassiopeia.py:242: in get_version
    patch = Patch.from_date(date, region=region)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'cassiopeia.core.patch.Patch'>, date = datetime.date(2024, 11, 2), region = <Region.korea: 'KR'>

    @classmethod
    def from_date(cls, date: arrow.Arrow, region: Union[Region, str]) -> "Patch":
        if not cls.__patches:
            cls.__load__()
        if not isinstance(region, Region):
            region = Region(region)
        for patch in cls.__patches[region]:
            patch_end = patch.end or arrow.now().shift(seconds=1)
>           if patch.start <= date < patch_end:
E           TypeError: '<=' not supported between instances of 'Arrow' and 'datetime.date'

.venv/lib/python3.12/site-packages/cassiopeia/core/patch.py:70: TypeError
================================================================================ short test summary info =================================================================================
FAILED tests/test_riot_handler.py::test_get_op_champions - TypeError: '<=' not supported between instances of 'Arrow' and 'datetime.date'

Based on my assessment, this error seems to be a bug. However, if I am missing something, I would appreciate it if you could let me know what it might be.

Let me know if you need any additional information.
Thank you.

@sdkim96 sdkim96 changed the title cass.get_version() signature mismatches with Patch.from_date() TypeError in cass.get_version() due to datetime.date and Arrow type mismatch in Patch.from_date() Nov 2, 2024
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

No branches or pull requests

1 participant