SatelCreative / spylib

A library to facilitate interfacing with Shopify's API
https://satelcreative.github.io/spylib
MIT License
3 stars 2 forks source link

:sparkles: Remove default API version and make it manual input #183

Closed ponty33 closed 1 year ago

ponty33 commented 1 year ago

close #173

ponty33 commented 1 year ago

I will answer 2 first, yes, it just doesn't work. There are something about ABC behavior that I don't under stand, but I couldn't make it work when writing test for it If 2 is not doable, the only work around I can think of is enter it in the arg If you use the same constant such as API_VERSION='2023-04' in the code you can ensure it's always using the same version in the code. I know it's not pretty, but since simply assign doesn't work then I don't know what else I can do.

hillairet commented 1 year ago

I don't see the problem here:

from abc import ABC, abstractmethod
from typing import ClassVar, Optional

from pydantic import BaseModel

class Token(ABC, BaseModel):
    store_name: str

    api_version: ClassVar[Optional[str]] = None

class OfflineTokenABC(Token, ABC):
    @abstractmethod
    def version(self):
        pass

class MyOfflineTokenABC(OfflineTokenABC):
    api_version: ClassVar[Optional[str]] = '2023-04'

    def version(self):
        print(self.api_version)

offline = MyOfflineTokenABC(store_name='potato')
print(offline.api_version)
offline.version()

MyOfflineTokenABC.api_version = '2024-04'
print(offline.api_version)
print(Token.api_version)

Output as expected:

2023-04
2023-04
2024-04
None

So two ways of setting the api_version. Maybe I'm not testing your problem though ...

ponty33 commented 1 year ago

I found where I did wrong... When I wrote the test, I make the load function returning another class that doesn't have API version :sweat: No wonder the version is nowhere to be found :disappointed: