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

TestClient methods are typed to return _ResultBase, but actually return Result #2207

Closed
davetapley opened this issue Jan 31, 2024 · 4 comments · Fixed by #2338
Closed

TestClient methods are typed to return _ResultBase, but actually return Result #2207

davetapley opened this issue Jan 31, 2024 · 4 comments · Fixed by #2338

Comments

@davetapley
Copy link
Contributor

All these methods are typed to return _ResultBase:

async def simulate_get(self, path='/', **kwargs) -> _ResultBase:
"""Simulate a GET request to an ASGI application.
(See also: :py:meth:`falcon.testing.simulate_get`)
"""
return await self.simulate_request('GET', path, **kwargs)

But actually returns Result here:

return Result(helpers.closed_wsgi_iterable(iterable), srmock.status, srmock.headers)

And Result defines the methods which are useful in testing:

@property
def text(self) -> str:
if self._text is None:
if not self.content:
self._text = ''
else:
if self.encoding is None:
encoding = 'UTF-8'
else:
encoding = self.encoding
self._text = self.content.decode(encoding)
return self._text
@property
def json(self) -> Optional[Union[dict, list, str, int, float, bool]]:
if not self.text:
return None
return json_module.loads(self.text)


But because it's typed _ResultBase I get e.g. Cannot access member "json" for type "_ResultBase",
even though the methods work 😬

I presume this is an oversight and not intentional?

@CaselIT
Copy link
Member

CaselIT commented Feb 1, 2024

That seems likely yes. PR to fix would be appreciated!

@davetapley
Copy link
Contributor Author

Closing for reasons on: #2209 (comment)

@davetapley davetapley closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
@CaselIT
Copy link
Member

CaselIT commented Feb 1, 2024

it seems doable, with a lot more effort

@CaselIT CaselIT reopened this Feb 1, 2024
@davetapley
Copy link
Contributor Author

@CaselIT I agree! See #2210 😁

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