Skip to content

Conversation

@bluetech
Copy link
Member

str(self.path) can't raise at all, so it can just be removed.

@property
def path(self) -> Union[py.path.local, str]:
""" return a path object pointing to source code (or a str in case
of OSError / non-existing file).
"""
if not self.raw.co_filename:
return ""
try:
p = py.path.local(self.raw.co_filename)
# maybe don't try this checking
if not p.check():
raise OSError("py.path check failed.")
return p
except OSError:
# XXX maybe try harder like the weird logic
# in the standard lib [linecache.updatecache] does?
return self.raw.co_filename

`str(self.path)` can't raise at all, so it can just be removed.
Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately i fear that self.path can raise a py.error.Error as p.check() may trigger a "interesting one"
still far-fetched, but it may ruin someones day

@bluetech
Copy link
Member Author

py.error.Error inherits from EnvironmentError, which is an alias for OSError in Python 3. The p.check() call is wrapped with except OSError. So the except py.error.Error could never have been reached anyway.

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, my my head it was the other way around, please go ahead then

@bluetech bluetech merged commit e319060 into pytest-dev:master May 28, 2020
@bluetech
Copy link
Member Author

Thanks for reviewing @RonnyPfannschmidt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants