Skip to content

Fix type errors after adding types to the py dependency#6511

Merged
bluetech merged 1 commit intopytest-dev:masterfrom
bluetech:py-typed-fixes
Jan 19, 2020
Merged

Fix type errors after adding types to the py dependency#6511
bluetech merged 1 commit intopytest-dev:masterfrom
bluetech:py-typed-fixes

Conversation

@bluetech
Copy link
Member

This is in preparation for adding type stubs to py. See pytest-dev/py#232.

These changes make mypy clean both before and after.

@bluetech bluetech requested a review from blueyed January 19, 2020 12:50
""" the file system path of the test module which collected this test. """
return self._pyfuncitem.fspath
# TODO: Remove ignore once _pyfuncitem is properly typed.
return self._pyfuncitem.fspath # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Use the error code here? (see --show-error-codes, could be added to the config probably) (with flake-ignore then)

Copy link
Member Author

Choose a reason for hiding this comment

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

We should probably do them all at once, maybe on the next mypy bump.

@cached_property
def location(self) -> Tuple[str, Optional[int], str]:
location = self.reportinfo()
assert isinstance(location[0], py.path.local), location[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

You've removed the change from reportinfo, right? (from the initial Git tree)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

class MyFunction(pytest.Function):
def reportinfo(self):
return "ABCDE", 42, "custom"
return py.path.local("foo"), 42, "custom"
Copy link
Contributor

Choose a reason for hiding this comment

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

That's kind of an API change - I've noticed this myself that the tests seem to be the only things using str.
Ok with me in general, just wanted to mention this, i.e. some plugins might return strings there (but likely fail then afterwards, depending on where it is used I guess?)
Maybe this could/should have a test?

Copy link
Member Author

Choose a reason for hiding this comment

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

The _bestrelpathcache backing this only works with py.path.local, that it returned something for str was accidental and incorrect. So I think the assert just codifies the current behavior.

Only this test trigerred the assert, and it's just a mock, so I think it should be fine.

@bluetech bluetech merged commit 4fb9cc3 into pytest-dev:master Jan 19, 2020
@bluetech bluetech deleted the py-typed-fixes branch January 19, 2020 13:23
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