Skip to content

Make Lark generic on transformer return type#1591

Merged
erezsh merged 3 commits into
masterfrom
issue1186
May 9, 2026
Merged

Make Lark generic on transformer return type#1591
erezsh merged 3 commits into
masterfrom
issue1186

Conversation

@erezsh

@erezsh erezsh commented May 9, 2026

Copy link
Copy Markdown
Member

Fixes #1186

One regression: subclasses of Lark using open() etc. will see a regression. But arguably it is pretty unusual, and we're fixing the much more common use-case.

erezsh added 2 commits May 9, 2026 18:44
Lark is now Generic[_Return_T]. Two @overload stubs on __init__ bind
_Return_T to the transformer's output type when a transformer= is
passed, or to ParseTree otherwise. parse() return type follows.

Also includes type-only tests.
@codecov

codecov Bot commented May 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.06%. Comparing base (3421420) to head (487c6ac).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1591      +/-   ##
==========================================
+ Coverage   90.01%   90.06%   +0.04%     
==========================================
  Files          52       52              
  Lines        8054     8089      +35     
==========================================
+ Hits         7250     7285      +35     
  Misses        804      804              
Flag Coverage Δ
unittests 90.06% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@erezsh

erezsh commented May 9, 2026

Copy link
Copy Markdown
Member Author

@MegaIng Any chance you can give it a quick look?

@MegaIng MegaIng self-assigned this May 9, 2026
@MegaIng

MegaIng commented May 9, 2026

Copy link
Copy Markdown
Member

IMO we should exclude test_typing.py from the coverage check to make the output cleaner. I don't think we currently have a coverage config file.

While reading through the logs I noticed that coverage can't parse test_pattern_matching.py since it's running with 3.8 and pattern matching is only support in 3.10+. I think moving up the coverage run from 3.8 to 3.10 is reasonable, but I am not going to insist if you don't want to.

@MegaIng MegaIng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The implementation looks good, we should just exclude the file from coverage.

The regression with subclasses is annoying, but I agree that this should be rare. It's jut a limitation of python's typing system not having HKTs

@erezsh

erezsh commented May 9, 2026

Copy link
Copy Markdown
Member Author

Looks ok?

@erezsh erezsh merged commit eb015d1 into master May 9, 2026
23 checks passed
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.

Wrong type hit when transformer is provided

2 participants