Repository: tobymao/sqlglot

Issue:
Dialect not exported explicitly
Using `sqlglot.Dialect.get_or_raise("sqlite")` with the current version (sqlglot 11.2.0) raises the following error in the mypy linter:
`attr-defined "Module sqlglot" does not explicitly export attribute "Dialect"`

To fix this, sqlglot shall declare reexported classes in a `__all__` field in its `__init__.py` file.


Discussion:
I can't reproduce this issue locally:

```
➜ cat test.py
import sqlglot
sqlglot.Dialect.get_or_raise("sqlite")
➜ mypy test.py
Success: no issues found in 1 source file
```

Is this what you meant? I have SQLGlot v11.2.0 and mypy v.1.0.0 in the above example.
Thx, after some tests (using the same versions as you) it seems to come from the strict mode of mypy:

```
% mypy test.py
Success: no issues found in 1 source file

% mypy --strict test.py
test.py:2: error: "Module sqlglot" does not explicitly export attribute "Dialect"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)
```

I have no opinion whether libraries are supposed to follow mypy's strict mode (which is optional in mypy). However, this is the only library out of 40+ libraries in my project which raises this (including classics like pandas, numpy, sklearn, aiohttp, ...). So it seems the strict mode has become the norm.
I see... I don't have an opinion on this either, let's wait for @tobymao's response.
Checks activated with `--strict` for future reference: https://emplocity.com/en/about-us/blog/mypy_not_enough/.
sure
@dmoklaf I'll try to resolve the dialect issue in `__init__.py`, because making SQLGlot work with `--strict` is going to take more time and it's not a high priority issue.
`from sqlglot.dialects.dialect import Dialect` ?
This doesn't seem to work for me..? On the other hand, if I do `__all__ = ["Dialect"]` inside `__init__.py` it does work, but that approach would require including all exported names in this list, which isn't great..
isn't that the point of this mypy check?
Not for you - for @dmoklaf 

sqlglot doesn't promise that Dialect is part of the main module.

See the readme: https://github.com/tobymao/sqlglot#custom-dialects
I'm a bit confused. So what I meant is that with this script:

```python
# test.py
import sqlglot
sqlglot.Dialect.get_or_raise("sqlite")
```

Running `mypy test.py --strict` resulted in `error: Module sqlglot does not explicitly export attribute Dialect [attr-defined]`. Even after making the change Barak suggested, I `pip install -e .` and still didn't work.

The fix I just tried and actually got mypy to stop yelling is:

```python
from sqlglot.dialects.dialect import Dialect as Dialect
```
Ah, I think see what you meant @barakalon. However, I think the intent is for us to export most of these helper functions in `__init__.py`, since they're not even used in that file.

Resolving patch:
diff --git a/sqlglot/__init__.py b/sqlglot/__init__.py
--- a/sqlglot/__init__.py
+++ b/sqlglot/__init__.py
@@ -9,33 +9,40 @@
 import typing as t
 
 from sqlglot import expressions as exp
-from sqlglot.dialects import Dialect, Dialects
-from sqlglot.diff import diff
-from sqlglot.errors import ErrorLevel, ParseError, TokenError, UnsupportedError
-from sqlglot.expressions import Expression
-from sqlglot.expressions import alias_ as alias
+from sqlglot.dialects.dialect import Dialect as Dialect, Dialects as Dialects
+from sqlglot.diff import diff as diff
+from sqlglot.errors import (
+    ErrorLevel as ErrorLevel,
+    ParseError as ParseError,
+    TokenError as TokenError,
+    UnsupportedError as UnsupportedError,
+)
 from sqlglot.expressions import (
-    and_,
-    column,
-    condition,
-    except_,
-    from_,
-    intersect,
-    maybe_parse,
-    not_,
-    or_,
-    select,
-    subquery,
+    Expression as Expression,
+    alias_ as alias,
+    and_ as and_,
+    column as column,
+    condition as condition,
+    except_ as except_,
+    from_ as from_,
+    intersect as intersect,
+    maybe_parse as maybe_parse,
+    not_ as not_,
+    or_ as or_,
+    select as select,
+    subquery as subquery,
+    table_ as table,
+    to_column as to_column,
+    to_table as to_table,
+    union as union,
 )
-from sqlglot.expressions import table_ as table
-from sqlglot.expressions import to_column, to_table, union
-from sqlglot.generator import Generator
-from sqlglot.parser import Parser
-from sqlglot.schema import MappingSchema, Schema
-from sqlglot.tokens import Tokenizer, TokenType
+from sqlglot.generator import Generator as Generator
+from sqlglot.parser import Parser as Parser
+from sqlglot.schema import MappingSchema as MappingSchema, Schema as Schema
+from sqlglot.tokens import Tokenizer as Tokenizer, TokenType as TokenType
 
 if t.TYPE_CHECKING:
-    from sqlglot.dialects.dialect import DialectType
+    from sqlglot.dialects.dialect import DialectType as DialectType
 
     T = t.TypeVar("T", bound=Expression)
 
diff --git a/sqlglot/dataframe/sql/functions.py b/sqlglot/dataframe/sql/functions.py
--- a/sqlglot/dataframe/sql/functions.py
+++ b/sqlglot/dataframe/sql/functions.py
@@ -4,8 +4,7 @@
 
 from sqlglot import exp as expression
 from sqlglot.dataframe.sql.column import Column
-from sqlglot.helper import ensure_list
-from sqlglot.helper import flatten as _flatten
+from sqlglot.helper import ensure_list, flatten as _flatten
 
 if t.TYPE_CHECKING:
     from sqlglot.dataframe.sql._typing import ColumnOrLiteral, ColumnOrName
diff --git a/sqlglot/diff.py b/sqlglot/diff.py
--- a/sqlglot/diff.py
+++ b/sqlglot/diff.py
@@ -11,8 +11,7 @@
 from dataclasses import dataclass
 from heapq import heappop, heappush
 
-from sqlglot import Dialect
-from sqlglot import expressions as exp
+from sqlglot import Dialect, expressions as exp
 from sqlglot.helper import ensure_collection
 
 


Test patch:
diff --git a/tests/dataframe/unit/test_functions.py b/tests/dataframe/unit/test_functions.py
--- a/tests/dataframe/unit/test_functions.py
+++ b/tests/dataframe/unit/test_functions.py
@@ -2,8 +2,7 @@
 import inspect
 import unittest
 
-from sqlglot import expressions as exp
-from sqlglot import parse_one
+from sqlglot import expressions as exp, parse_one
 from sqlglot.dataframe.sql import functions as SF
 from sqlglot.errors import ErrorLevel
 
diff --git a/tests/dataframe/unit/test_session.py b/tests/dataframe/unit/test_session.py
--- a/tests/dataframe/unit/test_session.py
+++ b/tests/dataframe/unit/test_session.py
@@ -1,8 +1,7 @@
 from unittest import mock
 
 import sqlglot
-from sqlglot.dataframe.sql import functions as F
-from sqlglot.dataframe.sql import types
+from sqlglot.dataframe.sql import functions as F, types
 from sqlglot.dataframe.sql.session import SparkSession
 from sqlglot.schema import MappingSchema
 from tests.dataframe.unit.dataframe_sql_validator import DataFrameSQLValidator