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

FileStorage perhaps has incorrect typing metadata #2155

Closed
hughsie opened this issue May 24, 2021 · 5 comments · Fixed by #2199
Closed

FileStorage perhaps has incorrect typing metadata #2155

hughsie opened this issue May 24, 2021 · 5 comments · Fixed by #2199
Labels
Milestone

Comments

@hughsie
Copy link

hughsie commented May 24, 2021

Describe how to replicate the bug.

from flask import request
# snip some app-specific logic...
fileitem = request.files["file"]
blob = fileitem.read()

and then:

mypy test.py
test.py:3: error: "FileStorage" has no attribute "read"

Environment:

  • Python version: 3.9.5
  • Flask version: 2.0.1
@ajayd-san

This comment has been minimized.

@YahyaFazlani

This comment has been minimized.

@davidism
Copy link
Member

davidism commented Jun 5, 2021

It proxies to all methods of the underlying stream. If mypy is showing an error then it's wrong, FileStorage defines __getattr__ so any name should be allowed.

@davidism davidism transferred this issue from pallets/flask Jun 5, 2021
@4sfaloth
Copy link
Contributor

I'm also experiencing this. Just to be clear @davidism are you saying werkzeug has its metadata correctly set, and that this is a bug/limitation in mypy itself?

@davidism
Copy link
Member

Looks like I didn't define the __getattr__ method in the datastructures.pyi file, so the type system isn't picking it up (it doesn't look at the source if there's a pyi file). Happy to consider a PR that fixes the pyi file.

@davidism davidism added this to the 2.0.2 milestone Jul 28, 2021
@davidism davidism linked a pull request Aug 6, 2021 that will close this issue
1 task
@davidism davidism closed this as completed Aug 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants