question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spurious warning "Unused entry 'genexpr'"

See original GitHub issue

Cython version 0.25.2

l = [1,2,3]

def f():
    print(x for x in l)
$ cython -Wextra -Werror foo.pyx

Error compiling Cython file:
------------------------------------------------------------
...
l = [1,2,3]

def f():
    print(x for x in l)
           ^
------------------------------------------------------------

foo.pyx:4:12: Unused entry 'genexpr'

This only happens when the generator expression is in a function, rather than at the module level. Surrounding the expression with parentheses doesn’t help. Converting it to a list comprehension does remove the warning, but will make performance worse, especially if the generator expression would not have run to completion.

I like to use -Wextra -Werror because the “unused” warnings often indicate a genuine error in my code.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
mhsmithcommented, Aug 27, 2021

@scoder: I’m sorry, but this isn’t fixed at all. My simple 3-line example above still fails, with almost the same message:

$ cython --version
Cython version 0.29.24
$ cython -Wextra -Werror foo.pyx
/home/smith/.virtualenvs/pypi/lib/python3.8/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/smith/tmp/foo.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
l = [1,2,3]

def f():
    print(x for x in l)
         ^
------------------------------------------------------------

foo.pyx:4:10: Unused entry 'genexpr'

Please reopen the issue.

1reaction
LordArocommented, Aug 23, 2020

You can use lists explicitly instead of generator expressions. Obviously this doesn’t work in all cases, and can significantly increase memory usage, but it will work some of the time…

print(x for x in foo)

->

print([x for x in foo])
Read more comments on GitHub >

github_iconTop Results From Across the Web

0.29.24 Milestone - GitHub
Spurious warning "Unused entry 'genexpr'" defect Error Reporting. #1699 opened on May 6, 2017 by mhsmith.
Read more >
Getting <generator object <genexpr> - python - Stack Overflow
I want to do the following math to it: Multiply 0.49 by 1.91 (the corresponding values from first_lst and second_lst ), and multiply...
Read more >
Pylint Documentation - Read the Docs
Pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for code smells. It....
Read more >
Pylint's ChangeLog — Pylint 2.4.4 documentation
This fixes a false negative with unused-variable which was no longer ... Warn about using the input() or round() built-ins for Python 3....
Read more >
Cython Changelog — Cython 3.0.0a11 documentation
The cython and cythonize commands ignored non-existing input files without error. ... A C compiler warning about unused code was resolved.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found