Skip to content

Missing node attributes for jinja2 #3197

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

Closed
The-Compiler opened this issue Aug 17, 2019 · 5 comments
Closed

Missing node attributes for jinja2 #3197

The-Compiler opened this issue Aug 17, 2019 · 5 comments
Labels
stubs: incomplete Annotations or sub-modules missing from an existing package or module

Comments

@The-Compiler
Copy link
Contributor

It looks like the stubs for jinja2 are missing attributes for its node objects.

For example, this works fine:

import jinja2
import jinja2.nodes

template = jinja2.Environment().parse('{{ foo.bar }}')
nodes = list(template.iter_child_nodes())
nodes = list(nodes[0].iter_child_nodes())
node = nodes[0]
assert isinstance(node, jinja2.nodes.Getattr)
print(node.attr)
print(node.node)

but mypy says:

x.py:9: error: "Getattr" has no attribute "attr"
x.py:10: error: "Getattr" has no attribute "node"

because of:

class Getattr(Expr):
fields: Any
def as_const(self, eval_ctx: Optional[Any] = ...): ...
def can_assign(self): ...

cc @rowillia who originally added them in #722

@srittau
Copy link
Collaborator

srittau commented Aug 19, 2019

I guess that's true for all attributes that are added dynamically via the fields class var. Patches welcome!

@utkarsh2102
Copy link
Contributor

Instead of Any, can't we define the fields for all the attributes? (45 such declarations at the moment).
That is something like, fields = ('node', 'attr', 'ctx') instead of what it is now?

@srittau
Copy link
Collaborator

srittau commented Oct 9, 2019

@utkarsh2102 I think this is what we need to do here.

utkarsh2102 added a commit to utkarsh2102/typeshed that referenced this issue Oct 12, 2019
@srittau srittau added stubs: incomplete Annotations or sub-modules missing from an existing package or module and removed stubs: false positive Type checkers report false errors labels Sep 17, 2020
@The-Compiler
Copy link
Contributor Author

FWIW this would be obsoleted by #5423.

The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue May 18, 2021
jinja ships its own (more correct) stubs now

see python/typeshed#3197
@srittau
Copy link
Collaborator

srittau commented May 18, 2021

Closing as the jinja2 stubs will be removed in a few months.

@srittau srittau closed this as completed May 18, 2021
mkonig pushed a commit to mkonig/qutebrowser that referenced this issue Dec 7, 2021
jinja ships its own (more correct) stubs now

see python/typeshed#3197
twigleingrid pushed a commit to twigleingrid/qutebrowser that referenced this issue May 13, 2022
jinja ships its own (more correct) stubs now

see python/typeshed#3197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: incomplete Annotations or sub-modules missing from an existing package or module
Projects
None yet
Development

No branches or pull requests

3 participants