Skip to content

Update setter error messages #2749

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

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions telegram/ext/_conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ def entry_points(self) -> List[Handler]:

@entry_points.setter
def entry_points(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to entry_points after initialization.')
raise AttributeError(
"You can not assign a new value to entry_points after initialization."
)

@property
def states(self) -> Dict[object, List[Handler]]:
Expand All @@ -349,7 +351,7 @@ def states(self) -> Dict[object, List[Handler]]:

@states.setter
def states(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to states after initialization.')
raise AttributeError("You can not assign a new value to states after initialization.")

@property
def fallbacks(self) -> List[Handler]:
Expand All @@ -361,7 +363,7 @@ def fallbacks(self) -> List[Handler]:

@fallbacks.setter
def fallbacks(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to fallbacks after initialization.')
raise AttributeError("You can not assign a new value to fallbacks after initialization.")

@property
def allow_reentry(self) -> bool:
Expand All @@ -370,7 +372,9 @@ def allow_reentry(self) -> bool:

@allow_reentry.setter
def allow_reentry(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to allow_reentry after initialization.')
raise AttributeError(
"You can not assign a new value to allow_reentry after initialization."
)

@property
def per_user(self) -> bool:
Expand All @@ -379,7 +383,7 @@ def per_user(self) -> bool:

@per_user.setter
def per_user(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to per_user after initialization.')
raise AttributeError("You can not assign a new value to per_user after initialization.")

@property
def per_chat(self) -> bool:
Expand All @@ -388,7 +392,7 @@ def per_chat(self) -> bool:

@per_chat.setter
def per_chat(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to per_chat after initialization.')
raise AttributeError("You can not assign a new value to per_chat after initialization.")

@property
def per_message(self) -> bool:
Expand All @@ -397,7 +401,7 @@ def per_message(self) -> bool:

@per_message.setter
def per_message(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to per_message after initialization.')
raise AttributeError("You can not assign a new value to per_message after initialization.")

@property
def conversation_timeout(
Expand All @@ -411,8 +415,8 @@ def conversation_timeout(

@conversation_timeout.setter
def conversation_timeout(self, value: object) -> NoReturn:
raise ValueError(
'You can not assign a new value to conversation_timeout after initialization.'
raise AttributeError(
"You can not assign a new value to conversation_timeout after initialization."
)

@property
Expand All @@ -422,7 +426,7 @@ def name(self) -> Optional[str]:

@name.setter
def name(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to name after initialization.')
raise AttributeError("You can not assign a new value to name after initialization.")

@property
def map_to_parent(self) -> Optional[Dict[object, object]]:
Expand All @@ -434,7 +438,9 @@ def map_to_parent(self) -> Optional[Dict[object, object]]:

@map_to_parent.setter
def map_to_parent(self, value: object) -> NoReturn:
raise ValueError('You can not assign a new value to map_to_parent after initialization.')
raise AttributeError(
"You can not assign a new value to map_to_parent after initialization."
)

@property
def persistence(self) -> Optional[BasePersistence]:
Expand Down
37 changes: 9 additions & 28 deletions telegram/ext/_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ def parse_mode(self) -> Optional[str]:

@parse_mode.setter
def parse_mode(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
)
raise AttributeError("You can not assign a new value to parse_mode after initialization.")

@property
def explanation_parse_mode(self) -> Optional[str]:
Expand All @@ -134,8 +131,7 @@ def explanation_parse_mode(self) -> Optional[str]:
@explanation_parse_mode.setter
def explanation_parse_mode(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
"You can not assign a new value to explanation_parse_mode after initialization."
)

@property
Expand All @@ -148,8 +144,7 @@ def disable_notification(self) -> Optional[bool]:
@disable_notification.setter
def disable_notification(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
"You can not assign a new value to disable_notification after initialization."
)

@property
Expand All @@ -162,8 +157,7 @@ def disable_web_page_preview(self) -> Optional[bool]:
@disable_web_page_preview.setter
def disable_web_page_preview(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
"You can not assign a new value to disable_web_page_preview after initialization."
)

@property
Expand All @@ -176,8 +170,7 @@ def allow_sending_without_reply(self) -> Optional[bool]:
@allow_sending_without_reply.setter
def allow_sending_without_reply(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
"You can not assign a new value to allow_sending_without_reply after initialization."
)

@property
Expand All @@ -190,10 +183,7 @@ def timeout(self) -> ODVInput[float]:

@timeout.setter
def timeout(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
)
raise AttributeError("You can not assign a new value to timeout after initialization.")

@property
def quote(self) -> Optional[bool]:
Expand All @@ -205,10 +195,7 @@ def quote(self) -> Optional[bool]:

@quote.setter
def quote(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
)
raise AttributeError("You can not assign a new value to quote after initialization.")

@property
def tzinfo(self) -> pytz.BaseTzInfo:
Expand All @@ -219,10 +206,7 @@ def tzinfo(self) -> pytz.BaseTzInfo:

@tzinfo.setter
def tzinfo(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
)
raise AttributeError("You can not assign a new value to tzinfo after initialization.")

@property
def run_async(self) -> bool:
Expand All @@ -234,10 +218,7 @@ def run_async(self) -> bool:

@run_async.setter
def run_async(self, value: object) -> NoReturn:
raise AttributeError(
"You can not assign a new value to defaults after because it would "
"not have any effect."
)
raise AttributeError("You can not assign a new value to run_async after initialization.")

def __hash__(self) -> int:
return hash(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_conversationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_immutable(self, attr):
assert list(value.keys())[0] == attr
else:
assert getattr(ch, attr) == attr
with pytest.raises(ValueError, match=f'You can not assign a new value to {attr}'):
with pytest.raises(AttributeError, match=f'You can not assign a new value to {attr}'):
setattr(ch, attr, True)

def test_immutable_per_message(self):
Expand All @@ -299,7 +299,7 @@ def test_immutable_per_message(self):
map_to_parent='map_to_parent',
)
assert ch.per_message is False
with pytest.raises(ValueError, match='You can not assign a new value to per_message'):
with pytest.raises(AttributeError, match='You can not assign a new value to per_message'):
ch.per_message = True

def test_per_all_false(self):
Expand Down