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

Multipart encoder produces type errors when using pylance language server #312

Open
Serhiy1 opened this issue Jul 12, 2021 · 4 comments
Open

Comments

@Serhiy1
Copy link

Serhiy1 commented Jul 12, 2021

To reproduce

  1. Setup visual studio code and install the python extension
  2. Enable type hinting by adding "python.analysis.typeCheckingMode": "basic", To settings.json
  3. Copy and paste the example from the docstring into a file
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder


encoder = MultipartEncoder({'field': 'value',
                             'other_field': 'other_value'})
r = requests.post('https://httpbin.org/post', data=encoder,
                    headers={'Content-Type': encoder.content_type})
  1. A typing error that is thrown
Argument of type "MultipartEncoder" cannot be assigned to parameter "data" of type "_Data" in function "post"
  Type "MultipartEncoder" cannot be assigned to type "_Data"
    Type cannot be assigned to type "None"
    "MultipartEncoder" is incompatible with "Text"
    "MultipartEncoder" is incompatible with "bytes"
    "MultipartEncoder" is incompatible with "Mapping[str, Any]"
    "__iter__" is not present
    "MultipartEncoder" is incompatible with "IO[Any]"PylancereportGeneralTypeIssues
  1. The current workaround is to add a # Type: ignore comment
r = requests.post('https://httpbin.org/post', data=encoder,     #type:ignore
                    headers={'Content-Type': encoder.content_type})
@sigmavirus24
Copy link
Collaborator

This library has existed long before PEP 485 and those errors are not a priority for us to fix as they do not break and things work as they should. Further the annotations for requests are notoriously wrong

@Serhiy1
Copy link
Author

Serhiy1 commented Jul 12, 2021

Low priority is no problem, I understand that this isn't a run time issue and if you ignore the warning everything works.

I'm Just reporting a user experience that initially very confusing and making a workaround publically available for anyone who is in a similar situation.

@sigmavirus24
Copy link
Collaborator

To be clear, images are:

  • not searchable
  • not readable for visually impaired users
  • not a solution

You'd do better for others (assuming a type error in this scenario is actually confusing for them) by pasting actual text that a search on Google or GitHub could find

@Serhiy1
Copy link
Author

Serhiy1 commented Jul 14, 2021

Fair point, the report has been updated.

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

No branches or pull requests

2 participants