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

Error message for __all__ operations #2137

Closed
r-priyam opened this issue Dec 4, 2021 · 11 comments
Closed

Error message for __all__ operations #2137

r-priyam opened this issue Dec 4, 2021 · 11 comments

Comments

@r-priyam
Copy link

r-priyam commented Dec 4, 2021

Environment data

  • Language Server version: v2021.12.1-pre.1
  • OS and version: Windows 11 Home Single Language 22000.348
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.9.9

Expected behaviour

Shouldn't error with the __all__ operations.

Code Snippet / Additional information

test.py

class AllBug:
    ...

__init__.py

from test import *

__all__ = (AllBug) # errors here

Error message - Operation on "all" is not supported, so exported symbol list may be incorrect

@github-actions github-actions bot added the triage label Dec 4, 2021
@r-priyam
Copy link
Author

r-priyam commented Dec 4, 2021

It appears that this was fixed previously in this release of pyright Point 4

@erictraut
Copy link
Contributor

This is an incorrect usage of __all__. You need to assign a tuple or list of symbol names, not actual symbols. You can fix this bug by changing your code above to one of the following:

__all__ = ("AllBug",)

or

__all__ = ["AllBug"]

@r-priyam
Copy link
Author

r-priyam commented Dec 4, 2021

Sorry and thanks eric

@r-priyam r-priyam closed this as completed Dec 4, 2021
@mangelozzi
Copy link

This is an incorrect usage of __all__. You need to assign a tuple or list of symbol names, not actual symbols. You can fix this bug by changing your code above to one of the following:

__all__ = ("AllBug",)

or

__all__ = ["AllBug"]

I get the same error even though it is a tuple (also tried a list same error):
image

@erictraut
Copy link
Contributor

You need to include a list of strings in the tuple, as in __all__ = ("DevHw", ). Your code is including a list of symbol references, not strings.

@mangelozzi
Copy link

You need to include a list of strings in the tuple, as in __all__ = ("DevHw", ). Your code is including a list of symbol references, not strings.

Oh my goodness sorry about that, I kept checking and couldnt see the difference, thank you.

@xeroc
Copy link

xeroc commented Jan 25, 2024

Funny how this works:

import abc


class AbstractTradingStrategy(abc.ABC):
    pass


__all__ = ["AbstractTradingStrategy"]

but this fails:

import abc


class AbstractTradingStrategy(abc.ABC):
    pass


__all__ = [AbstractTradingStrategy.__name__]    ## WARNING HERE!

@erictraut
Copy link
Contributor

@xeroc, that's correct. The first example is supported by type checkers and the second is not. Refer to this documentation for a full list of supported expression forms supported for __all__.

@xeroc
Copy link

xeroc commented Jan 25, 2024

@xeroc, that's correct. The first example is supported by type checkers and the second is not. Refer to this documentation for a full list of supported expression forms supported for __all__.

Thanks for the explanation and the link.
Do you have a proposal how I should do do this when using autoflake? It remives unused imports. So either i use .name, then the import is used, or i have to eun an assert on all imports. I prefer .name, as its cleaner code.

@erictraut
Copy link
Contributor

Do you have a proposal how I should do do this when using autoflake

I presume autoflake is a linter and code formatter? If so, this sounds like a bug in the linter. It should treat a symbol as referenced if it appears in the __all__ list. Consider reporting it as a bug to the maintainer.

@xeroc
Copy link

xeroc commented Jan 25, 2024

Thanks for pointing me to the right direction. Turns out autoflake has a parameter for that already:
PyCQA/autoflake#35

Sorry for bothering you for nothing.

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

4 participants