From 4e0f8038b6f88812406f340edbf80d65c043472c Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Sat, 6 Mar 2021 01:33:22 -0800 Subject: [PATCH] Add special globals module. Disallow untyped definitions. Organize imports from VS Code. Enable all runtime warnings. --- .mypy.ini | 1 + .vscode/settings.json | 6 +++++- g.py | 7 +++++++ main.py | 25 ++++++++++++++++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 g.py diff --git a/.mypy.ini b/.mypy.ini index 0971184..52ae442 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -4,6 +4,7 @@ warn_unused_configs = True disallow_any_generics = True disallow_subclassing_any = True disallow_untyped_calls = True +disallow_untyped_defs = True disallow_incomplete_defs = True check_untyped_defs = True disallow_untyped_decorators = True diff --git a/.vscode/settings.json b/.vscode/settings.json index 10d5722..3b5a339 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,6 @@ "python.linting.mypyEnabled": true, "python.linting.flake8Enabled": true, "python.linting.mypyArgs": [ - "--strict", "--ignore-missing-imports", "--follow-imports=silent", "--show-column-numbers" @@ -14,4 +13,9 @@ "editor.rulers": [ 120 ], + "[python]": { + "editor.codeActionsOnSave": { + "source.organizeImports": true + } + }, } diff --git a/g.py b/g.py new file mode 100644 index 0000000..37bae6a --- /dev/null +++ b/g.py @@ -0,0 +1,7 @@ +"""Shorthand globals module. For sharing mutable objects across modules. + +This is for organization and has no special effects. +""" +import tcod + +context: tcod.context.Context # Global context diff --git a/main.py b/main.py index c367691..5ddfe8a 100644 --- a/main.py +++ b/main.py @@ -1,19 +1,38 @@ #!/usr/bin/env python3 +"""Main module. + +Run this module from Python to start this program. +""" +import sys +import warnings + import tcod +import g + +SCREEN_WIDTH = 1280 +SCREEN_HEIGHT = 720 + +CONSOLE_WIDTH = SCREEN_WIDTH // 12 +CONSOLE_HEIGHT = SCREEN_HEIGHT // 12 + def main() -> None: """Main entrypoint.""" tileset = tcod.tileset.load_tilesheet("Alloy_curses_12x12.png", 16, 16, tcod.tileset.CHARMAP_CP437) - console = tcod.console.Console(1280 // 12, 720 // 12, order="C") - with tcod.context.new(width=1280, height=720, tileset=tileset) as context: + with tcod.context.new(width=SCREEN_WIDTH, height=SCREEN_HEIGHT, tileset=tileset) as g.context: while True: + # Rendering. + console = tcod.console.Console(CONSOLE_WIDTH, CONSOLE_HEIGHT, order="C") console.print(0, 0, "Hello World") - context.present(console, integer_scaling=True) + g.context.present(console, integer_scaling=True) + # Handle input. for event in tcod.event.wait(): if isinstance(event, tcod.event.Quit): raise SystemExit() if __name__ == "__main__": + if not sys.warnoptions: + warnings.simplefilter("default") # Enable all runtime warnings. main()