diff --git a/discord/__init__.py b/discord/__init__.py index 1e74cf91..818abc4a 100644 --- a/discord/__init__.py +++ b/discord/__init__.py @@ -68,7 +68,6 @@ class VersionInfo(NamedTuple): releaselevel: Literal["alpha", "beta", "candidate", "final"] serial: int - version_info: VersionInfo = VersionInfo(major=2, minor=0, micro=0, releaselevel='alpha', serial=0) logging.getLogger(__name__).addHandler(logging.NullHandler()) diff --git a/discord/ext/commands/cog.py b/discord/ext/commands/cog.py index 9931557d..3d3dc1c0 100644 --- a/discord/ext/commands/cog.py +++ b/discord/ext/commands/cog.py @@ -208,7 +208,7 @@ class Cog(metaclass=CogMeta): for command in self.__cog_commands__: setattr(self, command.callback.__name__, command) parent = command.parent - if parent is not None: + if parent: # Get the latest parent reference parent = lookup[parent.qualified_name] # type: ignore @@ -230,7 +230,7 @@ class Cog(metaclass=CogMeta): This does not include subcommands. """ - return [c for c in self.__cog_commands__ if c.parent is None] + return [c for c in self.__cog_commands__ if not c.parent] @property def qualified_name(self) -> str: diff --git a/discord/ext/json/__init__.py b/discord/ext/json/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/discord/ext/json/types.py b/discord/ext/json/types.py new file mode 100644 index 00000000..076afb1b --- /dev/null +++ b/discord/ext/json/types.py @@ -0,0 +1,95 @@ +import json + +from typing import Union, Any + +class Serializer: + def bind_file(self, file:str): + """Bind file to be serialized(loaded or dumped)""" + + self.file = file + + async def load(self, content:str): + raise NotImplementedError("Serializer has to be implemented!") + + async def dump(self): + raise NotImplementedError("Serializer hasn't been implemented") + +class File: + def __init__(self, path:str): + """ + Initialize a file. + + ======= + + path `str` : + + path to the file + """ + + self.path : str = path + + @staticmethod + def construct(path:str): + """ + Construct a File object statically + """ + + if not isinstance(path, str): + raise TypeError(f"Expected path to be type str, got {type(path)} instead.") + + return File(path) + + async def access(self, mode:str): + """ + Open object to access file. Don't use this in your code. + """ + + if not isinstance(mode, str): + raise TypeError(f"Expected mode to be type str, got {type(mode)} instead.") + + return open(self.path, mode) + + async def open_writer(self): + """Open plain writer for file""" + + return await self.access("w+") + + async def open_reader(self): + """Open plain reader for file""" + + return await self.access("r+") + + async def open_binary_writer(self): + """Open binary writer for file""" + + return await self.access("wb+") + + async def open_binary_reader(self): + """Open binary reader for file""" + + return await self.access("rb+") + + async def read_contents(self, binary=False) -> Union[str, bytes]: + """ + Dump out file contents + ====== + + binary `bool` (optional): + + Set to False normally. Controls whether to read file as binary or read as normal text. + """ + + reader = None # initialize + + if binary: + reader = await self.open_binary_reader() + else: + reader = await self.open_reader() + + contents = reader.read() + + reader.close() # safely close file + + return contents + + async def serialize(self, serializer:Serializer) -> Union[Any]: