[Core] Support already loaded packages in [p]load (#2116)

This commit is contained in:
El Laggron
2018-10-07 23:18:28 +02:00
committed by Toby Harradine
parent ee7e8aa782
commit 76bbcf2f8c
4 changed files with 124 additions and 97 deletions

16
redbot/core/errors.py Normal file
View File

@@ -0,0 +1,16 @@
import importlib.machinery
class RedError(Exception):
"""Base error class for Red-related errors."""
class PackageAlreadyLoaded(RedError):
"""Raised when trying to load an already-loaded package."""
def __init__(self, spec: importlib.machinery.ModuleSpec, *args, **kwargs):
super().__init__(*args, **kwargs)
self.spec: importlib.machinery.ModuleSpec = spec
def __str__(self) -> str:
return f"There is already a package named {self.spec.name.split('.')[-1]} loaded"