[issue44792] Improve syntax errors for invalid if expressions

2021-07-31 Thread Miguel Brito


Change by Miguel Brito :


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

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



[issue44792] Improve syntax errors for invalid if expressions

2021-07-31 Thread Miguel Brito


New submission from Miguel Brito :

Hi, I was playing around with Python's grammar and noticed that the error 
message for if expression is generic, so not very informative.

I decided to improve it slightly.

*From*:

```
>>> a = 42 if True
  File "", line 1
a = 42 if True
  ^
SyntaxError: invalid syntax
```

*To*:

```
$ ./python
Python 3.10.0b4 (tags/v3.10.0b4-dirty:2ba4b20854, Jul 31 2021, 11:50:15) [GCC 
7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 42 if True
  File "", line 1
a = 42 if True
  ^
SyntaxError: invalid syntax. Conditional expression expected an 'else' here.
```

--
messages: 398633
nosy: miguendes
priority: normal
severity: normal
status: open
title: Improve syntax errors for invalid if expressions

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



[issue44166] Make IndexError messages for list more informative

2021-05-18 Thread Miguel Brito


Miguel Brito  added the comment:

Thanks for your comments, folks! I really appreciate it.

I left a comment about this issue in the PR thread: 
https://github.com/python/cpython/pull/26207#issuecomment-843531990

--

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



[issue44166] Make IndexError messages for list more informative

2021-05-18 Thread Miguel Brito


Change by Miguel Brito :


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

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



[issue44166] Make IndexError messages for list more informative

2021-05-18 Thread Miguel Brito

New submission from Miguel Brito :

I've noticed that in people will often ask for help on forums or stackoverflow 
to better understand the causes of
IndexErrors [1][2][3].
> The error message line for an IndexError doesn’t give you great 
> information.[1]

Currently, when we access a out of bounds position we get something along the 
lines:
Traceback (most recent call last):

>>> a = [0, 10, 20, 30, 40]
>>> a[5]
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list index out of range
>>> a.pop(6)
Traceback (most recent call last):
  File "", line 1, in 
IndexError: pop index out of range
>>> a[6] = 7
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list assignment index out of range
>>> a = []
>>> a[2]
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list index out of range


These error messages are too broad and doesn't inform the current length of the 
list, nor the index that was fed to it.

To improve the debugging experience in both interactive and non-interactive 
code,
I propose to offer a richer and more informative error messages. I think this 
can help users, especially newer and less
experienced folks, debug their code.


>>> a = [0, 10, 20, 30, 40]
>>> a[5]
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list index out of range, the len is 5 so index must be in -5..4, 
got 5
>>> a[-6]
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list index out of range, the len is 5 so index must be in -5..4, 
got -6
>>> a.pop(6)
Traceback (most recent call last):
  File "", line 1, in 
IndexError: pop index out of range, the len is 5 so index must be in -5..4, got 
6
>>> a[6] = 7
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list assignment index out of range, the len is 5 so index must be 
in -5..4, got 6
>>> a = []
>>> a[2] = 0
Traceback (most recent call last):
  File "", line 1, in 
IndexError: list assignment index out of range, got index 2 but the list is 
empty


These proposed messages are inspired by other languages, with the difference 
that in Python we can have negative index.
So informing the allowed ranges is a plus.

These improvements are not restricted to list, so it can be applied to strings 
and tuples as well, or any other indexable
object.

I have a branch ready, looking forward to hearing from you!

[1] 
https://stackoverflow.com/questions/1098643/indexerror-list-index-out-of-range-and-python
[2] 
https://stackoverflow.com/questions/16005707/index-error-list-index-out-of-range-python
[3] https://realpython.com/python-traceback/#indexerror

--
components: Interpreter Core
messages: 393858
nosy: miguendes
priority: normal
severity: normal
status: open
title: Make IndexError messages for list more informative
type: enhancement
versions: Python 3.11

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



