Skip to content

Restart the library - #209

Draft
TheUntraceable wants to merge 380 commits into
masterfrom
rewrite
Draft

Restart the library#209
TheUntraceable wants to merge 380 commits into
masterfrom
rewrite

Conversation

@TheUntraceable

@TheUntraceable TheUntraceable commented Dec 21, 2022

Copy link
Copy Markdown
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

Sigmanificient commented Dec 22, 2022

Copy link
Copy Markdown
Member

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

Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/flags.py
Comment thread EpikCord/flags.py
Comment thread EpikCord/flags.py Outdated
Comment thread EpikCord/flags.py Outdated
Comment thread EpikCord/utils/loose.py Outdated
Comment thread EpikCord/client/client.py Outdated
Comment thread EpikCord/exceptions.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/ext/tasks.py
Comment thread EpikCord/ext/tasks.py Outdated
Comment thread EpikCord/ext/tasks.py Outdated
@Sigmanificient

Copy link
Copy Markdown
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
Copy Markdown
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.

@EmmmaTech

Copy link
Copy Markdown

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.

@EmmmaTech EmmmaTech left a comment

Copy link
Copy Markdown

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.

Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http_client.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated

@EmmmaTech EmmmaTech left a comment

Copy link
Copy Markdown

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.

Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/utils/loose.py
Comment thread EpikCord/utils/types.py Outdated
Comment thread EpikCord/client/http.py Outdated
@Sigmanificient

Copy link
Copy Markdown
Member

__all__ are not set

Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/client/http.py Outdated
Comment thread EpikCord/utils/loose.py Outdated
Comment thread EpikCord/utils/loose.py Outdated
Comment thread EpikCord/utils/loose.py Outdated

@Sigmanificient Sigmanificient left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any is evil.

@Sigmanificient Sigmanificient left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any is evil.

Comment thread EpikCord/client/buckets.py Outdated
...

def clear(self):
"""Pretends to clear the Event"""

Copy link
Copy Markdown
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
Copy Markdown
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.

@Sigmanificient Sigmanificient Jan 23, 2023

Copy link
Copy Markdown
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.



class MockBucket:
"""A mock bucket that does nothing."""

Copy link
Copy Markdown
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
Copy Markdown
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.

"""Pretends to wait for the Event to be set"""
...

def clear(self):

Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point

Comment thread EpikCord/client/buckets.py Outdated
Comment thread EpikCord/client/client.py Outdated

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
Copy Markdown
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
Copy Markdown
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 thread EpikCord/client/client.py
Comment on lines +11 to +14
token: str
The token of the bot.
intents: Intents
The intents of the bot.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread EpikCord/client/http.py Outdated
Comment on lines +63 to +64
method: str
The method of the route.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@Sigmanificient Sigmanificient Jan 23, 2023

Copy link
Copy Markdown
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.

Comment thread EpikCord/client/http.py Outdated
method = response.method
bucket_key: str = f"{method}:{url}"

bucket: Optional[Union[Bucket, TopLevelBucket]] = None

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread EpikCord/client/http.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@TheUntraceable TheUntraceable Jan 23, 2023

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@Sigmanificient

Copy link
Copy Markdown
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.

5 participants