Skip to content

Commit 0fa247d

Browse files
cpraschlpointan
authored andcommitted
#54 Fixing tox warnings
1 parent 006fd35 commit 0fa247d

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/geofiles/reader/geo_obj_reader.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ def _read(self, file: Iterable[str]) -> GeoObjectFile:
8181
elif new_level < current_level:
8282
while new_level < current_level:
8383
current_level -= 1
84-
current_parent = current_parent.parent
84+
if (
85+
current_parent is not None
86+
and current_parent.parent is not None
87+
):
88+
current_parent = current_parent.parent
8589
current_level = new_level
8690
# check if the current line defines the coordinate reference system
8791
elif trimmed.startswith("crs "):

src/geofiles/writer/geo_obj_writer.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC
22
from io import TextIOWrapper
3-
from typing import Any, List, Set, Dict
3+
from typing import Any, Dict, List, Set
44

55
from geofiles.domain.geo_object import GeoObject
66
from geofiles.domain.geo_object_file import GeoObjectFile
@@ -96,7 +96,7 @@ def _write(
9696

9797
# find all root nodes
9898
roots = []
99-
parents = dict()
99+
parents: Dict[str, List[GeoObject]] = dict()
100100
for geoobject in data.objects:
101101
if geoobject.parent is not None:
102102
siblings = parents.get(geoobject.parent.name)
@@ -107,12 +107,22 @@ def _write(
107107
else:
108108
roots.append(geoobject)
109109

110-
used = set()
110+
used: Set[str] = set()
111111
for geoobject in roots:
112-
self._write_geoobject(geoobject, geo_referenced, file, write_binary, used, parents, 0)
112+
self._write_geoobject(
113+
geoobject, geo_referenced, file, write_binary, used, parents, 0
114+
)
113115

114-
def _write_geoobject(self, geoobject: GeoObject, geo_referenced: bool, file: TextIOWrapper, write_binary: bool,
115-
used: Set[str], parents: Dict[str, List[GeoObject]], level: int) -> None:
116+
def _write_geoobject(
117+
self,
118+
geoobject: GeoObject,
119+
geo_referenced: bool,
120+
file: TextIOWrapper,
121+
write_binary: bool,
122+
used: Set[str],
123+
parents: Dict[str, List[GeoObject]],
124+
level: int,
125+
) -> None:
116126
"""
117127
Help method for writing a geoobject
118128
:param geoobject: to be written
@@ -152,9 +162,7 @@ def _write_geoobject(self, geoobject: GeoObject, geo_referenced: bool, file: Tex
152162
self._write_to_file(file, "/", write_binary)
153163

154164
if contains_textures:
155-
self._write_to_file(
156-
file, f.texture_coordinates[i], write_binary
157-
)
165+
self._write_to_file(file, f.texture_coordinates[i], write_binary)
158166

159167
if contains_normals:
160168
self._write_to_file(file, "/", write_binary)
@@ -171,7 +179,9 @@ def _write_geoobject(self, geoobject: GeoObject, geo_referenced: bool, file: Tex
171179
if geo_referenced:
172180
self._write_to_file(file, f"h {curr_level}", write_binary, True)
173181
for child in children:
174-
self._write_geoobject(child, geo_referenced, file, write_binary, used, parents, curr_level)
182+
self._write_geoobject(
183+
child, geo_referenced, file, write_binary, used, parents, curr_level
184+
)
175185

176186
def _write_transformation(
177187
self, geoobj: GeoObject, file: TextIOWrapper, write_binary: bool

tests/geofiles/writer/test_geo_obj_writer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ def test_write7(self) -> None:
8989
converter = OriginConverter()
9090
origin = converter.to_origin(data)
9191

92-
self._test_write(
93-
origin, "object_hierarchy" + self.get_writer().get_file_type()
94-
)
92+
self._test_write(origin, "object_hierarchy" + self.get_writer().get_file_type())
9593

9694
def test_write_local(self) -> None:
9795
data = self.get_local_cube()

0 commit comments

Comments
 (0)