-
Notifications
You must be signed in to change notification settings - Fork 105
py.code.Code "path" attribute not always a py.path.local object #71
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
Comments
Original comment by @nicoddemus OK, thanks. |
Original comment by @hpk42 so i guess it's ok to always just return py.path.local(co_filename) without any checks -- but we should see if any tests fail. The pytest pytest-dev/pytest#995 should be solved without relying on this IMO. |
Original comment by @hpk42 I now think that the code.path API is not such a good idea to begin with. if |
Original comment by @nicoddemus The question is what be the benefit of exposing this to the user? It goes against what the docs say, Python itself doesn't do this distinction (after all it is always stored in |
Original comment by @RonnyPfannschmidt there is a important detail we must take into a account, a localpath represents an absolute path and the given location for the code is a placeholder that's specifically not a path |
Original comment by @nicoddemus I really disagree... I don't think returning |
Original comment by @RonnyPfannschmidt i think we need to return None there, when its not a path |
Original comment by @RonnyPfannschmidt path is always absolute, thus not suitable for markers like |
Original comment by @nicoddemus IMO Other situations where this filename might not be valid is when distributing def use_entry(entry):
if isinstance(entry.path, str) and os.path.isfile(entry.path) or entry.check():
# do something with filename Most users would now arguably just write: def use_entry(entry):
path = py.path.local(entry.path)
if entry.check():
# do something with the file at entry.path So it makes sense to always return a @property
def path(self):
""" return a path object pointing to source code (note that it
might not point to an actually existing file). """
p = py.path.local(self.raw.co_filename)
+ return p
- # maybe don't try this checking
- if not p.check():
- # XXX maybe try harder like the weird logic
- # in the standard lib [linecache.updatecache] does?
- p = self.raw.co_filename
- return p (This also fixes the py.test bug) In summary, I see no downsides in making |
Original comment by @hpk42 Should we maybe jsut document that |
closing as py.code is no longer actually maintained |
Sometimes the
path
attribute of apy.code.Code
object is not apy.local.path
object but a plain string, usually due to a traceback entry not being located in a real file but as a result of an exec statement.This caused a regression in pytest, as seen in #995.
The text was updated successfully, but these errors were encountered: