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

double list comprehension loses scope of outer list comprehension variables #1357

Closed
steeling opened this issue May 24, 2024 · 2 comments
Closed

Comments

@steeling
Copy link

[
    [
        Page {
            val: {metric.name: generate(metric, _manifest.pageId, idx) for idx, metric in _manifest.metrics}
        }, 
    ] for _manifest in manifests
]

Gets _manifest not defined

@Peefy
Copy link
Contributor

Peefy commented May 24, 2024

Hello @steeling , I can't reproduce this issue. My kcl version is v0.9.0-alpha.1, could you please provider more information?

manifests = [
    {
        metrics = [
            {
                name = "key"
            }
        ]
        pageId = 1
    }
]
generate = lambda x, y, z {
    # Returns page.id
    y
}

schema Page:
    val: any

x = [
    [
        # Note I've used `"{}".format(metric.name)` here.
        Page {
            val: {"{}".format(metric.name): generate(metric, _manifest.pageId, idx) for idx, metric in _manifest.metrics}
        }, 
    ] for _manifest in manifests
]

The output is

manifests:
- metrics:
  - name: key
  pageId: 1
x:
- - val:
      key: 1

@steeling
Copy link
Author

ya that's working for me as well, not sure if it was an older version i was using at the time or if i had some other errors. sorry for the noise

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

No branches or pull requests

2 participants