[issue44137] importlib.resources.path raises RuntimeError when FileNotFoundError is raise in context manager

2021-05-15 Thread Miguel Brito


Miguel Brito  added the comment:

I can reproduce this. From what I can see the issue is that 
`importlib.resources.path` intentionally suppresses `FileNotFoundError` errors.

https://github.com/python/cpython/blob/main/Lib/importlib/resources.py#L138

Based on `importlib.resources.path` docstring I think this is to avoid raising 
an exception if the file is deleted before the context manager exits.

On contextlib.py, since type is not None, it will try to throw the exception 
but since it's supressed nothing will happen and the code will reach the end by 
raising the RuntimeError.

https://github.com/python/cpython/blob/main/Lib/contextlib.py#L151

If I'm not mistaken, this is the test that verifies that behaviour: 
https://github.com/python/cpython/blob/main/Lib/test/test_importlib/test_path.py#L51


I'm not a core dev but it looks like it's an intentional behaviour.

Maybe the docs should be more clear about this. It's not obvious to me when I 
read the docs.

--
nosy: +miguendes

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



[issue32133] documentation: numbers module nitpick

2021-05-15 Thread Miguel Brito


Miguel Brito  added the comment:

@rhettinger added your suggestion.

--

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



[issue32133] documentation: numbers module nitpick

2021-05-15 Thread Miguel Brito


Change by Miguel Brito :


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

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



[issue44095] Add suffix property to zipfile.Path

2021-05-14 Thread Miguel Brito


Miguel Brito  added the comment:

I prototyped something by adding `suffix`, `suffixes`, and `stem`. To me these 
are the most obvious ones and would be useful right away.

Regarding the others I'm not so sure. It seems that zipfile.Path is just a 
convenient class to provide basic navigational operations. It's not meant to be 
100% consistent with pathlib.Path. 

In any case, it'd nice to discuss it.


Here it is: https://github.com/python/cpython/pull/26129

--

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



[issue44095] Add suffix property to zipfile.Path

2021-05-14 Thread Miguel Brito


Change by Miguel Brito :


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

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



[issue44095] Add suffix property to zipfile.Path

2021-05-14 Thread Miguel Brito


Miguel Brito  added the comment:

+1. 

The docstring says:
```
class Path:
"""
A pathlib-compatible interface for zip files.
```
but only a few methods are supported. It'd be nice to have at least `stem`, 
`parents`, `suffixes`, `parts`, which IMHO would make sense here.

I'd love to work on this if the Core Devs think it makes sense and if OP is not 
doing so also.

--
nosy: +miguendes

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



[issue32133] documentation: numbers module nitpick

2021-05-14 Thread Miguel Brito


Miguel Brito  added the comment:

Seen that nobody is working on this I transformed the suggestion into a PR.

--
nosy: +miguendes

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



[issue44110] Improve string's __getitem__ error message

2021-05-11 Thread Miguel Brito


Change by Miguel Brito :


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

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



[issue44110] Improve string's __getitem__ error message

2021-05-11 Thread Miguel Brito


New submission from Miguel Brito :

I noticed that __getitem__ message, although helpful, could be improved a bit 
further. This will also make it consistent with other error messages such as 
the ones raised by `str.count`, `str.split`, `str.endswith` and so many others.

Currently, the error message goes like this: "TypeError: string indices must be 
integers" but we could specify the type of the object passed as argument to 
__getitem__. So, for example:

```
>>> idx = '1'
>>> s = 'abcde'
>>> s[idx]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: string indices must be integers, not 'str'
```

This makes easier to debug and it is also consistent with other methods:

>>> "alala".count(8)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: must be str, not int

