-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Deprecate
row
parameter of Stream.post_process
in favor…
… or `record` Take 2 for #966
- Loading branch information
1 parent
fe5a01b
commit c8f38fc
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import annotations | ||
|
||
import functools | ||
import typing as t | ||
import warnings | ||
|
||
|
||
def deprecate_row_param(func: t.Callable) -> t.Callable: | ||
@functools.wraps(func) | ||
def wrapper(*args: t.Any, **kwargs: t.Any) -> t.Any: # noqa: ANN401 | ||
if "row" in kwargs: | ||
warnings.warn( | ||
f"The 'row' parameter for '{func.__qualname__}' is deprecated. " | ||
"Use 'record' instead.", | ||
category=DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
kwargs["record"] = kwargs.pop("row") | ||
return func(*args, **kwargs) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from __future__ import annotations | ||
|
||
import warnings | ||
|
||
from singer_sdk.helpers._deprecation import deprecate_row_param | ||
|
||
|
||
class Deprecated: | ||
@deprecate_row_param | ||
def check_row(self, record): | ||
pass | ||
|
||
|
||
class StaleSubclass(Deprecated): | ||
def check_row(self, row): | ||
return super().check_row(row=row) | ||
|
||
|
||
class OkSubclass(Deprecated): | ||
def check_row(self, row): | ||
return super().check_row(row) | ||
|
||
|
||
class NewSubclass(Deprecated): | ||
def check_row(self, record): | ||
return super().check_row(record) | ||
|
||
|
||
def test_deprecated_row_parameter(): | ||
d = Deprecated() | ||
|
||
# No warning should be raised | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("error") | ||
d.check_row("test") | ||
|
||
# No warning should be raised | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("error") | ||
d.check_row(record="test") | ||
|
||
# Warning should be raised | ||
_assert_deprecation_warning(d) | ||
|
||
s = StaleSubclass() | ||
_assert_deprecation_warning(s) | ||
|
||
o = OkSubclass() | ||
# No warning should be raised | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("error") | ||
o.check_row(row="test") | ||
|
||
n = NewSubclass() | ||
# No warning should be raised | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("error") | ||
n.check_row(record="test") | ||
|
||
|
||
def _assert_deprecation_warning(instance: Deprecated): | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
instance.check_row(row="test") | ||
assert len(w) == 1 | ||
assert issubclass(w[-1].category, DeprecationWarning) | ||
assert str(w[-1].message) == ( | ||
"The 'row' parameter for 'Deprecated.check_row' is deprecated. " | ||
"Use 'record' instead." | ||
) |