From e79a8b9b870df04221b503c74c2d13a745164e17 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sat, 27 Jul 2024 01:15:22 -0600 Subject: [PATCH] worked out the rest of the pyright errors --- src/dragonglass/tree.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/dragonglass/tree.py b/src/dragonglass/tree.py index eaaef6b..5edcf50 100644 --- a/src/dragonglass/tree.py +++ b/src/dragonglass/tree.py @@ -27,6 +27,18 @@ class SourceNode: def __str__(self) -> str: return f"SourceNode({self._path}, {self._is_dir}) [is_md={self._is_md}]" + @property + def is_dir(self) -> bool: + return self._is_dir + + @property + def is_md(self) -> bool: + return self._is_md + + @property + def path(self) -> Path: + return self._path + def link_target(self, prefix: str = "/") -> str: xpath = self._path.with_suffix('.html') if self._is_md else self._path return urlquote(prefix + xpath.as_posix()) @@ -74,25 +86,24 @@ class SourceIndex: self._byname: dict[str, SourceNode] = {} self._byalias: dict[str, SourceNode] = {} for node in nodelist: - if node._is_dir: + if node.is_dir: continue - if node._is_md: - tmp = node._path.with_suffix('') + if node.is_md: + tmp = node.path.with_suffix('') key = tmp.name if key not in self._byname: self._byname[key] = node self._byname[tmp.as_posix()] = node if node.metadata: - aliases = node.metadata.get('aliases', []) - if isinstance(aliases, list): - for alias in aliases: - if alias not in self._byalias: - self._byalias[alias] = node + aliases: list[str] = node.metadata.get('aliases', []) + for alias in aliases: + if alias not in self._byalias: + self._byalias[alias] = node else: - key = node._path.name + key = node.path.name if key not in self._byname: self._byname[key] = node - self._byname[node._path.as_posix()] = node + self._byname[node.path.as_posix()] = node def lookup(self, reference: str) -> tuple[SourceNode | None, str | None]: if reference in self._byname: