-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
Typing requires template globals to accept no arguments #4098
Comments
These temporarily work around pallets/flask#4098 [1]. [1]: pallets/flask#4098
hey, can i have this issue? |
@default-303, hello! I am not the maintainer of this repo, but I can tell you a few things about pull requests. Don't make my mistakes - don't try frantically looking at what you don't like in the code or when you see an issue to do something right there (I'm sorry that I did this Pallets again, sorry ...) If we talk about issues in general, you need to carefully consider the problem, look at the specific places in the code where the author sees flaws. If there is something unknown to you from the world of programming - delve into it too. |
Analyze! Think! Find a solution! Write the code! Good luck, @default-303) |
@Yourun-proger Yes I will, thanks https://github.com/default-303/flask.git |
Seems to be fixed: $ git clone https://github.com/lucaswerkmeister/repro-flask-mypy-template_global
Cloning into 'repro-flask-mypy-template_global'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (6/6), done.
$ sed -i '/flask/ s/^.*$/git+git:\/\/github.com\/pallets\/flask@aac67289e517bda4ef488819edab74539ef8e9b9#egg=flask/' repro-flask-mypy-template_global/requirements.txt
$ make -C repro-flask-mypy-template_global/
make: Entering directory '/tmp/repro-flask-mypy-template_global'
python3 -m venv venv/ && \
. venv/bin/activate && \
pip install --upgrade pip && \
pip install -r requirements.txt && \
mypy app.py
Requirement already satisfied: pip in ./venv/lib/python3.9/site-packages (21.1.1)
Collecting pip
Using cached pip-21.1.2-py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.1.1
Uninstalling pip-21.1.1:
Successfully uninstalled pip-21.1.1
Successfully installed pip-21.1.2
Collecting flask
Cloning git://github.com/pallets/flask (to revision aac67289e517bda4ef488819edab74539ef8e9b9) to /tmp/pip-install-p37w2zmc/flask_af79151c67bc4a58880143fc4a889f2b
Running command git clone -q git://github.com/pallets/flask /tmp/pip-install-p37w2zmc/flask_af79151c67bc4a58880143fc4a889f2b
Running command git rev-parse -q --verify 'sha^aac67289e517bda4ef488819edab74539ef8e9b9'
Running command git fetch -q git://github.com/pallets/flask aac67289e517bda4ef488819edab74539ef8e9b9
Collecting mypy==0.812
Using cached mypy-0.812-cp39-cp39-manylinux2010_x86_64.whl (22.7 MB)
Collecting Werkzeug>=2.0
Using cached Werkzeug-2.0.1-py3-none-any.whl (288 kB)
Collecting Jinja2>=3.0
Using cached Jinja2-3.0.1-py3-none-any.whl (133 kB)
Collecting itsdangerous>=2.0
Using cached itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting click>=8.0
Using cached click-8.0.1-py3-none-any.whl (97 kB)
Collecting mypy-extensions<0.5.0,>=0.4.3
Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Collecting typing-extensions>=3.7.4
Using cached typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)
Collecting typed-ast<1.5.0,>=1.4.0
Using cached typed_ast-1.4.3-cp39-cp39-manylinux1_x86_64.whl (769 kB)
Collecting MarkupSafe>=2.0
Using cached MarkupSafe-2.0.1-cp39-cp39-manylinux2010_x86_64.whl (30 kB)
Using legacy 'setup.py install' for flask, since package 'wheel' is not installed.
Installing collected packages: MarkupSafe, Werkzeug, typing-extensions, typed-ast, mypy-extensions, Jinja2, itsdangerous, click, mypy, flask
Running setup.py install for flask ... done
Successfully installed Jinja2-3.0.1 MarkupSafe-2.0.1 Werkzeug-2.0.1 click-8.0.1 flask-2.1.0.dev0 itsdangerous-2.0.1 mypy-0.812 mypy-extensions-0.4.3 typed-ast-1.4.3 typing-extensions-3.10.0.0
Success: no issues found in 1 source file
make: Leaving directory '/tmp/repro-flask-mypy-template_global' |
The typings in Flask 2.0.1 require a function decorated with
@app.template_global()
to take no arguments. As far as I’m aware, template globals certainly are supposed to take arguments (e.g. the example in the API documentation takes one argument), so I assume this is not intended. I think this specific issue was introduced with #4071, which applied theTemplateGlobalCallable
type alias to that decorator; however, theTemplateGlobalCallable
type itself is already an alias fort.Callable[[], t.Any]
(i.e., take no arguments and return anything) in Flask 2.0.0. I haven’t checked yet ifapp.add_template_global()
is affected.Example code:
Sample repository: https://github.com/lucaswerkmeister/repro-flask-mypy-template_global
Steps to reproduce:
Environment:
The text was updated successfully, but these errors were encountered: