Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attrs strips filename information from tracebacks #491

Closed
jgkamat opened this issue Jan 26, 2019 · 4 comments
Closed

Attrs strips filename information from tracebacks #491

jgkamat opened this issue Jan 26, 2019 · 4 comments
Labels

Comments

@jgkamat
Copy link

jgkamat commented Jan 26, 2019

With this file, named 'test.py'

import attr
import traceback

@attr.s
class Coordinates(object):
	x = attr.ib()
	y = attr.ib()


	def __attrs_post_init__(self):
		traceback.print_stack()

Coordinates(1,2)

The output generated is:

  File "test.py", line 14, in <module>
    Coordinates(1,2)
  File "<attrs generated init bbaf7cf2afa21222b9e9b6e67f14e8b55cc4c79a>", line 4, in __init__
    self.__attrs_post_init__()
  File "test.py", line 12, in __attrs_post_init__
    traceback.print_stack()

Loosing the filename information completely is incredibly annoying when debugging. I'm currently trying to track down a couple performance issues, and I'm not sure if the attrs generated init I happen to be looking at is from my code or from one of the libraries I'm pulling. It would be nice to actually display the real filename with a pointer to the attrs header, but even something like 'attrs generated init for class Coordinates' would be infinitely better.

(for example):
2019-01-25-222613_520x111_scrot

@jgkamat jgkamat changed the title Attrs strips filename/line number information from tracebacks Attrs strips filename information from tracebacks Jan 26, 2019
@hynek
Copy link
Member

hynek commented Jan 26, 2019

The problem here is that the __init__ isn't defined in a file per se. I guess we could maybe fake it to point to the file that defined the class?

@hynek
Copy link
Member

hynek commented Jan 26, 2019

(I've opened another ticket for your second suggestion since they are separate issues and it might have gotten lost here)

@hynek
Copy link
Member

hynek commented Jan 26, 2019

Ah one more thing: the reason why the file is this weird mumbojumbo is that they are being cached. The same set of attributes gets the same init which makes your wish a bit harder to fulfill. We'd probably have to copy the method object before we change the name and return it. That might be fast enough tho.

@wsanchez wsanchez added the Bug label Jan 30, 2019
@hynek
Copy link
Member

hynek commented Aug 18, 2019

We have “fixed” this as well as we can in #560. Maybe adding file names to docstrings will help further but this as it is cannot be fixed

@hynek hynek closed this as completed Aug 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants