[issue33809] Expose `capture_locals` parameter in `traceback` convenience functions

2021-09-16 Thread Ulrich Petri


Ulrich Petri  added the comment:

> If we copy all the params from TracebackException (and it will be all params, 
> why only this one?)

Why expose the internal machinery at all?
If all additional parameters (and unless I'm miscounting we're talking about 2) 
were exposed on the convenience functions why add to the developers mental load 
with the underlying implementation?

> more documentation and a higher cognitive load for someone reading the 
> documentation to learn the API.

I would agree if the API in question was ergonomic and the documentation easy 
to read in the first place. I think neither is true for the traceback module 
and its documentation.

Another example from today where I helped a coworker who was unable to figure 
out on his own how to print the current stack with locals:


  from traceback import StackSummary, walk_stack
  
  print("".join(StackSummary.extract(walk_stack(None), 
capture_locals=True).format()))

There are multiple things that make this API non-intuitive:
- Why does walk_stack() need an explicit None argument?
- Why is StackSummary created via the extract() classmethod instead of having a 
regular __init__?
- Why can't extract() be smart if no iterator is passed and figure out on it's 
own if we're in an exception context or not and call walk_stack / walk_tb 
accordingly?
- Why is the result a list if each item can contain multiple internal newlines?

--

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



[issue43176] Dataclasses derived from empty frozen bases skip immutability checks

2021-05-06 Thread Ulrich Petri


Ulrich Petri  added the comment:

@eric.smith Sure, here you go:


dataclass_empty.py:
```
from dataclasses import dataclass


@dataclass
class A:
pass


@dataclass(frozen=True)
class B(A):
x: int

print("42")
```

Running this on < 3.8.10:
```
$ ~/.pythonz/pythons/CPython-3.8.1/bin/python3.8 --version
Python 3.8.1

$ ~/.pythonz/pythons/CPython-3.8.1/bin/python3.8 dataclass_empty.py
42
```

And on 3.8.10:
```
$ /usr/local/opt/python@3.8/bin/python3 --version
Python 3.8.10

$ /usr/local/opt/python@3.8/bin/python3 dataclass_empty.py
Traceback (most recent call last):
  File "dataclass_empty.py", line 10, in 
class B(A):
  File 
"/usr/local/Cellar/python@3.8/3.8.10/Frameworks/Python.framework/Versions/3.8/lib/python3.8/dataclasses.py",
 line 1011, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File 
"/usr/local/Cellar/python@3.8/3.8.10/Frameworks/Python.framework/Versions/3.8/lib/python3.8/dataclasses.py",
 line 896, in _process_class
raise TypeError('cannot inherit frozen dataclass from a '
TypeError: cannot inherit frozen dataclass from a non-frozen one
```

--

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



[issue43176] Dataclasses derived from empty frozen bases skip immutability checks

2021-05-06 Thread Ulrich Petri


Ulrich Petri  added the comment:

Wether the original behaviour was intentional or not this change introduces 
backwards incompatibility (and in our case, breakage) between 3.8.10 and 
previous releases (I expect the same to be true for the equivalent 3.9 
releases).

--
nosy: +ulope

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



[issue33809] Expose `capture_locals` parameter in `traceback` convenience functions

2021-01-15 Thread Ulrich Petri


Ulrich Petri  added the comment:

That would make it slightly better, but I still think it's a pretty arcane 
incantation (esp. for newer people).

What makes you hesitant to adding the parameter to the convenience functions?

--

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



[issue33809] Expose `capture_locals` parameter in `traceback` convenience functions

2021-01-13 Thread Ulrich Petri


Ulrich Petri  added the comment:

Functionally equivalent code would be:

print("".join(TracebackException.from_exception(ex, 
capture_locals=True).format()))

vs. (hypothetically)

print_exc(capture_locals=True)

Which is quite a significant difference IMO.

--

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



[issue35046] logging.StreamHandler performs two syscalls when one would do

2019-02-06 Thread Ulrich Petri


Ulrich Petri  added the comment:

This change breaks (probably unsupported) uses of the logging module (esp. in 
combination with structlog) where non-string objects are passed through the 
.format() and .emit() calls.

Previously it was possible to set the terminator attribute to None (and then 
handling that case in a custom 'stream' implementation), which now breaks with 
a TypeError due to the concatenation.

In case anyone else runs into this (however unlikely that is). A workaround is 
to set the .terminator to something like this:

class ConcatenableNothing:
def __radd__(self, other):
return other

--
nosy: +ulope

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



[issue33809] Expose `capture_locals` parameter in `traceback` convenience functions

2018-06-08 Thread Ulrich Petri


New submission from Ulrich Petri :

Since 3.5 the internal machinery of the `traceback` module has gained the very 
useful ability to capture locals.

