Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/wrapt/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def __new__(cls, callback=None, *args, interface=..., **kwargs):
if "__anext__" in interface_attrs and "__anext__" not in class_attrs:
namespace["__anext__"] = __wrapper_anext__

if "__fspath__" in interface_attrs and "__fspath__" not in class_attrs:
namespace["__fspath__"] = __wrapper_fspath__

if (
"__length_hint__" in interface_attrs
and "__length_hint__" not in class_attrs
Expand Down
19 changes: 19 additions & 0 deletions tests/core/test_lazy_object_proxy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import os
import sys
import unittest
from pathlib import Path

import wrapt


class TestLazyObjectProxy(unittest.TestCase):

def test_pathlike_interface_is_lazy(self):
for interface in (os.PathLike, Path):
with self.subTest(interface=interface):
status = {"created": 0}

def factory():
status["created"] += 1
return Path("example.txt")

proxy = wrapt.LazyObjectProxy(factory, interface=interface)
self.assertEqual(status["created"], 0)
self.assertTrue(hasattr(type(proxy), "__fspath__"))
self.assertEqual(os.fspath(proxy), "example.txt")
self.assertEqual(status["created"], 1)
self.assertEqual(os.fspath(proxy), "example.txt")
self.assertEqual(status["created"], 1)

def test_lazy_object_proxy(self):
status = {"created": 0}

Expand Down