[issue41478] Empty representation of AssertionError

2020-08-06 Thread Ilya Kamenshchikov

Ilya Kamenshchikov  added the comment:

Changing behavior and it's impact on existing code is, without a doubt, a
big deal here. Maybe it's a reason not to do anything about it.

Just to understand guiding design principle, what is expected from __str__
in more general case? I thought about it as "user-friendly string
representation", therefore expected an Exception without a message to
identify itself by it's class.

Best Regards,
--
Ilya Kamen

On Thu, Aug 6, 2020 at 6:05 PM Rémi Lapeyre  wrote:

>
> Rémi Lapeyre  added the comment:
>
> > That's a solution, except you must know ahead of time this issue exists.
>
> If we changed str(e) to make it the same as repr(e), there would be no way
> to get only the message. str(e) returns the message so if the message given
> was empty (or no message was given) you get an empty string. This cannot be
> changed without breaking a lot of code.
>
> --
> versions: +Python 3.10, Python 3.9
>
> ___
> Python tracker 
> <https://bugs.python.org/issue41478>
> ___
>

--

___
Python tracker 
<https://bugs.python.org/issue41478>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41478] Empty representation of AssertionError

2020-08-06 Thread Ilya Kamenshchikov

Ilya Kamenshchikov  added the comment:

That's a solution, except you must know ahead of time this issue exists.

Best Regards,
--
Ilya Kamen

On Tue, Aug 4, 2020 at 6:59 PM Rémi Lapeyre  wrote:

>
> Rémi Lapeyre  added the comment:
>
> Hi, can you not use its repr:
>
>
> >>> try: raise ValueError
> ... except Exception as e: print(f"Following happened: {e!r}")
> ...
> Following happened: ValueError()
>
> ?
>
> --
> nosy: +remi.lapeyre
>
> ___
> Python tracker 
> <https://bugs.python.org/issue41478>
> ___
>

--

___
Python tracker 
<https://bugs.python.org/issue41478>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41478] Empty representation of AssertionError

2020-08-04 Thread Ilya Kamenshchikov


New submission from Ilya Kamenshchikov :

I have a high level wrapper where I am catching expection and present  it  in 
(more) user-friendly format with a message. 


try:
raise ValueError
except Exception as e:
print(f"Following happened: {e}")

>>> prints "Following happened: "

Can an exception print it's class when it has no message?

--
components: Interpreter Core
messages: 374831
nosy: Ilya Kamenshchikov
priority: normal
severity: normal
status: open
title: Empty representation of AssertionError
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue41478>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39760] ast.FormattedValue.format_spec unnecessarily wrapped in JoinedStr

2020-02-26 Thread Ilya Kamenshchikov


New submission from Ilya Kamenshchikov :

Most usual usecase for format_spec is to specify it as a constant, that would 
be logical to represent as ast.Constant. However, ast.parse wraps value of 
ast.FormattedValue.format_spec into a JoinedStr with a single constant value, 
as can be seen from example below:


import ast

code = '''f"is {x:d}"'''
tree = ast.parse(code)

for n in ast.walk(tree):
if isinstance(n, ast.FormattedValue):
print(
type(n.format_spec),
len(n.format_spec.values),
set(type(v) for v in n.format_spec.values),
)

This is confusing for programmatically analyzing the ast, and likely creates 
some overhead in any modules using ast and FormattedValue.

Proposal: represent ast.FormattedValue.format_spec as ast.Constant in most 
cases.

--
components: Library (Lib)
messages: 362691
nosy: Ilya Kamenshchikov
priority: normal
severity: normal
status: open
title: ast.FormattedValue.format_spec unnecessarily wrapped in JoinedStr
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue39760>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39626] random choice to delegate to sample on sets

2020-02-13 Thread Ilya Kamenshchikov


New submission from Ilya Kamenshchikov :

In a few of my projects I had this (minor) pain of having to remember which 
collections of elements are sets and which are [list, tuple]. It causes me to 
double check and have random.sample(my_set, 1)[0] in many places. 

