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

Restart the library #209

Draft
wants to merge 379 commits into
base: master
Choose a base branch
from
Draft

Restart the library #209

wants to merge 379 commits into from

Conversation

TheUntraceable
Copy link
Member

Description

The library is very messy and outdated. It needs a rewrite. It has been a few months since I have actively worked on the library, and so I don't know where exactly I am now. Restarting the library will solve all these issues.

Checklist

  • - All code changes have been tested, if any
  • - The documentation has been updated accordingly for any code changes
  • - This PR fixes an already existing issue
  • - This PR adds a new feature (new functions, methods, classes, parameters, etc.)
  • - This PR fixes a bug
  • - This PR is a breaking change (removes/renames functions, parameters etc.)
  • - This PR is NOT a code change (changes Documentation files, README.md, CONTRIBUTING.md etc.)

@TheUntraceable TheUntraceable changed the title Get back to start Restart the library Dec 21, 2022
@TheUntraceable TheUntraceable added enhancement New feature or request high priority labels Dec 21, 2022
@TheUntraceable TheUntraceable self-assigned this Dec 21, 2022
@Sigmanificient
Copy link
Member

Sigmanificient commented Dec 22, 2022

Since more changes are incoming making this a draft should be a good idea

EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/flags.py Show resolved Hide resolved
EpikCord/flags.py Show resolved Hide resolved
EpikCord/flags.py Outdated Show resolved Hide resolved
EpikCord/flags.py Outdated Show resolved Hide resolved
EpikCord/utils/loose.py Outdated Show resolved Hide resolved
EpikCord/client/client.py Outdated Show resolved Hide resolved
EpikCord/exceptions.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/ext/tasks.py Outdated Show resolved Hide resolved
EpikCord/ext/tasks.py Outdated Show resolved Hide resolved
@Sigmanificient
Copy link
Member

If you're going for a rewrite you must define strong rules from the beginning to follow. It would be nice to set a linter and ensure mypy compliance for example. Before it becames too late

@Sigmanificient Sigmanificient self-assigned this Dec 22, 2022
@TheUntraceable TheUntraceable marked this pull request as draft December 23, 2022 16:04
@TheUntraceable
Copy link
Member Author

If you're going for a rewrite you must define strong rules from the beginning to follow. It would be nice to set a linter and ensure mypy compliance for example. Before it becames too late

I was thinking of using PyRight instead, MyPy is confusing with its errors. It defaults to object when using a key that is missing in a TypedDict, PyRight does something similar iirc. I'll continue looking for a type checker.

@EmreTech
Copy link

If you're going for a rewrite you must define strong rules from the beginning to follow. It would be nice to set a linter and ensure mypy compliance for example. Before it becames too late

I was thinking of using PyRight instead, MyPy is confusing with its errors. It defaults to object when using a key that is missing in a TypedDict, PyRight does something similar iirc. I'll continue looking for a type checker.

Well you should because mypy is behind of pyright in terms of support with newer typing features.

Copy link

@EmreTech EmreTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

epikcord.client.http_client doesn't need the _client suffix because it's obvious that module defines an http client because of the name of the parent module.

EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http_client.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
Copy link

@EmreTech EmreTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're definitely not done with HTTP.

EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/utils/loose.py Show resolved Hide resolved
EpikCord/utils/types.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
@Sigmanificient
Copy link
Member

__all__ are not set

EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/client/http.py Outdated Show resolved Hide resolved
EpikCord/utils/loose.py Outdated Show resolved Hide resolved
EpikCord/utils/loose.py Outdated Show resolved Hide resolved
EpikCord/utils/loose.py Outdated Show resolved Hide resolved
Copy link
Member

@Sigmanificient Sigmanificient left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any is evil.

Copy link
Member

@Sigmanificient Sigmanificient left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any is evil.

...

def clear(self):
"""Pretends to clear the Event"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The docstring is a phrase ending in a period."
According to the pep 8, docstring should be "consistent with the docstring convention in pep 257".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a look at PEP257 and I need to do some major changes to docstrings, majorly making them commands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure on how much you should follow it, though, making docstring "a phrase ending in a period." would definitively improve them, in their consistency and clearness.

@@ -10,18 +10,26 @@


class MockBucket:
"""A mock bucket that does nothing."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it an abstract class or a protocol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alr, I'll do that soon. I was thinking about it.

async def wait(self):
"""Pretends to wait for the Event to be set"""
...

def clear(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing annotations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

EpikCord/client/buckets.py Outdated Show resolved Hide resolved
@@ -3,7 +3,27 @@


class Client:
"""The main class of EpikCord. Use this to interact with the Discord API and Gateway."""
def __init__(self, token: str, intents: Intents, *, version: int = 10):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont like magic number, it should be extracted to a final int constant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess that makes sense

Comment on lines +11 to +14
token: str
The token of the bot.
intents: Intents
The intents of the bot.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way too generic, no one want to read that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can be more specific with it. Although being that vague also isn't too bad, it's the token of your bot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great place to remind people on how to retrieve the token, (maybe as an url to a side page), the importance of not sharing it etc. Boring text, but still preventive for the few that are sage enough to take a read through it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is mean to provide the developer the core knowledge about a library in its abstract form. It is also a way to share advice on code management and good practice, optimization trick for the more pickiest.

Unfortunately, we have too many of those automatically generated docs the give you blind sentence that bring next to no information and just describe what you already know. This is the role endorsed by the argument names, not the role of a documentation. And this is why peoples are taking less and less attention to them because reading two or three time the same piece of into is exhausting.

Comment on lines 63 to 64
method: str
The method of the route.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method could be a Enum type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to have to do Route(Methods.GET, URL) for everything...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to have to do Route(Methods.GET, URL) for everything...

And this is why partials exists

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from functools import partial

GetRoute = partial(Route, method=Methods.GET)

See the partial documentation.

url = response.url
method = response.method
bucket_key: str = f"{method}:{url}"

bucket: Optional[Union[Bucket, TopLevelBucket]] = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using types that are too too much complex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is that complex? It does what it says...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By having a typehint of Optional[Union[Bucket, TopLevelBucket]] you have to deal why 2 different interfaces at the same time while being sure that you are not in a None case. This makes more guards statements that could have being avoided by having a better separation of variables, a protocol that define a middle ground interface of the two objects, or other techniques. Reducing the type will always makes the program simpler and easier to read. You dont have to clutter you mind with the correctness of the types and can focus on the code execution.

Comment on lines 236 to 239
channel_id=major_parameters.channel_id,
guild_id=major_parameters.guild_id,
webhook_id=major_parameters.webhook_id,
webhook_token=major_parameters.webhook_token
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Make TopLevelBucket Inherit from MajorParameters

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes no sense though; MajorParameters is a class that groups all of the major parameters into a single class, a TopLevelBucket is a bucket used for handling rate limits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the TopLevelBucket uses all the attributes of the MajorParameters in order to work.

Inheritance a mechanism where you can to derive a class from another class for a hierarchy of classes that share a set of attributes and methods

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the hierarchy tree for that though.

MajorParameters
      |
      |
      |
TopLevelBucket

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then use composition

@Jerry-py
Copy link
Contributor

Can't we just make a rewrite branch and add it to the milestone thing (Projects)?

@Sigmanificient
Copy link
Member

Can't we just make a rewrite branch and add it to the milestone thing (Projects)?

What a nice idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high priority
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants