Skip to content

Commit

Permalink
fix: bubble BaseComponent instantiation errors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
percevalw committed Nov 28, 2024
1 parent 0299401 commit 45e0234
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Seed random states (instead of using `random.RandomState()`) when shuffling in data readers : this is important for
1. reproducibility
2. in multiprocessing mode, ensure that the same data is shuffled in the same way in all workers
- Bubble BaseComponent instantiation errors correctly

## v0.14.0 (2024-11-14)

Expand Down
26 changes: 16 additions & 10 deletions edsnlp/pipes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ def __call__(cls, nlp=inspect.Signature.empty, *args, **kwargs):
# If this component is missing the nlp argument, we curry it with the
# provided arguments and return a CurriedFactory object.
sig = inspect.signature(cls.__init__)
bound = sig.bind_partial(None, nlp, *args, **kwargs)
bound.arguments.pop("self", None)
if (
"nlp" in sig.parameters
and sig.parameters["nlp"].default is sig.empty
and bound.arguments.get("nlp", sig.empty) is sig.empty
):
return CurriedFactory(cls, bound.arguments)
if nlp is inspect.Signature.empty:
bound.arguments.pop("nlp", None)
try:
bound = sig.bind_partial(None, nlp, *args, **kwargs)
bound.arguments.pop("self", None)
if (
"nlp" in sig.parameters
and sig.parameters["nlp"].default is sig.empty
and bound.arguments.get("nlp", sig.empty) is sig.empty
):
return CurriedFactory(cls, bound.arguments)
if nlp is inspect.Signature.empty:
bound.arguments.pop("nlp", None)
except TypeError: # pragma: no cover
if nlp is inspect.Signature.empty:
super().__call__(*args, **kwargs)
else:
super().__call__(nlp, *args, **kwargs)
return super().__call__(**bound.arguments)


Expand Down

0 comments on commit 45e0234

Please sign in to comment.