From 32f905406790d261241bf30aec6b8e193b96efd3 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 6 Dec 2022 12:52:44 +0100 Subject: [PATCH] prc: Add `ConfigVariableFilename.__fspath__()` Fixes #1406 --- dtool/src/prc/configVariableFilename.I | 11 +++++++++++ dtool/src/prc/configVariableFilename.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/dtool/src/prc/configVariableFilename.I b/dtool/src/prc/configVariableFilename.I index 51013ddfcf..e4bb29faae 100644 --- a/dtool/src/prc/configVariableFilename.I +++ b/dtool/src/prc/configVariableFilename.I @@ -218,6 +218,17 @@ set_word(size_t n, const Filename &value) { set_string_word(n, value); } +/** + * Allows a ConfigVariableFilename object to be passed to any Python function + * that accepts an os.PathLike object. + * + * @since 1.10.13 + */ +INLINE std::wstring ConfigVariableFilename:: +__fspath__() const { + return get_ref_value().to_os_specific_w(); +} + /** * Returns the variable's value, as a reference into the config variable * itself. This is the internal method that implements get_value(), which diff --git a/dtool/src/prc/configVariableFilename.h b/dtool/src/prc/configVariableFilename.h index 7537e22117..762435201f 100644 --- a/dtool/src/prc/configVariableFilename.h +++ b/dtool/src/prc/configVariableFilename.h @@ -60,6 +60,8 @@ PUBLISHED: INLINE Filename get_word(size_t n) const; INLINE void set_word(size_t n, const Filename &value); + INLINE std::wstring __fspath__() const; + private: void reload_cache(); INLINE const Filename &get_ref_value() const;