Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseSegment.pos_marker is typed as non optional but sometimes set to None #2738

Closed
3 tasks done
OTooleMichael opened this issue Feb 28, 2022 · 0 comments · Fixed by #2741
Closed
3 tasks done

BaseSegment.pos_marker is typed as non optional but sometimes set to None #2738

OTooleMichael opened this issue Feb 28, 2022 · 0 comments · Fixed by #2741
Labels
bug Something isn't working

Comments

@OTooleMichael
Copy link
Contributor

Search before asking

  • I searched the issues and found no similar issues.

What Happened

During Fix applications Segments are stripped of their position markers which is against the typing of Segments.

However furthermore this caused an issue when attempting to create a fresh tree segment for insertion. In the code base thus far all inserted segments (from a fix) have been raw and not made of a sequence. However when creating a fresh more complex element eg ColumnReference the sequence will throw because it cannot find a position.

This empty position is truly possible and occurs elsewhere in the code base. However simply switching the typing to Optional[PositionMarker] will throw significant static typing errors.

Expected Behaviour

  1. Typing is consistent
  2. There is methodology for creating complex sequences to insert as a fix

Observed Behaviour

Errors thrown when creating unpositioned Segments (for later Fix insertions)

How to reproduce

    sequence = [
        CodeSegment(raw=table_ref, name="naked_identifier", type="identifier"),
        SymbolSegment(raw=".", type="symbol", name="dot"),
        CodeSegment(raw=column_name, name="naked_identifier", type="identifier"),
    ]
    # This next line cant execute
    new_column = ColumnReferenceSegment(segments=segments, pos_marker=None)
    return LintResult(
            # Reference the element, not the string.
            anchor=anchor,
            description=description,
            fixes=[ LintFix..create_before(anchor, edit_segments=[new_column]) ]
      )

Dialect

NA

Version

0.10.1

Configuration

NA

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant