-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use python built in type annotations in LLDB visualizer scripts #134291
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
Conversation
rustbot has assigned @Mark-Simulacrum. Use |
This comment has been minimized.
This comment has been minimized.
Do these check out with mypy where possible?
|
The only thing that currently doesn't is
The main benefit of type hints is the completions tbh. Most of the method names are pretty long and have C++ naming conventions.
How important is backwards compatibility to 3.5? Since this is a debugger visualizer script, afaik it'll always be run through the python distribution that's bundled with LLDB. I checked winlibs and the oldest distributed version (LLVM 14.0.0) was built with python 3.9. I wasn't able to get anything older than LLVM14 on ubuntu either. |
I didn't mean that 3.5 should be our supported version; just that if it is helpful, there is a way to specify content types or nullability that works with older versions. Since the Your version analysis seems correct to me. Maybe we should aim to support down to 3.8 if that is LLVM's policy? |
Ah yeah i forgot about that. |
r? tgross35 r=me if we're good on versions etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested a few things that could be more specific but I think most of this looks good. Thanks for putting up this change, type hints make Python so much nicer to work with.
Please squash once you update.
@rustbot author
src/etc/lldb_lookup.py
Outdated
@@ -19,8 +19,7 @@ def classify_rust_type(type): | |||
return RustType.OTHER | |||
|
|||
|
|||
def summary_lookup(valobj, dict): | |||
# type: (SBValue, dict) -> str | |||
def summary_lookup(valobj: lldb.SBValue, dict) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the dict
arguments get typed as Dict
? There are a few instances of this. They could probably also be renamed to _dict
or _llvm_dict
since AIUI they're supposed to be opaque and unused, any idea why LLVM passes them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose not to since there's no reason to ever use it - anything to dissuade people from trying seemed like a good idea. If you'd like i can add them though. Allegedly LLDB uses them for bookkeeping, but I haven't dug around the source code enough to know how/when they're used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, that is interesting. I wasn't sure what it would be but LLVM actually uses : dict
in their repo a few times, thanks for double checking.
Maybe we could do a bit of both - what about something like LldbOpaque = object
and then using LldbOpaque
as the type hint? Then at least we have something there that also indicates it probably shouldn't be used.
src/etc/lldb_lookup.py
Outdated
@@ -5,11 +5,11 @@ | |||
|
|||
|
|||
# BACKCOMPAT: rust 1.35 | |||
def is_hashbrown_hashmap(hash_map): | |||
def is_hashbrown_hashmap(hash_map) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be:
def is_hashbrown_hashmap(hash_map: SBValue) -> bool:
@@ -111,7 +111,7 @@ def classify_struct(name, fields): | |||
return RustType.STRUCT | |||
|
|||
|
|||
def classify_union(fields): | |||
def classify_union(fields: List) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the List
type be narrowed in this file? Per https://lldb.llvm.org/python_api/lldb.SBType.html#lldb.SBType.fields I think this could be List[SBTypeMember]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file they can't be, as the functions are shared between LLDB and GDB.
f032edd
to
4b00d02
Compare
src/etc/lldb_providers.py
Outdated
class LLDBOpaque: | ||
""" | ||
A type used by LLDB internally. Values of this type should never be used except when passing as | ||
an argument to an LLDB function. | ||
""" | ||
|
||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, you don't need pass
since there is a docstring.
Also I think that technically a global LLDBOpaque = object
would be more accurate since the real type will be an object
but will it will never be a class LLDBOpaque
, but that doesn't matter much (If you leave the class, I would just make it clear in the docstring that this is strictly for typing).
4b00d02
to
693a0d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks for the changes!
@bors r+ rollup |
Rollup of 3 pull requests Successful merges: - rust-lang#134291 (Use python built in type annotations in LLDB visualizer scripts) - rust-lang#134857 (Unsafe binder support in rustdoc) - rust-lang#134957 (chore: fix some typos) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#134291 - Walnut356:type_annots, r=tgross35 Use python built in type annotations in LLDB visualizer scripts Replaces type annotation comments with python's built-in type annotations. Built-in type annotations were added in python 3.5. LLDB [currently recommends (and as of LLVM 21, will enforce)](llvm/llvm-project#114807) a minimum python version of 3.8. Rust's test suite also requires python 3.10.
Replaces type annotation comments with python's built-in type annotations.
Built-in type annotations were added in python 3.5. LLDB currently recommends (and as of LLVM 21, will enforce) a minimum python version of 3.8. Rust's test suite also requires python 3.10.