Spencer Brown <spencer...@live.com> added the comment:

There is a solution to this: you can modify the linecache module's cache to add 
lines under a fake filename, which is the approach attrs takes here:
https://github.com/python-attrs/attrs/blob/9727008fd1e40bc55cdc6aee71e0f61553f33127/src/attr/_make.py#L347
However, there are several downsides. 
- That dict isn't documented or appears in __all__, so it's arguably private.
- The C implementation of traceback printing opens files directly, so this 
doesn't work there.
- You have to invent a unique filename, and manually remove lines from the 
cache if the function is later deleted.
This does affect both namedtuple and dataclasses, though it's probably not too 
important given how straightforward the generated code they produce is.

----------
nosy: +Spencer Brown

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

Reply via email to