mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 17:36:15 +00:00
Fix typing issues and improve typing completeness across the library
Co-authored-by: Danny <Rapptz@users.noreply.github.com> Co-authored-by: Josh <josh.ja.butt@gmail.com>
This commit is contained in:
@ -23,7 +23,8 @@ DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import Dict, Optional
|
||||
|
||||
from typing import Optional, Tuple, Dict
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
@ -35,7 +36,7 @@ import aiohttp
|
||||
import platform
|
||||
|
||||
|
||||
def show_version():
|
||||
def show_version() -> None:
|
||||
entries = []
|
||||
|
||||
entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info))
|
||||
@ -52,7 +53,7 @@ def show_version():
|
||||
print('\n'.join(entries))
|
||||
|
||||
|
||||
def core(parser, args):
|
||||
def core(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None:
|
||||
if args.version:
|
||||
show_version()
|
||||
|
||||
@ -185,7 +186,7 @@ _base_table.update((chr(i), None) for i in range(32))
|
||||
_translation_table = str.maketrans(_base_table)
|
||||
|
||||
|
||||
def to_path(parser, name, *, replace_spaces=False):
|
||||
def to_path(parser: argparse.ArgumentParser, name: str, *, replace_spaces: bool = False) -> Path:
|
||||
if isinstance(name, Path):
|
||||
return name
|
||||
|
||||
@ -223,7 +224,7 @@ def to_path(parser, name, *, replace_spaces=False):
|
||||
return Path(name)
|
||||
|
||||
|
||||
def newbot(parser, args):
|
||||
def newbot(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None:
|
||||
new_directory = to_path(parser, args.directory) / to_path(parser, args.name)
|
||||
|
||||
# as a note exist_ok for Path is a 3.5+ only feature
|
||||
@ -265,7 +266,7 @@ def newbot(parser, args):
|
||||
print('successfully made bot at', new_directory)
|
||||
|
||||
|
||||
def newcog(parser, args):
|
||||
def newcog(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None:
|
||||
cog_dir = to_path(parser, args.directory)
|
||||
try:
|
||||
cog_dir.mkdir(exist_ok=True)
|
||||
@ -299,7 +300,7 @@ def newcog(parser, args):
|
||||
print('successfully made cog at', directory)
|
||||
|
||||
|
||||
def add_newbot_args(subparser):
|
||||
def add_newbot_args(subparser: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
||||
parser = subparser.add_parser('newbot', help='creates a command bot project quickly')
|
||||
parser.set_defaults(func=newbot)
|
||||
|
||||
@ -310,7 +311,7 @@ def add_newbot_args(subparser):
|
||||
parser.add_argument('--no-git', help='do not create a .gitignore file', action='store_true', dest='no_git')
|
||||
|
||||
|
||||
def add_newcog_args(subparser):
|
||||
def add_newcog_args(subparser: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
||||
parser = subparser.add_parser('newcog', help='creates a new cog template quickly')
|
||||
parser.set_defaults(func=newcog)
|
||||
|
||||
@ -322,7 +323,7 @@ def add_newcog_args(subparser):
|
||||
parser.add_argument('--full', help='add all special methods as well', action='store_true')
|
||||
|
||||
|
||||
def parse_args():
|
||||
def parse_args() -> Tuple[argparse.ArgumentParser, argparse.Namespace]:
|
||||
parser = argparse.ArgumentParser(prog='discord', description='Tools for helping with discord.py')
|
||||
parser.add_argument('-v', '--version', action='store_true', help='shows the library version')
|
||||
parser.set_defaults(func=core)
|
||||
@ -333,7 +334,7 @@ def parse_args():
|
||||
return parser, parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
parser, args = parse_args()
|
||||
args.func(parser, args)
|
||||
|
||||
|
Reference in New Issue
Block a user