A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-July/101455.html below:

[Python-Dev] Can Python implementations reject semantically invalid expressions?

[Python-Dev] Can Python implementations reject semantically invalid expressions?Maciej Fijalkowski fijall at gmail.com
Mon Jul 5 10:44:57 CEST 2010
On Fri, Jul 2, 2010 at 10:35 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sat, 3 Jul 2010 11:39:07 am Greg Ewing wrote:
>> Stefan Behnel wrote:
>> > So, would it still be Python if it folded
>> >
>> >     1 + "1"
>> >
>> > into
>> >
>> >     raise TypeError()
>> >
>> > at compile time?
>>
>> It would have to be
>>
>>     raise TypeError("Exactly the message that would have been
>> produced at run time")
>
>
> Python doesn't make any guarantees about the message that exceptions
> display, so I don't think you need to match the message, just the
> exception. Anyone testing for specific exception messages is living in
> a state of sin and shouldn't complain when their code stops working. An
> implementation might choose to raise TypeError('is this the right place
> for an argument?') on alternate Tuesdays, and it would still meet the
> promises made by the language.
>

In theory it does not, in practice people rely on it. Besides, I would
not be overly happy if:

def f():
 return 1 + "1"

and

def g():
 a = 1
 return a + "1"

raise different messages
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4