You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interfaces can include concrete (non-abstract) methods that provide default implementations. These methods can be accessed directly from implementing classes without explicit implementation:
116
+
117
+
```python
118
+
classIService(Interface):
119
+
@abstractmethod
120
+
defprocess(self, data: str) -> str:
121
+
...
122
+
123
+
deflog(self, message: str) -> None:
124
+
"""Concrete method with default implementation."""
125
+
print(f"[LOG] {message}")
126
+
127
+
@classmethod
128
+
defget_version(cls) -> str:
129
+
"""Concrete class method."""
130
+
return"1.0.0"
131
+
132
+
classMyService(IService):
133
+
@implements(IService.process)
134
+
defprocess_data(self, data: str) -> str:
135
+
returnf"Processed: {data}"
136
+
137
+
service = MyService()
138
+
139
+
# Access concrete methods directly
140
+
service.log("Starting process") # Works directly
141
+
service.get_version() # Works directly
142
+
143
+
# Also accessible through interface casting
144
+
interface = service.as_interface(IService)
145
+
interface.log("Through interface") # Also works
146
+
interface.get_version() # Also works
147
+
```
148
+
112
149
### Concrete Classes
113
150
114
151
By default, partial implementations are allowed at class definition time. To enforce complete implementation:
@@ -302,6 +339,12 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
302
339
303
340
## Changelog
304
341
342
+
### 0.1.1
343
+
-**Bug Fix**: Fixed access to concrete (non-abstract) methods when using `as_interface()`
344
+
- Concrete methods in interfaces can now be properly accessed both directly and through interface casting
345
+
- Added comprehensive test coverage for concrete method access patterns
346
+
- Improved documentation with concrete method usage examples
347
+
305
348
### 0.1.0
306
349
- Initial release
307
350
- Basic interface and implementation functionality
0 commit comments