From 29c6a92f61035e48a4a1b992aa3cceecbfb8bb1e Mon Sep 17 00:00:00 2001 From: Jaideep Singh Date: Sun, 24 May 2026 17:43:06 -0400 Subject: [PATCH 1/3] fix: use EAFP try/except for os.getegid/geteuid in stat() (issue #177) Replace LBYL platform check with EAFP try/except AttributeError pattern. os.getegid() and os.geteuid() are unavailable on Windows and other non-POSIX platforms (e.g. WASI), raising AttributeError. Rather than checking the platform up front, wrap the assignments in a try/except block so group_access and user_access are simply omitted when the underlying OS calls are not available. Closes #177 --- src/celpy/__main__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/celpy/__main__.py b/src/celpy/__main__.py index 3b792db..2e4ff4a 100644 --- a/src/celpy/__main__.py +++ b/src/celpy/__main__.py @@ -253,8 +253,12 @@ def stat(path: Union[Path, str]) -> Optional[celtypes.MapType]: "st_ino": celtypes.IntType(status.st_ino), "st_nlink": celtypes.IntType(status.st_nlink), "st_size": celtypes.IntType(status.st_size), - "group_access": celtypes.BoolType(status.st_gid == os.getegid()), - "user_access": celtypes.BoolType(status.st_uid == os.geteuid()), + } + try: + data["group_access"] = celtypes.BoolType(status.st_gid == os.getegid()) + data["user_access"] = celtypes.BoolType(status.st_uid == os.geteuid()) + except AttributeError: + pass } # From mode File type: From 8b6d2bc3543ee198e0a556117dd30526aed89d67 Mon Sep 17 00:00:00 2001 From: Jaideep Singh Date: Sun, 24 May 2026 17:48:53 -0400 Subject: [PATCH 2/3] fix: remove stray closing brace causing mypy syntax error --- src/celpy/__main__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/celpy/__main__.py b/src/celpy/__main__.py index 2e4ff4a..8fae4bf 100644 --- a/src/celpy/__main__.py +++ b/src/celpy/__main__.py @@ -259,7 +259,6 @@ def stat(path: Union[Path, str]) -> Optional[celtypes.MapType]: data["user_access"] = celtypes.BoolType(status.st_uid == os.geteuid()) except AttributeError: pass - } # From mode File type: # - block, character, directory, regular, symbolic link, named pipe, socket From 0fb1d19ef5ebcefba390039d35636dbef620271b Mon Sep 17 00:00:00 2001 From: Jaideep Singh Date: Sun, 24 May 2026 17:52:06 -0400 Subject: [PATCH 3/3] fix: correct indentation of closing brace for ruff format --- src/celpy/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/celpy/__main__.py b/src/celpy/__main__.py index 8fae4bf..c6d46c8 100644 --- a/src/celpy/__main__.py +++ b/src/celpy/__main__.py @@ -253,7 +253,7 @@ def stat(path: Union[Path, str]) -> Optional[celtypes.MapType]: "st_ino": celtypes.IntType(status.st_ino), "st_nlink": celtypes.IntType(status.st_nlink), "st_size": celtypes.IntType(status.st_size), - } + } try: data["group_access"] = celtypes.BoolType(status.st_gid == os.getegid()) data["user_access"] = celtypes.BoolType(status.st_uid == os.geteuid())