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

variable tracking for assignment inside of def #192

Closed
sqlalchemy-bot opened this issue Jun 18, 2012 · 5 comments
Closed

variable tracking for assignment inside of def #192

sqlalchemy-bot opened this issue Jun 18, 2012 · 5 comments

Comments

@sqlalchemy-bot
Copy link

@sqlalchemy-bot sqlalchemy-bot commented Jun 18, 2012

Migrated issue, originally created by Michael Bayer (@zzzeek)

from mako.template import Template
t = Template(
"""
<%
   def foo():
       s = 1
%>

""".strip(),
   strict_undefined=True,
)
t.render()

would rise "NameError: 's' is not defined"


Attachments: 192.2.patch | 192.patch

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Jun 18, 2012

Michael Bayer (@zzzeek) wrote:

this is a likely patch which also cleans up "ident stack" a bit.

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Jun 19, 2012

Michael Bayer (@zzzeek) wrote:

updated version generalizes names located within defs and fixes it for 2.4 as well.

new test:

t = Template(
"""
<%
   def foo():
       s = 1
       def bar():
           t = s
%>

""".strip(),
   strict_undefined=True,
)

t.render()
@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Jun 19, 2012

Michael Bayer (@zzzeek) wrote:

and more:

t = Template(
"""
<%
   def foo():
       class Bat(object):
           pass
       Bat
%>

""".strip(),
   strict_undefined=True,
)
# should pass
t.render()


t = Template(
"""
<%
   def foo():
       class Bat(object):
           pass
       Bat
%>

   ${Bat}

""".strip(),
   strict_undefined=True,
)
# should pass
t.render(Bat='adsf')

# should raise
t.render()

however, make sure we distill these into test_ast.py as more test_locate_identifiers tests.

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Jul 7, 2012

Michael Bayer (@zzzeek) wrote:

91b7e5f

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Jul 7, 2012

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant