-
Notifications
You must be signed in to change notification settings - Fork 187
__all__ can be a tuple or a list #62
Comments
This is because if |
Most of the code I've seen makes Also making Perhaps a good approach is to skip the |
That would defeat the purpose of having |
I'm in complete agreement that making That said I'll close this issue. Perhaps generating this message will provide incentive to switch to using tuples to get the benefit of BTW thanks for creating this handy tool -- I run all my python code through it to keep myself consistent. |
Is there a need for pep257 to know what is public or not? Are there different PEP-257 rules for public and private things? |
@ziadsawalha PEP 257 says:
To enforce that pep257 should know which functions and classes are private and which are public. If there is no |
So pep257 checks that |
It's probably best to document this behavior either in README or in the error-message, though. |
FWIW I’ve seen |
__all__ = ['g']
def f():
pass
def g():
"""Docstring."""
__all__.append('f') In this case, even though |
Yeah..... hmmmm But that's almost impossible to get water-tight. What if you have something like this: import os
__all__ = ['g']
def f():
pass
def g():
"""Docstring."""
if os.environ.get("FEATURE_F"):
__all__.append('f') I feel like I've come across many more projects that have all as a static list than I have come across ones where it is dynamically changed; but that might be the types of projects I work with. I don't have solid data on that and I'm not sure how to get it. How about if we add an option (ex. |
I would rather have no option, but a warning if
Not sure that this is the best wording, though. Anyway, pep257 will proceed and will return 0 code in no other errors were found—so it's a pure warning that will not influence success/failure of the static analysis. |
@halst How about this? I added the following to #63: if self.current.value == '[':
msg = ("%s WARNING: __all__ is defined as a list, this means "
"pep257 cannot reliably detect contents of the __all__ "
"variable, because it can be mutated. Change __all__ to be "
"an (immutable) tuple, to remove this warning. Note, "
"pep257 uses __all__ to detect which definitions are "
"public, to warn if public definitions are missing "
"docstrings. If __all__ is a (mutable) list, pep257 cannot "
"reliably assume its contents. pep257 will proceed "
"assuming __all__ is not mutated.\n" % self.filename)
sys.stderr.write(msg) And the output looks like this:
|
__all__ was formally a tuple to remove the warning from pep257 tool, PyCQA/pydocstyle#62
Is there a way to disable these really annoying warnings? We have some legacy code that we don't want to update but we still have to maintain it for a while. Why would we have a warning that cannot be disabled using the normal ignore mechanism? |
I'm not sure I see the point of this warning, as even
This makes |
The Python official docs refer to IMO, I think you should consider removing thewarning and instead document pydocstyle's shortfall when handling modules that mutate |
Parse_all() flags an error if all is not a tuple, whereas all is more commonly a list.
The text was updated successfully, but these errors were encountered: