-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Filters: --async
and --function
and --class
and various typing ones
#21
Comments
I'll prototype it and play with it and see how it feels. |
This is a pretty fun prototype:
Needs a bit more thought, then tests and docs. |
I didn't implement |
A |
Maybe this:
If you are working on a project and trying to add types to every single function, you can iterate on it using this to find the functions that still need some work: symbex --untyped --partially-typed --signatures |
Maybe Or maybe It would be slightly surprising that while most of these filter options add together, For that reason I think using |
Confirmed, this works already to get all async methods: symbex -d ../datasette -s --async '*.*' |
--async
and --function
and --class
filters?--async
and --function
and --class
and various typing ones
I built a messy prototype of the typing ones and I like them a lot: symbex --typed -s # File: tests/example_symbols.py Line: 50
def func_type_annotations(a: int, b: str) -> bool
# File: tests/example_symbols.py Line: 94
def function_with_non_pep_0484_annotation(x: ?, xx: ?, yy: ?, y: ?, zz: float) -> ?
# File: tests/example_symbols.py Line: 104
def complex_annotations(code: str, symbols: Iterable[str]) -> List[Tuple[(AST, Optional[str])]]
# File: symbex/lib.py Line: 11
def find_symbol_nodes(code: str, filename: str, symbols: Iterable[str]) -> List[Tuple[(AST, Optional[str])]]
# File: symbex/lib.py Line: 35
def code_for_node(code: str, node: AST, class_name: str, signatures: bool) -> Tuple[(str, int)]
# File: symbex/lib.py Line: 66
def match(name: str, symbols: Iterable[str]) -> bool
# File: symbex/lib.py Line: 91
def function_definition(function_node: AST)
# File: symbex/lib.py Line: 193
def annotation_definition(annotation: AST) -> str
# File: symbex/lib.py Line: 241
def annotation_summary(node: AST) -> AnnotationSummary symbex --untyped -s # File: tests/example_symbols.py Line: 10
def func_positional_args(a, b, c)
# File: tests/example_symbols.py Line: 15
async def async_func(a, b, c)
# File: tests/example_symbols.py Line: 20
def func_default_args(a, b=2, c=3)
... |
Am I right that these should always be OR and not AND? I just tried this and it didn't give me what I expected:
Turns out I expected just typed async functions, but I got back ALL async functions and then ALL typed functions. |
I'm going to try these as AND rather than OR and see how that feels. |
Yes, AND for filters feels better. Switching to that. |
This method is failing the test for class ClassForTypedTests:
def method_fully_typed(self, a: int, b: str) -> bool:
pass Because |
I'm going to refactor AnnotationSummary = namedtuple(
"Summary", ["num_arguments", "num_typed", "return_is_typed"]
) I'm going to change it to this: class TypeSummary:
fully: bool
partially: bool
) |
That caused another problem: now |
Here's a fun trick: llm --system 'Suggest several ways to refactor this' ' if (
not symbols
and not signatures
and not async_
and not function
and not class_
and not typed
and not untyped
and not partially_typed
and not fully_typed
):
ctx = click.get_current_context()
click.echo(ctx.get_help())
ctx.exit()' Output:
|
One last thought: an |
The
--signatures
option turns out to be a pretty great way to start navigating a new codebase.It might be useful to be able to filter by types of content. Potentially the following:
--async
- return async function (and method) definitions--function
- just functions--class
- just classes--method
- just class methodsThese would be additive, so the following:
Would return all methods and all functions.
But... what would this do?
Would it return all async functions AND async methods? If so, would combining it with
--function
or--method
not make a difference?Or should there be a
--async-method
filter that's different from--async
(which only gets async functions)?The text was updated successfully, but these errors were encountered: