From 87004ead98e92007cbcbdab60c3e3cc771b06da7 Mon Sep 17 00:00:00 2001 From: "Arjun G. Menon" Date: Fri, 22 Nov 2024 23:47:15 -0500 Subject: [PATCH] Allows for checking whether page.some_property exists more easily, without hasattr. --- alteza/fs.py | 4 ++++ test_content/sectionK/sectionM/index.py.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/alteza/fs.py b/alteza/fs.py index b5a9775..2ec72e5 100644 --- a/alteza/fs.py +++ b/alteza/fs.py @@ -296,6 +296,10 @@ def gitFirstAuthDate(self) -> Optional[date]: return None return None + def __getattr__(self, attr: str) -> None: + """Allows for checking whether page.some_property exists more easily (without `hasattr`).""" + return None + class PyPageNode(PageNode): def __init__(self, parent: Optional[DirNode], dirPath: str, fileName: str) -> None: diff --git a/test_content/sectionK/sectionM/index.py.html b/test_content/sectionK/sectionM/index.py.html index 3bd4422..40fad45 100644 --- a/test_content/sectionK/sectionM/index.py.html +++ b/test_content/sectionK/sectionM/index.py.html @@ -23,7 +23,7 @@

{{file.title}} {{ - if hasattr(file, 'x1y'): + if file.x1y: write('   ' + file.x1y) }}