To me this is not how I think and causes friction: conceptually, I know 
something is a collection and I want 1 random choice from it. Having to 
differentiate on sequences vs sets makes my code uglier :(

This issue is similar to https://bugs.python.org/issue37708.

--
components: Library (Lib)
messages: 361954
nosy: Ilya Kamenshchikov
priority: normal
severity: normal
status: open
title: random choice to delegate to sample on sets

___
Python tracker 
<https://bugs.python.org/issue39626>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38131] compile(mode='eval') uninformative error message

2019-09-12 Thread Ilya Kamenshchikov


New submission from Ilya Kamenshchikov :

While trying to construct a valid ast node programmatically, I have tried 
following: 

import ast

tree = ast.BinOp(left=ast.Num(n=2), right=ast.Num(n=2), op=ast.Add())
expr = ast.Expression(body=[tree])
ast.fix_missing_locations(expr)
exe = compile(expr, filename="", mode="eval")
print(eval(exe))

Unfortunately this gives unhelpful error message:

>>>exe = compile(expr, filename="", mode="eval")
TypeError: required field "lineno" missing from expr

Turns out I need to make body of ast.Expression not a list, but a node:
expr = ast.Expression(body=tree)  # works

Confusion also comes from naming the field "body", which takes value of a list 
for ast.Module and some others.

--
components: Library (Lib)
messages: 352090
nosy: Ilya Kamenshchikov
priority: normal
severity: normal
status: open
title: compile(mode='eval') uninformative error message
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 
<https://bugs.python.org/issue38131>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7951] Should str.format allow negative indexes when used for __getitem__ access?

2019-07-13 Thread Ilya Kamenshchikov


Ilya Kamenshchikov  added the comment:

Py3.6+ f-strings support any indexing as they actually evaluate python 
expressions. 

>>> a = ['Java', 'Python']
>>> var = f"Hello {a[-1]}"
Hello Python

--
nosy: +Ilya Kamenshchikov

___
Python tracker 
<https://bugs.python.org/issue7951>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37352] Typo in documentation: "to making it easy"

2019-07-13 Thread Ilya Kamenshchikov


Ilya Kamenshchikov  added the comment:

The wording from Carol Willing makes it read simpler. Also in the next 
sentence, 'test-directed development' goes under the name 'test-driven 
development' as of 2019 (search in google -> 
https://en.wikipedia.org/wiki/Test-driven_development). I have created a pull 
request with simpler wording and 'test-driven development'.

CLA is signed, will take time to propagate.

--
nosy: +Ilya Kamenshchikov

___
Python tracker 
<https://bugs.python.org/issue37352>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37352] Typo in documentation: "to making it easy"

2019-07-13 Thread Ilya Kamenshchikov


Change by Ilya Kamenshchikov :


--
keywords: +patch
pull_requests: +14525
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/14730

___
Python tracker 
<https://bugs.python.org/issue37352>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37182] ast - handling new line inside a string

2019-06-06 Thread Ilya Kamenshchikov


Ilya Kamenshchikov  added the comment:

Same problem holds for tabs (\\t vs \t).

For \\r vs \r, it is even more fun: 
txt1 = '"""\\r"""'
txt2 = '"""\r"""'

>>> b'\r'
>>> b'\n'

--

___
Python tracker 
<https://bugs.python.org/issue37182>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37182] ast - handling new line inside a string

2019-06-06 Thread Ilya Kamenshchikov


New submission from Ilya Kamenshchikov :

parsing two different strings produces identical ast.Str nodes:

import ast

txt1 = '"""\\n"""'
txt2 = '"""\n"""'

tree1 = ast.parse(txt1)
tree2 = ast.parse(txt2)

print(tree1.body[0].value.s == tree2.body[0].value.s)
print(bytes(tree1.body[0].value.s, encoding='utf-8'))
print(bytes(tree2.body[0].value.s, encoding='utf-8'))

>>> True
>>> b'\n'
>>> b'\n'

Expected result: I should be able to distinguish between the nodes created from 
two different strings.

--
components: Library (Lib)
messages: 344861
nosy: Ilya Kamenshchikov
priority: normal
severity: normal
status: open
title: ast - handling new line inside a string
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue37182>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2943] Distutils should generate a better error message when the SDK is not installed

2016-01-01 Thread Ilya Kamenshchikov

Ilya Kamenshchikov added the comment:

please fix spent half a day to understand I need C compiler

--
nosy: +Ilya Kamenshchikov

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue2943>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com