Skip to content

Support comprehensions inside functions when use strict_undefined flag.#386

Closed
cocolato wants to merge 2 commits intosqlalchemy:mainfrom
cocolato:fix/incompatible_comp
Closed

Support comprehensions inside functions when use strict_undefined flag.#386
cocolato wants to merge 2 commits intosqlalchemy:mainfrom
cocolato:fix/incompatible_comp

Conversation

@cocolato
Copy link
Contributor

@cocolato cocolato commented Feb 1, 2024

Fixes: #320

Now the test code works as expected if strict_undefined is set to true:

from mako.template import Template

text = """
<%
    mydict = { 'foo': 1 }

    ## Uncomment the following line to workaround the error
    ##k = None
    def getkeys(x):
        return [ k for k in x.keys() ]
%>

${ ','.join( getkeys(mydict) ) }
"""

tmpl = Template(text=text, strict_undefined=True)
out = tmpl.render()
print(out)

output:




foo

@zzzeek
Copy link
Member

zzzeek commented Feb 1, 2024

wow I dig this, you're into mako now. great let's run the CI

@zzzeek zzzeek requested a review from sqla-tester February 1, 2024 16:28
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision daffd38 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change daffd38: https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5147

@zzzeek
Copy link
Member

zzzeek commented Feb 5, 2024

can you add a changelog file? thanks

Copy link
Member

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great.

it needs:

  1. a changelog file, like the other one
  2. the fixes: line:
    Fixes: #320
    Closes: #386
    Pull-request: https://github.com/sqlalchemy/mako/pull/386
    Pull-request-sha: daffd3832b4adab291625e1e6efcdb56f8d0d05e
    
    Change-Id: I0591873a83837f8f35b0963c0536df1e2675012f

"bar %% baz",
]

def test_lsitcomp_in_func_strict(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

cocolato and others added 2 commits February 6, 2024 06:13
Closes: sqlalchemy#386
Pull-request: sqlalchemy#386
Pull-request-sha: 7840ad3

Change-Id: I0591873a83837f8f35b0963c0536df1e2675012f
@cocolato cocolato force-pushed the fix/incompatible_comp branch from daffd38 to cc6a3e0 Compare February 6, 2024 06:39
@cocolato
Copy link
Contributor Author

cocolato commented Feb 6, 2024

All has been updated.

@zzzeek zzzeek requested a review from sqla-tester February 6, 2024 13:14
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision cc6a3e0 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset cc6a3e0 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5147

@sqla-tester
Copy link
Collaborator

Michael Bayer (zzzeek) wrote:

thanks!

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5147

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/5147 has been merged. Congratulations! :)

artdogma added a commit to artdogma/pymako that referenced this pull request Aug 27, 2025
Fixes: sqlalchemy/mako#320

Now the test code works as expected if strict_undefined is set to true:

```python
from mako.template import Template

text = """
<%
    mydict = { 'foo': 1 }

    ## Uncomment the following line to workaround the error
    ##k = None
    def getkeys(x):
        return [ k for k in x.keys() ]
%>

${ ','.join( getkeys(mydict) ) }
"""

tmpl = Template(text=text, strict_undefined=True)
out = tmpl.render()
print(out)
```

output:
```

foo

```

Closes: #386
Pull-request: sqlalchemy/mako#386
Pull-request-sha: cc6a3e0694fb5615db2c3fec2cd23bc9e8a70066

Change-Id: I0591873a83837f8f35b0963c0536df1e2675012f
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.

strict_undefined flag is incompatible with comprehensions inside functions

3 participants