It would be useful to also expose that ability through the various convenience 
functions.

--
components: Library (Lib)
messages: 319079
nosy: ulope
priority: normal
severity: normal
status: open
title: Expose `capture_locals` parameter in `traceback` convenience functions
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8

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



[issue27362] json.dumps to check for obj.__json__ before raising TypeError

2018-02-01 Thread Ulrich Petri

Change by Ulrich Petri :


--
nosy: +ulope

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



[issue12782] Multiple context expressions do not support parentheses for continuation across lines

2017-05-14 Thread Ulrich Petri

Ulrich Petri added the comment:

So this would basically be:

with ExitStack() as stack:
cm1 = stack.enter_context(a_long_name.with_a_long_method())
cm2 = stack.enter_context(another_long_variable.with_a_long_method())

Seems like a very non-obvious and inelegant solution...

--
nosy: +ulope

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



[issue29787] Internal importlib frames visible when module imported by import_module throws exception

2017-03-14 Thread Ulrich Petri

Ulrich Petri added the comment:

Thanks for the fast response. 
However I disagree with the assertion that this is "working as expected". IMO 
the same arguments apply as in the original ticket (esp. Georg Brandls) 
http://bugs.python.org/issue15110#msg163258.

It is unexpected, confusing (esp. to newer devs) and adds a lot of 
(unnecessary) noise to tracebacks.

Also this basically demotes `import_module` to second rate league since it 
doesn't get to enjoy the niceties of "proper" import which is unfortunate since 
it's used heavily for example in django.

--

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



[issue29787] Internal importlib frames visible when module imported by import_module throws exception

2017-03-10 Thread Ulrich Petri

New submission from Ulrich Petri:

Importing a module that raises an exception on import trough 
`importlib.import_module()` causes importlib to not strip it's internal frames 
from the traceback.


Minimal example:

--a.py--
import importlib

importlib.import_module("b")
--a.py--


--b.py--
raise Exception()
--b.py--

#~ python3.6 a.py
Traceback (most recent call last):
  File "a.py", line 3, in 
importlib.import_module("b")
  File 
"/Users/ulo/.pythonz/pythons/CPython-3.6.0/lib/python3.6/importlib/__init__.py",
 line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 978, in _gcd_import
  File "", line 961, in _find_and_load
  File "", line 950, in _find_and_load_unlocked
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in _call_with_frames_removed
  File "/Users/ulo/t/b.py", line 1, in 
raise Exception()
Exception

--
messages: 289381
nosy: ulope
priority: normal
severity: normal
status: open
title: Internal importlib frames visible when module imported by import_module 
throws exception
type: behavior
versions: Python 3.6

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



[issue21978] Support index access on OrderedDict views (e.g. o.keys()[7])

2016-12-07 Thread Ulrich Petri

Ulrich Petri added the comment:

Should this maybe reconsidered now that dicts are ordered by default?

Having to explain why list is needed in list(some_ordered_dict.values())[0] is  
a constant thorn in my side when dealing with people new to Python.

--
nosy: +ulope

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



[issue28697] asyncio.Lock, Condition, Semaphore docs don't mention `async with` syntax

2016-11-15 Thread Ulrich Petri

New submission from Ulrich Petri:

The docs for asyncio's Lock, Condition and Semaphore should use the new clean 
`async with lock:` syntax instead of the older (and IMO rather ugly) `with 
(yield from lock):` version.

--
assignee: docs@python
components: Documentation, asyncio
messages: 280861
nosy: docs@python, gvanrossum, ulope, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.Lock, Condition, Semaphore docs don't mention `async with` syntax
versions: Python 3.5, Python 3.6, Python 3.7

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



[issue27337] 3.6.0a2 tarball has weird paths

2016-06-28 Thread Ulrich Petri

Ulrich Petri added the comment:

Just as another datapoint: This also breaks installing a2 with pythonz.

--
nosy: +ulope

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



[issue24120] pathlib.(r)glob stops on PermissionDenied exception

2015-07-02 Thread Ulrich Petri

Ulrich Petri added the comment:

Antoine, thanks for the review. I didn't realise that `tree` outputs non-ASCII 
by default. I've updated the patch with a pure ASCII file tree.

Unfortunately I don't have a Windows dev environment available at the moment, 
so I can't easily test for that.

--
Added file: http://bugs.python.org/file39843/issue24120_2.diff

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



[issue24120] pathlib.(r)glob stops on PermissionDenied exception

2015-06-05 Thread Ulrich Petri

Ulrich Petri added the comment:

The attached patch adds an unaccessible directory to the pathlib tests to 
provoke the problem and also fixes the cause in pathlib.

It applies to at least 3.4 - 3.6

--
keywords: +patch
nosy: +ulope
Added file: http://bugs.python.org/file39634/issue24120.diff

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