>>> "lala|helo".split(1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: must be str or None, not int

>>> 1 in "lala"
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'in ' requires string as left operand, not int

>>> "lala|helo".split(object())
Traceback (most recent call last):
  File "", line 1, in 
TypeError: must be str or None, not object

--
components: Interpreter Core
messages: 393473
nosy: miguendes
priority: normal
severity: normal
status: open
title: Improve string's __getitem__ error message
type: enhancement
versions: Python 3.10, Python 3.11

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



[issue43124] [security] smtplib multiple CRLF injection

2021-05-08 Thread Miguel Brito


Change by Miguel Brito :


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

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



[issue43124] [security] smtplib multiple CRLF injection

2021-05-07 Thread Miguel Brito


Miguel Brito  added the comment:

If there's no one working on it I'd be happy to prepare a fix.

--
nosy: +miguendes

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



[issue44061] Regression in pkgutil: iter_modules stopped taking Path argument in python 3.8.10 and 3.9.5

2021-05-07 Thread Miguel Brito


Change by Miguel Brito :


--
keywords: +patch
pull_requests: +24621
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/25964

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



[issue44061] Regression in pkgutil: iter_modules stopped taking Path argument in python 3.8.10 and 3.9.5

2021-05-06 Thread Miguel Brito


Miguel Brito  added the comment:

I can reproduce it on latest master running on Linux.

steve.dower: I wrote some tests and wrapping get_importer argument with 
os.fsdecode() fixes it.

I'm happy to open an PR, just let me know or if OP is not willing to do so 
either.

--
nosy: +miguendes

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



[issue44030] Markup with_traceback code example

2021-05-05 Thread Miguel Brito


Miguel Brito  added the comment:

If we make it a code snippet it works. Just adding a `::` after the paragraph.

Here's a print on Firefox locally: https://imgur.com/a/g2vsqf2

I created a PR for that if you think it's a good solution, feel free to merge :)

--

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



[issue44030] Markup with_traceback code example

2021-05-05 Thread Miguel Brito


Change by Miguel Brito :


--
keywords: +patch
nosy: +miguendes
nosy_count: 2.0 -> 3.0
pull_requests: +24596
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/25929

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



[issue43952] Multiprocessing UNIX socket connection: client freeze if authkey is an empty byte string

2021-05-03 Thread Miguel Brito


Miguel Brito  added the comment:

I had a look at the HMAC RFC and apparently empty bytes sequence can be used as 
secret key.

"The definition of HMAC requires a cryptographic hash function, which
we denote by H, and a secret key K. 

...

The authentication key K can be of any length up to B, the
block length of the hash function."
   
https://tools.ietf.org/html/rfc2104.html#section-2

Assuming that is the case, the fix would be to change the Listener to:

```
if self._authkey is not None:
deliver_challenge(c, self._authkey)
answer_challenge(c, self._authkey)
return c
```


I created a PR for that, if anyone can review it, I appreciate it.
https://github.com/python/cpython/pull/25845

--

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



[issue44018] Bug in random.seed

2021-05-03 Thread Miguel Brito


Miguel Brito  added the comment:

The problem is that random seed will do

```
if isinstance(a, str):
a = a.encode()
a += _sha512(a).digest()
a = int.from_bytes(a, 'big')
```

and that will modify the bytearray in place.

>>> a = bytearray("1234", "utf-8")
>>> a += b"digest"
>>> a
bytearray(b'1234digest')


IMHO, seed shouldn't modify the input. Since str, and bytes are immutable that 
will only happen when passing a bytearray which is not consistent.

--
nosy: +miguendes

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



[issue43952] Multiprocessing UNIX socket connection: client freeze if authkey is an empty byte string

2021-05-03 Thread Miguel Brito


Change by Miguel Brito :


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

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



[issue43913] unittest module cleanup functions not run unless tearDownModule() is defined

2021-05-03 Thread Miguel Brito


Miguel Brito  added the comment:

Thanks terry.reedy, actually I read it in the mailing list, someones comment 
not a guideline.

Do you mind having a look at the PR?

--

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



[issue43952] Multiprocessing UNIX socket connection: client freeze if authkey is an empty byte string

2021-05-01 Thread Miguel Brito


Miguel Brito  added the comment:

I tried debugging this and from what I can see it's because there's an if that 
checks if the authkey is not None in the Client constructor:

https://github.com/python/cpython/blob/v3.9.4/Lib/multiprocessing/connection.py#L512

```
if authkey is not None:
answer_challenge(c, authkey)
deliver_challenge(c, authkey)
```

Whereas in the Listener, the check is different:

https://github.com/python/cpython/blob/v3.9.4/Lib/multiprocessing/connection.py#L469

```
c = self._listener.accept()
if self._authkey:
deliver_challenge(c, self._authkey)
answer_challenge(c, self._authkey)
return c
```

If I change the Listener to:

```
if self._authkey is not None:
deliver_challenge(c, self._authkey)
answer_challenge(c, self._authkey)
return c
```

it works.


The docs say:

"""
If authkey is given and not None, it should be a byte string and will be used 
as the secret key for an HMAC-based authentication challenge. No authentication 
is done if authkey is None. AuthenticationError is raised if authentication 
fails. See Authentication keys.
"""


Now the question is, if None is OK because no auth will be done what about 
empty bytes? Can it be used as secret key? If empty bytes is not accepted 
shouldn't Listener/Client raise an exception in the constructor?

--
nosy: +miguendes

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



[issue43869] Fix documentation of epoch/time.time

2021-05-01 Thread Miguel Brito


Miguel Brito  added the comment:

Seen that no one is working on this issue I created an PR to clarify the docs.

https://github.com/python/cpython/pull/25777

--

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



[issue43869] Fix documentation of epoch/time.time

2021-05-01 Thread Miguel Brito


Change by Miguel Brito :


--
keywords: +patch
nosy: +miguendes
nosy_count: 4.0 -> 5.0
pull_requests: +24467
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25777

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



[issue43913] unittest module cleanup functions not run unless tearDownModule() is defined

2021-05-01 Thread Miguel Brito


Miguel Brito  added the comment:

I was reading through the dev guide and past issues and I didn't know it's 
advisable to give the author of the issue a chance to submit the PR.

Sorry about that, you can close mine in this case.

--

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



[issue43871] urllib.parse.urlparse doesn't check port

2021-05-01 Thread Miguel Brito


Miguel Brito  added the comment:

I also think the validation logic should be ran as early as possible.

I gave it a shot and implemented it. 

I appreciate any reviews: https://github.com/python/cpython/pull/25774

Got some ideas from https://github.com/python/cpython/pull/16780

--

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



[issue43871] urllib.parse.urlparse doesn't check port

2021-05-01 Thread Miguel Brito


Change by Miguel Brito :


--
keywords: +patch
nosy: +miguendes
nosy_count: 4.0 -> 5.0
pull_requests: +24464
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25774

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



[issue43978] Incorrect "versionadded" info in typing.NoReturn documentation

2021-04-30 Thread Miguel Brito


Miguel Brito  added the comment:

This looks like a leftover from a merge conflict. Or a bad copy and paste 
indeed.

I've checked the file prior to the PR and the was no version 3.5.4 tag.

I've opened a PR to fix this: https://github.com/python/cpython/pull/25760

--

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



[issue43978] Incorrect "versionadded" info in typing.NoReturn documentation

2021-04-30 Thread Miguel Brito


Change by Miguel Brito :


--
keywords: +patch
nosy: +miguendes
nosy_count: 3.0 -> 4.0
pull_requests: +24450
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/25760

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



[issue43913] unittest module cleanup functions not run unless tearDownModule() is defined

2021-04-28 Thread Miguel Brito


Miguel Brito  added the comment:

Hello, first time here. I created an PR for that. Managed to reproduce the 
issue both manually and via unit test.

I hope there's no edge case but all tests pass on my machine.

--
nosy: +miguendes

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