New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve handling of custom objects in BP.insert/replace_bot #2151
Conversation
@Bibo-Joshi Didn't look at the code yet, but just from the PR description, I wonder if we should also warn on objects which can't be copied. Another option is to mandate that all objects must adhere to a certain interface. (I tend to like that one better) |
There's another small bug, that should be fixed in this PR: https://t.me/pythontelegrambotgroup/396509 TL;DR, in |
@@ -128,12 +128,12 @@ def set_bot(self, bot: Bot) -> None: | |||
self.bot = bot | |||
|
|||
@classmethod | |||
def replace_bot(cls, obj: object) -> object: | |||
def replace_bot(cls, obj: object) -> object: # pylint: disable=R0911 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def replace_bot(cls, obj: object) -> object: # pylint: disable=R0911 | |
def replace_bot(cls, obj: object) -> object: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pylint complains about the methods having too many return statements, so moving that line to the except Exception
will make the test fail …
new_obj = copy(obj) | ||
try: | ||
new_obj = copy(obj) | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except Exception: | |
except Exception: # pylint: disable=R0911 |
new_obj = copy(obj) | ||
try: | ||
new_obj = copy(obj) | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except Exception: | |
except Exception: # pylint: disable=R0911 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like what we talked about.
if an object can't be copied, they're probably something special and don't contain a Bot instance. Therefore, those will now just be skipped.
Note: I noticed the latter while testing the changes on a personal project, where I have locks in some objects that have a custom pickle behaviour but not a custom copy behaivour