Comments (2)
The reason the signature is the way it is is because the line attributes might be None
. If you want to write typesafe code, you will need to check for this. If you are checking for this and mypy can't figure out that you are doing the check, that would be a problem on mypy's side, not something we can fix.
from lark.
I thought something like that, this particularly can happen if you inject tokens after the lexer stage. But if you are not injecting tokens, then you end with every function on a transformer following this pattern
def some_rule(...,token:Token,...)->SomeType:
line = token.line #type:ignore
Are there other cases apart from token injection that can make the line a None while column or position isn't?
Otherwise the transformers code can be wrote like:
def some_rule(...,token:Token[int],...)->SomeType:
line = token.line
When you know you are not injecting tokens, and if you are, you can explicitly state that you are generating tokens without information by using Token[None]
from lark.
Related Issues (20)
- Referencing capturing groups errors when using LALR HOT 5
- Breaking changes / docs out of date HOT 7
- GrammarError: Rule 'anycase' used but not defined (in rule pipesyn) HOT 5
- Can not chain or merge two transformers HOT 7
- Black formatter breaks Lark standalone parser generation
- Is it possible to parse a list of terminals? HOT 2
- Partial parsing HOT 11
- Is there a way to receive callbacks when a rule finishes
- Checking for allowed tokens with accepts() triggers transformer callbacks HOT 4
- Directly used literals not returned by transformer HOT 1
- Ability to search for parseable substrings HOT 6
- Improve IMAP ID parser HOT 13
- multiline strings in python3 grammar HOT 1
- Type of `tree.data` is wrong. HOT 1
- File input to `parse` method gives TypeError: object of type '_io.TextIOWrapper' has no len() HOT 5
- CPython 3.11.7 breaks `regex` module compatible pattern width calculations HOT 9
- Exclude classes in create_tranformer by user provided pedicate
- Data structure for getting possible terminal sequences? HOT 2
- AssertionError when using templates HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lark.