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

[WIP] Another stab at #88 #99

Closed
wants to merge 1 commit into from
Closed

[WIP] Another stab at #88 #99

wants to merge 1 commit into from

Conversation

pavel-kirienko
Copy link
Member

Disabling the Jinja cache results in the unique name generator state disappearing from the global Jinja context:

>       return _UniqueNameGenerator.ensure_generator_in_globals(env.globals)('c', adj_base_token, '_', '_')
E       TypeError: 'NoneType' object is not callable
.tox/py35-test/lib/python3.5/site-packages/nunavut/lang/c.py:527: TypeError

This issue affects all languages. The following test modification indicates that the state gets replaced with None:

------------------------- src/nunavut/lang/__init__.py -------------------------
index bd6524c..135a29a 100644
@@ -226,7 +226,7 @@ class _UniqueNameGenerator:
    def ensure_generator_in_globals(cls, environment_globals: typing.Dict[str, typing.Any]) -> '_UniqueNameGenerator':
        from .. import TypeLocalGlobalKey

-        if TypeLocalGlobalKey not in environment_globals:
+        if environment_globals.get(TypeLocalGlobalKey) is None:
            environment_globals[TypeLocalGlobalKey] = cls()
        return typing.cast('_UniqueNameGenerator', environment_globals[TypeLocalGlobalKey])

I don't quite understand what is happening and why it worked on my machine last week.

@thirtytwobits do you find the added test logic sensible?

Disabling the Jinja cache results in the unique name generator state disappearing from the global Jinja context:

    >       return _UniqueNameGenerator.ensure_generator_in_globals(env.globals)('c', adj_base_token, '_', '_')
    E       TypeError: 'NoneType' object is not callable
    .tox/py35-test/lib/python3.5/site-packages/nunavut/lang/c.py:527: TypeError

This issue affects all languages. The following test modification indicates that the state gets replaced with None:

    ------------------------- src/nunavut/lang/__init__.py -------------------------
    index bd6524c..135a29a 100644
    @@ -226,7 +226,7 @@ class _UniqueNameGenerator:
        def ensure_generator_in_globals(cls, environment_globals: typing.Dict[str, typing.Any]) -> '_UniqueNameGenerator':
            from .. import TypeLocalGlobalKey

    -        if TypeLocalGlobalKey not in environment_globals:
    +        if environment_globals.get(TypeLocalGlobalKey) is None:
                environment_globals[TypeLocalGlobalKey] = cls()
            return typing.cast('_UniqueNameGenerator', environment_globals[TypeLocalGlobalKey])

Am stuck.
@pavel-kirienko pavel-kirienko added bug Something isn't working help wanted Extra attention is needed labels Nov 6, 2019
@pavel-kirienko pavel-kirienko mentioned this pull request Nov 6, 2019
@thirtytwobits
Copy link
Member

So I rebased this on my PR and we do get past the None error but it still doesn't work the way you expect. I am uncertain that macros will have anything that isn't an argument reevaluated. For that you'll want to create another template and include it.

@thirtytwobits
Copy link
Member

Closing as I merged this into #91 before tracking down the final problems with it.

@pavel-kirienko pavel-kirienko deleted the issue88 branch November 16, 2019 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants