Skip to content

Fix app.extra annotation - #1659

Merged
tiangolo merged 1 commit into
fastapi:masterfrom
bharel:fix-extra-annotation
Aug 3, 2020
Merged

tiangolo merged 1 commit into
fastapi:masterfrom
bharel:fix-extra-annotation

Conversation

@bharel

@bharel bharel commented Jun 30, 2020

Copy link
Copy Markdown
Contributor

**kwargs annotation is based on the value.
ATM extra is annotated like Dict[str, Dict[str, Any]] which causes issues with type-checkers.

@codecov

codecov Bot commented Jun 30, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #1659 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1659   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          235       235           
  Lines         6989      6989           
=========================================
  Hits          6989      6989           
Impacted Files Coverage Ξ”
fastapi/applications.py 100.00% <ΓΈ> (ΓΈ)

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 306ec8d...ab6af09. Read the comment docs.

@Kludex

Kludex commented Jun 30, 2020

Copy link
Copy Markdown
Contributor

What issues?

@bharel

bharel commented Jun 30, 2020

Copy link
Copy Markdown
Contributor Author

@Kludex, type-checkers will complain that app.extra["foo"] = 123 is invalid. That's because they think extra is a dict inside a dict.

@Kludex

Kludex commented Jun 30, 2020

Copy link
Copy Markdown
Contributor

@bharel Could you post the error that you got or is there a FastAPI issue about it? Do you mind providing more information? We can't even know which "type-checkers"...

@Kludex

Kludex commented Jun 30, 2020 •

Copy link
Copy Markdown
Contributor

I just saw that all the **extra in the param_functions.py are using the notation as you suggest. I don't see any problems updating it, so I'll approve and I think the CI pipeline failed for something not related to your changes... But I'm not sure.

@bharel

bharel commented Jun 30, 2020 •

Copy link
Copy Markdown
Contributor Author

@bharel Could you post the error that you got or is there a FastAPI issue about it? Do you mind providing more information? We can't even know which "type-checkers"...

All of them.
Here's an example:
image
It appears on all of the static type checkers, such as mypy, pycharm etc. It's just an incorrect type annotation.

I doubt the build fails because of the PR.

@tiangolo
tiangolo merged commit f1c5330 into fastapi:master Aug 3, 2020
@tiangolo

tiangolo commented Aug 3, 2020

Copy link
Copy Markdown
Member

Great, good catch! πŸ”

For reference, it's described here: https://mypy.readthedocs.io/en/stable/getting_started.html?highlight=kwargs#more-function-signatures

Thanks for your contribution! β˜• 🍰

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.

3 participants