Skip to content

Add check for __dir__ #86

@henryiii

Description

@henryiii

Description

It's great to see there's a plugin for checking __all__! However, there's a very closely related need: modules that define __all__ should also define __dir__ (Python 3.7+), usually to this:

def __dir__() -> list[str]:
    return list(__all__)

This will cause tab completion to only show the public interface of a module, and not imports like annotations and all sorts of other things that are not part of the public interface. See https://learn.scientific-python.org/development/patterns/exports for more info.

I think this check should be split up into two codes; one for normal files, and one for __init__.py files, as implementing a correct __dir__ for __init__.py is harder (it should include submodules that have been imported, doable but more than the one line body above).

What do you think? I could look at adding it if you think it's in scope. Maybe a new three-digit prefix, like DALL101 and DALL102?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions