-
Notifications
You must be signed in to change notification settings - Fork 2
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
Define syntax #5
Comments
I guess it is a good idea to divide that into separate topics, unless they clearly interact. Here are some - it is probably a good idea to support less if that means better syntax.
It might also be worth defining where stenotype syntax is applicable - e.g. tuple syntax |
Thanks for your input @maxfischer2781
I fully agree, in particular I'd add that there is no strict need for completeness, since corner cases should be able to just fall back to regular type annotation.
I agree on the general look. Regarding async, I think its essential to have a good shorthand for it, since async functions are among the worst ones to annotate. There doesn't seem to be a common sign to identify async stuff yet, would it be reasonable to just introduce one? I see
I personally like
I'd like to support
Thanks for gathering all the proposals floating around. My personal favorite is
I never encountered this, but am in no way opposed. The
I'm not familiar with structural types, it sounds a bit like a generic. Is it actually commonly used in python? Regarding (custom?) protocols, I think they might be something for a later point in time, unless you think that they are essential (with the obvious exception of iterable/generator functions, which would be
Optimally, anything that is not a type and not a container would just be interpreted as a literal: A caveat would be that in that case it is impossible to write a function that consumes/returns specific types, since it won't be possible to interpret it as a literal. But this to me falls under the kind of corner cases that should just be written in non-steno.
any, many, or all of the following:
In order to effectively work with this project, it is probably a good idea to provide a cli tool on install that consumes a string and prints the long type annotation, given that it is in a valid context, just to quickly test what is recognized as steno and what isn't: $ stenotype "import typing; typing.List[int]"
import typing
List[int]
$ stenotype "(int|bool, ?str) -> ?'a'|'b'"
Callable[[Union[int, bool], Optional[str]], Optional[Literal['a', 'b']]] |
One could go with how they are used in code. That looks pretty good for docs at least.
Not sure if the more complex ones make sense with nesting - e.g.
I like both
Structural types are basically formalised duck-typing. I have not used them for typing yet, since
Using plain literals is tricky because of conflicts. For example,
I really like the idea of having a CLI tool to test annotations. Do you think it would be feasible to invert this as well?
|
good find, always nice if other people have already sussed out details like "looking good". That said, I need to take a good look at all of them to get a feel for what exactly they do and how prevalent they might be. There is a point to introducing a fixed set of words like
Maybe footguns should be discouraged at some point, but that would be post v1.0
I prefer pipe for terseness, but I'm fine with
I guess I should actually look into import hooks in order to have a qualified opinion, but my gut feeling is that relying on runtime evaluation is going to created a lot more problems than it can solve. I mean, we don't have a chance to even get an AST if we have a file with invalid python expressions, do we? Regarding postponed types, as far as I can see quoting shouldn't be necessary for non-literals in Maybe that's what you also mean, I wasn't 100% sure.
|
Regarding the parser: If we want to use Python's AST (which is likely) then type annotations must be syntactically valid expressions -- not necessarily valid at runtime. For example, Even with postponed annotations, annotations must be valid expressions:
In other words, I see two realistic choices:
A custom parser is unfeasible, since it means every other tool would fail. Personally, I think 1 is the way to go - there are some subtle but noticeable restrictions from using pure Python syntax. At a glance, most things should be possible with pure Python syntax, though. You can test that the ast works exactly the same with and without postponed annotations:
|
I agree on 1 feeling better. I think we might have collected enough now to start a draft, i'll try to propose something by the end of the week. |
closes #7 Motivated by #5, I don't think this proposal is specific enough to close it just yet. A lot of other stuff has also made it into this PR: - small fixes to the workflow file, yaml is a way too permissive format - pushing the docs to gh-pages on every PR merge - adding a bunch of badges to the readme - restoring the "documentation" section to TOOLING.rst - changing the docs look to the flask theme, because I like it better than alabaster
I did not think about Generics/TypeVars yet - good to see you have included them. Having TypeVars defined automatically would be neat. We might want to have some reserved typevars ( If a |
I don't know if it's necessary, but I thought that it might be necessary to require nested quotes for forward references to make them work unambiguously: foo: "['MyType']" # list of MyType elements Any other identifier could work too of course, in case nested quotes look too silly. The main gain would be that we wouldn't need to think about "What if a user calls their class 'await' or 'T'?" scenarios. I must admit that while I added TypeVars and Generics, I never really worked with them in python. Since I don't know how their usage could be improved, I left their descriptions blank. That being said, I think that we could just start prototyping a Would it be alright with you if I close this issue now? |
There should be a human readable syntax definition. This issue will serve as a place to collect requirements, ideas, and restrictions. It will be closed as soon as the rule set has been added to the documentation, which will serve as the source of truth for the implementation.
The text was updated successfully, but these errors were encountered: