diff --git a/pytiled_parser/parsers/json/tiled_map.py b/pytiled_parser/parsers/json/tiled_map.py index 977ccf0..030683c 100644 --- a/pytiled_parser/parsers/json/tiled_map.py +++ b/pytiled_parser/parsers/json/tiled_map.py @@ -126,6 +126,19 @@ def parse(file: Path) -> TiledMap: layers = [layer for layer in map_.layers if hasattr(layer, "tiled_objects")] for my_layer in layers: + # Mypy extremely hates what is going on in this whole block + # For some reason an ignore on this first for loop is causing it + # to just not care about any of the problems in here. + # However, under normal circumstances, mypy hates just about every + # line of this block. + # + # This is because we are doing some run-time modification of the attributes + # on the tiled_object class and making assumptions about things based on that. + # This is done to achieve a system where we can load-in tilesets which were + # defined in a Tiled Object Template. This is tough because we need to know what + # tilesets have been loaded in already, and use them if they have been, but then + # be able to dynamically add-in tilesets after having parsed the rest of the map. + for tiled_object in my_layer.tiled_objects: # type: ignore if hasattr(tiled_object, "new_tileset"): if tiled_object.new_tileset is not None: diff --git a/pytiled_parser/parsers/json/tileset.py b/pytiled_parser/parsers/json/tileset.py index 2a5cd35..b1cc1aa 100644 --- a/pytiled_parser/parsers/json/tileset.py +++ b/pytiled_parser/parsers/json/tileset.py @@ -49,7 +49,7 @@ RawTile = TypedDict( "objectgroup": RawLayer, }, ) -RawTile.__docs__ = """ +RawTile.__doc__ = """ The keys and their types that appear in a Tile JSON Object. """ diff --git a/pytiled_parser/parsers/tmx/layer.py b/pytiled_parser/parsers/tmx/layer.py index ba179c9..d539d67 100644 --- a/pytiled_parser/parsers/tmx/layer.py +++ b/pytiled_parser/parsers/tmx/layer.py @@ -369,3 +369,5 @@ def parse( return _parse_image_layer(raw_layer) elif type_ == "layer": return _parse_tile_layer(raw_layer) + else: + raise RuntimeError("Unknown layer type in map file!") diff --git a/pytiled_parser/parsers/tmx/properties.py b/pytiled_parser/parsers/tmx/properties.py index c2118e9..fd29543 100644 --- a/pytiled_parser/parsers/tmx/properties.py +++ b/pytiled_parser/parsers/tmx/properties.py @@ -13,7 +13,12 @@ def parse(raw_properties: etree.Element) -> Properties: for raw_property in raw_properties.findall("property"): type_ = raw_property.attrib.get("type") - value_ = raw_property.attrib.get("value") + + if "value" not in raw_property.attrib: + continue + + value_ = raw_property.attrib["value"] + if type_ == "file": value = Path(value_) elif type_ == "color": diff --git a/pytiled_parser/parsers/tmx/tiled_map.py b/pytiled_parser/parsers/tmx/tiled_map.py index c93caba..6cf5a33 100644 --- a/pytiled_parser/parsers/tmx/tiled_map.py +++ b/pytiled_parser/parsers/tmx/tiled_map.py @@ -84,7 +84,20 @@ def parse(file: Path) -> TiledMap: layers = [layer for layer in map_.layers if hasattr(layer, "tiled_objects")] for my_layer in layers: - for tiled_object in my_layer.tiled_objects: + # Mypy extremely hates what is going on in this whole block + # For some reason an ignore on this first for loop is causing it + # to just not care about any of the problems in here. + # However, under normal circumstances, mypy hates just about every + # line of this block. + # + # This is because we are doing some run-time modification of the attributes + # on the tiled_object class and making assumptions about things based on that. + # This is done to achieve a system where we can load-in tilesets which were + # defined in a Tiled Object Template. This is tough because we need to know what + # tilesets have been loaded in already, and use them if they have been, but then + # be able to dynamically add-in tilesets after having parsed the rest of the map. + + for tiled_object in my_layer.tiled_objects: # type: ignore if hasattr(tiled_object, "new_tileset"): if tiled_object.new_tileset is not None: already_loaded = None diff --git a/setup.cfg b/setup.cfg index dc44c28..d86e872 100644 --- a/setup.cfg +++ b/setup.cfg @@ -77,25 +77,10 @@ line_length=88 # Global options: [mypy] -python_version = 3.6 +python_version = 3.10 warn_unused_configs = True warn_redundant_casts = True - -# Per-module options: -[mypy-pytiled_parser.*] -disallow_any_unimported = True -disallow_any_decorated = 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 -warn_return_any = True -warn_unused_ignores = True -no_implicit_optional = True -strict_optional = True +ignore_missing_imports = True [mypy-tests.*] ignore_errors = True