forked from OpenBB-finance/OpenBB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - Custom deprecation (OpenBB-finance#6005)
* custom deprecation * custom deprecation * using the new deprecation * custom deprecation on the package builder * remove comment * ruff * black * static assets * tests * using parametrization instead * test for deprecated endpoints (OpenBB-finance#6014) * Deprecation warning on the reference docs (OpenBB-finance#6015) * typo/fix * bring back methods needed for markdown generation * add deprecation warning to docs * contributor docs for deprecating endpoints - tks @deeleeramone * small changes on publishing procedure per @the-praxs * moving the deprecation summary class to deprecation file instead * explanation on class variables * Update website/content/platform/development/contributor-guidelines/deprecating_endpoints.md Co-authored-by: Pratyush Shukla <[email protected]> * Update website/content/platform/development/contributor-guidelines/deprecating_endpoints.md Co-authored-by: Pratyush Shukla <[email protected]> * Update website/content/platform/development/contributor-guidelines/deprecating_endpoints.md Co-authored-by: Pratyush Shukla <[email protected]> * Update openbb_platform/openbb/package/index.py Co-authored-by: Pratyush Shukla <[email protected]> * Update website/content/platform/development/contributor-guidelines/deprecating_endpoints.md Co-authored-by: Pratyush Shukla <[email protected]> * Update website/content/platform/development/contributor-guidelines/deprecating_endpoints.md Co-authored-by: Pratyush Shukla <[email protected]> * deprecating on 4.3 instead @the-praxs --------- Co-authored-by: Igor Radovanovic <[email protected]> Co-authored-by: Pratyush Shukla <[email protected]>
- Loading branch information
1 parent
f4890b2
commit 3c36b79
Showing
13 changed files
with
353 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
OpenBB-specific deprecation warnings. | ||
This implementation was inspired from Pydantic's specific warnings and modified to suit OpenBB's needs. | ||
""" | ||
|
||
from typing import Optional, Tuple | ||
|
||
|
||
class DeprecationSummary(str): | ||
"""A string subclass that can be used to store deprecation metadata.""" | ||
|
||
def __new__(cls, value, metadata): | ||
"""Create a new instance of the class.""" | ||
obj = str.__new__(cls, value) | ||
obj.metadata = metadata | ||
return obj | ||
|
||
|
||
class OpenBBDeprecationWarning(DeprecationWarning): | ||
""" | ||
A OpenBB specific deprecation warning. | ||
This warning is raised when using deprecated functionality in OpenBB. It provides information on when the | ||
deprecation was introduced and the expected version in which the corresponding functionality will be removed. | ||
Attributes | ||
---------- | ||
message: Description of the warning. | ||
since: Version in what the deprecation was introduced. | ||
expected_removal: Version in what the corresponding functionality expected to be removed. | ||
""" | ||
|
||
# The choice to use class variables is based on the potential for extending the class in future developments. | ||
# Example: launching Platform V5 and decide to create a subclimagine we areass named OpenBBDeprecatedSinceV4, | ||
# which inherits from OpenBBDeprecationWarning. In this subclass, we would set since=4.X and expected_removal=5.0. | ||
# It's important for these values to be defined at the class level, rather than just at the instance level, | ||
# to ensure consistency and clarity in our deprecation warnings across the platform. | ||
|
||
message: str | ||
since: Tuple[int, int] | ||
expected_removal: Tuple[int, int] | ||
|
||
def __init__( | ||
self, | ||
message: str, | ||
*args: object, | ||
since: Tuple[int, int], | ||
expected_removal: Optional[Tuple[int, int]] = None, | ||
) -> None: | ||
super().__init__(message, *args) | ||
self.message = message.rstrip(".") | ||
self.since = since | ||
self.expected_removal = expected_removal or (since[0] + 1, 0) | ||
self.long_message = ( | ||
f"{self.message}. Deprecated in OpenBB Platform V{self.since[0]}.{self.since[1]}" | ||
f" to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}." | ||
) | ||
|
||
def __str__(self) -> str: | ||
"""Return the warning message.""" | ||
return self.long_message |
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
Oops, something went wrong.