Improve handling of custom objects in BP.insert/replace_bot#2151
Improve handling of custom objects in BP.insert/replace_bot#2151Bibo-Joshi merged 7 commits intomasterfrom
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 |
|
|
||
| @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.
| def replace_bot(cls, obj: object) -> object: # pylint: disable=R0911 | |
| def replace_bot(cls, obj: object) -> object: |
There was a problem hiding this comment.
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.
| 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.
| except Exception: | |
| except Exception: # pylint: disable=R0911 |
Poolitzer
left a comment
There was a problem hiding this comment.
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