Skip to content

refactor(datatypes): improve typing#7654

Open
OutSquareCapital wants to merge 5 commits into
tobymao:mainfrom
OutSquareCapital:dtypes-typing
Open

refactor(datatypes): improve typing#7654
OutSquareCapital wants to merge 5 commits into
tobymao:mainfrom
OutSquareCapital:dtypes-typing

Conversation

@OutSquareCapital
Copy link
Copy Markdown
Contributor

@OutSquareCapital OutSquareCapital commented May 16, 2026

This PR improve the expressions::datatypes::{DataType, DataTypeParam} type safety, with the kwargs argument in DataType::build narrowed from object to a new dedicated TypedDict in the _typing module, and a narrowed this property on DataTypeParam

Comment thread sqlglot/_typing.py


class DataTypeArgs(ParserNoDialectArgs, total=False):
expressions: list[exp.Literal | exp.Neg | exp.DataTypeParam | exp.ColumnDef]
Copy link
Copy Markdown
Contributor Author

@OutSquareCapital OutSquareCapital May 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this couldn't be narrowed in the other way, i.e DataType::expressions, since there's a lot of unsafe attributes acces that would require logic change instead of pure typing changes.

I determined the values simply by dummy typing it as list[float] at first, and then adjusting depending on the errors:

sqlglot\generator.py:5042: error: List item 0 has incompatible type "Literal | Neg"; expected "float"  [list-item]
sqlglot\dialects\dialect.py:1731: error: List item 0 has incompatible type "DataTypeParam"; expected "float"  [list-item]
sqlglot\optimizer\simplify.py:20: error: Library stubs not installed for "dateutil.relativedelta"  [import-untyped]

I also knew that struct types use exp::ColumnDef

@OutSquareCapital OutSquareCapital marked this pull request as ready for review May 16, 2026 10:56
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

Successfully merging this pull request may close these issues.

1 participant