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

Type checking calls[] is insufficient #610

Closed
evilensky opened this issue Dec 21, 2022 · 6 comments
Closed

Type checking calls[] is insufficient #610

evilensky opened this issue Dec 21, 2022 · 6 comments
Assignees

Comments

@evilensky
Copy link

evilensky commented Dec 21, 2022

Describe the bug

this bit of code

import requests
import responses

def get_something():
    return requests.get('http://example.com')


def test_get_something():
    with responses.RequestsMock() as rsps:
        rsps.add(responses.GET, 'http://example.com', body='foo')
        foo = get_something()
        assert rsps.calls[0].request.url == 'http://example.com/'

results in a type checking failure in mypy and pyright. The Pyright message is:

Cannot access member "request" for type "List[Call]"
  Member "request" is unknown

Additional context

No response

Version of responses

0.22.0

Steps to Reproduce

Example in bug description.

Expected Result

The example code should pass type checking. Members of List[Call] should have their attributes properly annotated.

Actual Result

Cannot access member "request" for type "List[Call]"   Member "request" is unknown

@beliaev-maksim
Copy link
Collaborator

Thanks for reporting an issue

Can you please attach a minimal reproducible code snippet?

Similar to stackoverflow
https://stackoverflow.com/help/minimal-reproducible-example

@evilensky
Copy link
Author

evilensky commented Dec 21, 2022

Got it. I believe the below is both complete and minimal:

import requests
import responses

def get_something():
    return requests.get('http://example.com')


def test_get_something():
    with responses.RequestsMock() as rsps:
        rsps.add(responses.GET, 'http://example.com', body='foo')
        foo = get_something()
        assert rsps.calls[0].request.url == 'http://example.com/'

Updated original report.

The mypy equivalent of the above Pyright error is:

error: Item "List[Call]" of "Union[Call, List[Call]]" has no attribute "request" [union-attr]

@evilensky
Copy link
Author

evilensky commented Dec 21, 2022

This was fixed in master? any chance we could get a release? :) 26bb973

@evilensky evilensky closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
@evilensky evilensky reopened this Dec 21, 2022
@beliaev-maksim
Copy link
Collaborator

Yes, we will do it soon

Need to add a couple of things

@evilensky
Copy link
Author

Any ETA on a new release? Thanks for the great tool.

@beliaev-maksim
Copy link
Collaborator

@evilensky please track #629 ticket for the release info

Build must pass internal review before publishing, usually a couple of weeks

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

No branches or pull requests

2 participants