From 67023b85c41d23d6c6d69812a41b207c4f8a9331 Mon Sep 17 00:00:00 2001 From: Joseph Young <80432516+jpy-git@users.noreply.github.com> Date: Wed, 24 Nov 2021 18:52:02 +0000 Subject: [PATCH] Add __all__ attributes to __init__.py files to resolve F401 (#1949) Co-authored-by: Barry Hart --- src/sqlfluff/__init__.py | 10 ++++- src/sqlfluff/api/__init__.py | 11 ++++- src/sqlfluff/core/__init__.py | 16 +++++++- src/sqlfluff/core/linter/__init__.py | 11 ++++- src/sqlfluff/core/parser/__init__.py | 41 +++++++++++++++++-- src/sqlfluff/core/parser/grammar/__init__.py | 17 +++++++- src/sqlfluff/core/parser/segments/__init__.py | 23 ++++++++++- src/sqlfluff/core/templaters/__init__.py | 12 +++++- 8 files changed, 127 insertions(+), 14 deletions(-) diff --git a/src/sqlfluff/__init__.py b/src/sqlfluff/__init__.py index 8f849d88617..0ca558f8814 100644 --- a/src/sqlfluff/__init__.py +++ b/src/sqlfluff/__init__.py @@ -3,7 +3,7 @@ import pytest # Expose the public API. -from sqlfluff.api import lint, fix, parse, list_rules, list_dialects # noqa: F401 +from sqlfluff.api import lint, fix, parse, list_rules, list_dialects # Import metadata (using importlib_metadata backport for python versions <3.8) if sys.version_info < (3, 8, 0): @@ -11,6 +11,14 @@ else: from importlib import metadata +__all__ = ( + "lint", + "fix", + "parse", + "list_rules", + "list_dialects", +) + # Get the current version __version__ = metadata.version("sqlfluff") diff --git a/src/sqlfluff/api/__init__.py b/src/sqlfluff/api/__init__.py index ad8beb1bc00..1221b4f3eab 100644 --- a/src/sqlfluff/api/__init__.py +++ b/src/sqlfluff/api/__init__.py @@ -1,7 +1,14 @@ """Elements which wrap the sqlfluff core library for public use.""" -# flake8: noqa: F401 - # Expose the simple api from sqlfluff.api.simple import lint, fix, parse, APIParsingError from sqlfluff.api.info import list_rules, list_dialects + +__all__ = ( + "lint", + "fix", + "parse", + "APIParsingError", + "list_rules", + "list_dialects", +) diff --git a/src/sqlfluff/core/__init__.py b/src/sqlfluff/core/__init__.py index 3473a22611b..2491c6bac79 100644 --- a/src/sqlfluff/core/__init__.py +++ b/src/sqlfluff/core/__init__.py @@ -1,6 +1,5 @@ """The core elements of sqlfluff.""" -# flake8: noqa: F401 import tblib.pickling_support # type: ignore # Config objects @@ -26,6 +25,21 @@ # Timing objects from sqlfluff.core.timing import TimingSummary +__all__ = ( + "FluffConfig", + "Linter", + "Lexer", + "Parser", + "dialect_selector", + "dialect_readout", + "SQLBaseError", + "SQLTemplaterError", + "SQLLexError", + "SQLParseError", + "SQLLintError", + "SQLFluffUserError", + "TimingSummary", +) # This is for "sqlfluff lint" and "sqlfluff fix" multiprocessing (--processes) # support. If an exception (i.e. runtime error) occurs in a worker process, we diff --git a/src/sqlfluff/core/linter/__init__.py b/src/sqlfluff/core/linter/__init__.py index 8e870e5d51f..a23ae26059f 100644 --- a/src/sqlfluff/core/linter/__init__.py +++ b/src/sqlfluff/core/linter/__init__.py @@ -1,8 +1,15 @@ """Linter class and helper classes.""" -# flake8: noqa: F401 - from sqlfluff.core.linter.common import RuleTuple, ParsedString, NoQaDirective from sqlfluff.core.linter.linted_file import LintedFile from sqlfluff.core.linter.linting_result import LintingResult from sqlfluff.core.linter.linter import Linter + +__all__ = ( + "RuleTuple", + "ParsedString", + "NoQaDirective", + "LintedFile", + "LintingResult", + "Linter", +) diff --git a/src/sqlfluff/core/parser/__init__.py b/src/sqlfluff/core/parser/__init__.py index a31f0693eac..e45f279f05a 100644 --- a/src/sqlfluff/core/parser/__init__.py +++ b/src/sqlfluff/core/parser/__init__.py @@ -1,6 +1,4 @@ -""" init file for the parser """ - -# flake8: noqa: F401 +"""init file for the parser.""" from sqlfluff.core.parser.segments import ( BaseSegment, @@ -36,3 +34,40 @@ from sqlfluff.core.parser.lexer import Lexer, StringLexer, RegexLexer from sqlfluff.core.parser.parser import Parser from sqlfluff.core.parser.matchable import Matchable + +__all__ = ( + "BaseSegment", + "BaseFileSegment", + "RawSegment", + "CodeSegment", + "UnlexableSegment", + "CommentSegment", + "WhitespaceSegment", + "NewlineSegment", + "KeywordSegment", + "SymbolSegment", + "Indent", + "Dedent", + "SegmentGenerator", + "Sequence", + "GreedyUntil", + "StartsWith", + "OneOf", + "Delimited", + "Bracketed", + "AnyNumberOf", + "Ref", + "Anything", + "Nothing", + "OptionallyBracketed", + "Conditional", + "StringParser", + "NamedParser", + "RegexParser", + "PositionMarker", + "Lexer", + "StringLexer", + "RegexLexer", + "Parser", + "Matchable", +) diff --git a/src/sqlfluff/core/parser/grammar/__init__.py b/src/sqlfluff/core/parser/grammar/__init__.py index 3af78693a06..f0f37ad02a3 100644 --- a/src/sqlfluff/core/parser/grammar/__init__.py +++ b/src/sqlfluff/core/parser/grammar/__init__.py @@ -1,10 +1,23 @@ """Definitions of grammars.""" -# flake8: noqa: F401 - from sqlfluff.core.parser.grammar.base import Ref, Anything, Nothing from sqlfluff.core.parser.grammar.anyof import AnyNumberOf, OneOf, OptionallyBracketed from sqlfluff.core.parser.grammar.delimited import Delimited from sqlfluff.core.parser.grammar.greedy import GreedyUntil, StartsWith from sqlfluff.core.parser.grammar.sequence import Sequence, Bracketed from sqlfluff.core.parser.grammar.conditional import Conditional + +__all__ = ( + "Ref", + "Anything", + "Nothing", + "AnyNumberOf", + "OneOf", + "OptionallyBracketed", + "Delimited", + "GreedyUntil", + "StartsWith", + "Sequence", + "Bracketed", + "Conditional", +) diff --git a/src/sqlfluff/core/parser/segments/__init__.py b/src/sqlfluff/core/parser/segments/__init__.py index 94e438777dc..55bec6aedd6 100644 --- a/src/sqlfluff/core/parser/segments/__init__.py +++ b/src/sqlfluff/core/parser/segments/__init__.py @@ -1,6 +1,5 @@ """Definitions of the segment classes.""" -# flake8: noqa: F401 from sqlfluff.core.parser.segments.base import ( BaseSegment, BaseFileSegment, @@ -25,3 +24,25 @@ Dedent, TemplateSegment, ) + +__all__ = ( + "BaseSegment", + "BaseFileSegment", + "UnparsableSegment", + "BracketedSegment", + "SegmentGenerator", + "RawSegment", + "CodeSegment", + "UnlexableSegment", + "CommentSegment", + "WhitespaceSegment", + "NewlineSegment", + "KeywordSegment", + "SymbolSegment", + "EphemeralSegment", + "allow_ephemeral", + "MetaSegment", + "Indent", + "Dedent", + "TemplateSegment", +) diff --git a/src/sqlfluff/core/templaters/__init__.py b/src/sqlfluff/core/templaters/__init__.py index 5c804fa8cd6..42dc6a49f33 100644 --- a/src/sqlfluff/core/templaters/__init__.py +++ b/src/sqlfluff/core/templaters/__init__.py @@ -1,7 +1,5 @@ """Templater Code.""" -# flake8: noqa: F401 - from sqlfluff.core.templaters.base import TemplatedFile # Although these shouldn't usually be instantiated from here @@ -15,3 +13,13 @@ def core_templaters(): """Returns the templater tuples for the core templaters.""" yield from [RawTemplater, JinjaTemplater, PythonTemplater, PlaceholderTemplater] + + +__all__ = ( + "TemplatedFile", + "RawTemplater", + "JinjaTemplater", + "PythonTemplater", + "PlaceholderTemplater", + "core_templaters", +)