-
Notifications
You must be signed in to change notification settings - Fork 6
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
Large refactoring to simplify code and remove duplicate code #13
Conversation
Also fix incorrect typehinting in the return values of many functions
Also, rewrite the httpx client opening to use a context window so it'll automatically close after the action These changes also prompted the changing of many of the functions to static methods
…ns are properly raised
This commit reverts pyproject.toml to the original state
From 1.0.9
not going to lie, i'm out of time to review this pull request, so i haven't replied yet. |
That's totally fine, I made a huge pull request (large rewrite) to an old repo. I'm using my own fork for my purposes so I don't personally need the pull request merger for anything, it's really just more for other people to see the existence of my fork/branch. You can do the actual merge at your own pace. |
i understand, great, i'm glad for that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit old, but not forgotten, thank you for your PR, i appreciate it
Hello, thank you for your wonderful library. It's very well made and works well. I've written in the changelog file but I'll write it again here.
I spent some time just consolidating a lot of duplicated code:
raw()
,__repr__()
, and__str__()
, so I moved all those to a base class calledObject
and had the anilist classes derive from that. Additionally, if a class has an ID, I made aHashable
type as a subclass ofObject
which implemented__eq__()
and__hash__()
.api_query()
and had all functions call that instead.sync_client.py
file and theasync_client.py
for the purpose of having different logic in the api query step, but I moved all the steps that were the same for both files out into a third external fileclient_process.py
so they can be called equally.One change I made that technically could be breaking is I removed the mass ignoring of exceptions in the data packaging code. There were many instances of code like:
This probably isn't good because it hides errors which can lead to both complications in debugging and unintended behavior in production. For now, I left the structure of the code the same and just changed "pass" to "raise". To undo this change, one can do a substitution operation in
client_process.py
to replace "raise" back to "pass".Finally, I fixed what I believe to be an error but I'm technically not sure. In the function
get_message_activity()
python-anilist/anilist/sync_client.py
Line 1271 in a21b26b
it looks like there are two functions inside the one definition, and the function starts over with a new query call here:
python-anilist/anilist/sync_client.py
Line 1322 in a21b26b
so I split the function into
get_message_activity()
andget_message_activity_sent()
.https://github.com/r-hensley/python-anilist/blob/f9183a0656d5db8a9da68902f36dc67c355201ab/anilist/sync_client.py#L376-390
I ran all the tests and (after changing one obsolete ID in one of the tests), confirmed they all passed:
Overall, I reduced:
sync_client.py
: 1,370 lines → 390 linesasync_client.py
: 1,463 lines → 407 linesclient_process.py
(NEW): 0 lines → 703 linesTell me if you have any questions.