Skip to content

wrong typehint for optional value #3330

@luqmansen

Description

@luqmansen

Documentation description

A lot of arguments in the dlt.extract.hints.DltResourceHints.apply_hints function are actually optional, but it's not wrapped with typing.Optional,
making some static linter, such as ruff/pyrefly, mark it as an error if we're providing a None value to it.

Example usecase: I want to set incremental hints based on certain condition

resource.apply_hints(incremental=incremental if condition is True else None,)

dlt/dlt/extract/hints.py

Lines 444 to 457 in 7b6f8c4

table_name: TTableHintTemplate[str] = None,
parent_table_name: TTableHintTemplate[str] = None,
write_disposition: TTableHintTemplate[TWriteDispositionConfig] = None,
columns: TTableHintTemplate[TAnySchemaColumns] = None,
primary_key: TTableHintTemplate[TColumnNames] = None,
merge_key: TTableHintTemplate[TColumnNames] = None,
incremental: TIncrementalConfig = None,
schema_contract: TTableHintTemplate[TSchemaContract] = None,
additional_table_hints: Optional[Dict[str, TTableHintTemplate[Any]]] = None,
table_format: TTableHintTemplate[TTableFormat] = None,
file_format: TTableHintTemplate[TFileFormat] = None,
references: TTableHintTemplate[TTableReferenceParam] = None,
create_table_variant: bool = False,
nested_hints: TTableHintTemplate[Dict[TTableNames, TResourceNestedHints]] = None,

Let me know if this is not intentional. I can create a PR for this. Thanks for the great library!

Are you a dlt user?

Yes, I'm already a dlt user.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttech-debtLeftovers from previous work. Should be fixed over time

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions