Release: 2024-10-24
PriorityCallback
now has type checking support, similar toCallback
, with type checked variants:PriorityCallback0
,PriorityCallback1
, etc (#128).UnregisterContext
is now public, meant to be used in type annotations.- Python 3.10+ is now required.
#48: New type-checker friendly
proxy = GetProxy(I, obj)
function as an alternative toproxy = I(obj)
. The latter is not accepted by type checkers in general because interfaces are protocols, which can't be instantiated.Also fixed a type-checking error with
AsssertImplements
:Only concrete class can be given where "Type[Interface]" is expected
This happens due to python/mypy#5374.
#47: Interfaces no longer check type annotations at all.
It was supported initially, but in practice this feature has shown up to be an impediment to adopting type annotations incrementally, as it discourages adding type annotations to improve existing interfaces, or annotating existing implementations without having to update the interface (and all other implementations by consequence).
It was decided to let the static type checker correctly deal with matching type annotations, as it can do so more accurately than
oop-ext
did before.
#43: Fix support for type annotated
Attribute
andReadOnlyAttribute
:class IFoo(Interface): value: int = Attribute(int)
- #41: Fix regression introduced in
1.1.0
where installing a callback usingcallback.After
orcallback.Before
would make a method no longer compliant with the signature required by its interface.
- #38: Reintroduce
extra_args
argument toCallback._GetKey
, so subclasses can make use of it. - #36: Fix regression introduced in
1.1.0
whereAbstract
andImplements
decorators could no longer be used in interfaces implementations.
#25:
oop-ext
now includes inline type annotations and exposes them to user programs.If you are running a type checker such as mypy on your tests, you may start noticing type errors indicating incorrect usage. If you run into an error that you believe to be incorrect, please let us know in an issue.
The types were developed against
mypy
version 0.800.#26: New type-checked
Callback
variants,Callback0
,Callback1
,Callback2
, etc, providing type checking for all operations(calling,Register
, etc) at nearly zero runtime cost.Example:
from oop_ext.foundation.callback import Callback2 def changed(x: int, v: float) -> None: ... on_changed = Callback2[int, float]() on_changed(10, 5.25)
Fixed
Callbacks.Before
andCallbacks.After
signatures: previously their signature conveyed that they supported multiple callbacks, but it was a mistake which would break callers because every parameter after the 2nd would be considered thesender_as_parameter
parameter, which was forwarded toAfter
andBefore
functions of the_shortcuts.py
module.
Callbacks
can be used as context manager, which provides aRegister(callback, function)
, which automatically unregisters all functions when the context manager ends.Callback.Register(function)
now returns an object with aUnregister()
method, which can be used to undo the register call.
- Change back the default value of
requires_declaration
toTrue
and fix an error (#22) where the cache wasn't properly cleared.
- Fixes an issue (#20) where mocked classmethods weren't considered a valid method during internal checks.
- Add optional argument
requires_declaration
so users can decide whether or not@ImplementsInterface
declarations are necessary.
- Implementations no longer need to explicitly declare that they declare an interface with
@ImplementsInterface
: the check is done implicitly (and cached) by AssertImplements and equivalent functions.
- Interface and implementation methods can no longer contain mutable defaults, as this is considered a bad practice in general.
Null
instances are now hashable.
Fix mismatching signatures when creating "interface stubs" for instances:
foo = IFoo(Foo())
- Interfaces now support keyword-only arguments.
- Remove
FunctionNotRegisteredError
exception, which has not been in use for a few years.
- Fix issues of ignored exception on nested callback.
- Fix issues and remove obsolete code.
- First release on PyPI.