├── .gitignore ├── .travis.yml ├── CODEOWNERS ├── DCO ├── Dockerfile ├── Jenkinsfile ├── LICENSE ├── MAINTAINERS ├── README.md ├── build.go ├── build.yml ├── driver ├── fixtures │ └── fixtures_test.go ├── impl │ └── impl.go ├── main.go ├── normalizer │ ├── annotation.go │ ├── fixtures │ │ ├── python_example_1.json │ │ └── python_example_2.json │ ├── normalizer.go │ ├── transforms.go │ └── util.go └── sdk_test.go ├── fixtures ├── _integration.py ├── _integration.py.legacy ├── _integration.py.native ├── _integration.py.sem.uast ├── _integration.py.uast ├── _syntax_error.py ├── annotations.py ├── annotations.py.native ├── annotations.py.sem.uast ├── annotations.py.uast ├── aritmeticops.py ├── aritmeticops.py.native ├── aritmeticops.py.sem.uast ├── aritmeticops.py.uast ├── assert_constant.py ├── assert_constant.py.native ├── assert_constant.py.sem.uast ├── assert_constant.py.uast ├── augassign.py ├── augassign.py.native ├── augassign.py.sem.uast ├── augassign.py.uast ├── bench_accumulator_factory.py ├── bench_accumulator_factory.py.native ├── bench_accumulator_factory.py.sem.uast ├── bench_accumulator_factory.py.uast ├── bench_binary_search.py ├── bench_binary_search.py.native ├── bench_binary_search.py.sem.uast ├── bench_binary_search.py.uast ├── bench_ethopian_multiplication.py ├── bench_ethopian_multiplication.py.native ├── bench_ethopian_multiplication.py.sem.uast ├── bench_ethopian_multiplication.py.uast ├── bench_fibonacci.py ├── bench_fibonacci.py.native ├── bench_fibonacci.py.sem.uast ├── bench_fibonacci.py.uast ├── bench_fizzbuzz.py ├── bench_fizzbuzz.py.native ├── bench_fizzbuzz.py.sem.uast ├── bench_fizzbuzz.py.uast ├── bench_gcd.py ├── bench_gcd.py.native ├── bench_gcd.py.sem.uast ├── bench_gcd.py.uast ├── bench_happy_numbers.py ├── bench_happy_numbers.py.native ├── bench_happy_numbers.py.sem.uast ├── bench_happy_numbers.py.uast ├── bench_hundred_doors.py ├── bench_hundred_doors.py.native ├── bench_hundred_doors.py.sem.uast ├── bench_hundred_doors.py.uast ├── bench_is_prime.py ├── bench_is_prime.py.native ├── bench_is_prime.py.sem.uast ├── bench_is_prime.py.uast ├── bench_javaobs.py ├── bench_javaobs.py.native ├── bench_javaobs.py.sem.uast ├── bench_javaobs.py.uast ├── bench_mutual_recursion.py ├── bench_mutual_recursion.py.native ├── bench_mutual_recursion.py.sem.uast ├── bench_mutual_recursion.py.uast ├── bench_n_queens.py ├── bench_n_queens.py.native ├── bench_n_queens.py.sem.uast ├── bench_n_queens.py.uast ├── bench_palindrome.py ├── bench_palindrome.py.native ├── bench_palindrome.py.sem.uast ├── bench_palindrome.py.uast ├── bench_pangram.py ├── bench_pangram.py.native ├── bench_pangram.py.sem.uast ├── bench_pangram.py.uast ├── bench_power_set.py ├── bench_power_set.py.native ├── bench_power_set.py.sem.uast ├── bench_power_set.py.uast ├── bench_towers_hanoi.py ├── bench_towers_hanoi.py.native ├── bench_towers_hanoi.py.sem.uast ├── bench_towers_hanoi.py.uast ├── bitwise.py ├── bitwise.py.native ├── bitwise.py.sem.uast ├── bitwise.py.uast ├── comment_indented.py ├── comment_indented.py.native ├── comment_indented.py.sem.uast ├── comment_indented.py.uast ├── comments.py ├── comments.py.native ├── comments.py.sem.uast ├── comments.py.uast ├── comparisonop.py ├── comparisonop.py.native ├── comparisonop.py.sem.uast ├── comparisonop.py.uast ├── complex.py ├── complex.py.native ├── complex.py.sem.uast ├── complex.py.uast ├── comprehension_dict.py ├── comprehension_dict.py.native ├── comprehension_dict.py.sem.uast ├── comprehension_dict.py.uast ├── comprehension_list.py ├── comprehension_list.py.native ├── comprehension_list.py.sem.uast ├── comprehension_list.py.uast ├── comprehension_set.py ├── comprehension_set.py.native ├── comprehension_set.py.sem.uast ├── comprehension_set.py.uast ├── continue_break.py ├── continue_break.py.native ├── continue_break.py.sem.uast ├── continue_break.py.uast ├── declarations_annotated.py ├── declarations_annotated.py.native ├── declarations_annotated.py.sem.uast ├── declarations_annotated.py.uast ├── ellipsis.py ├── ellipsis.py.native ├── ellipsis.py.sem.uast ├── ellipsis.py.uast ├── empty_comment.py ├── empty_comment.py.native ├── empty_comment.py.sem.uast ├── empty_comment.py.uast ├── except.py ├── except.py.native ├── except.py.sem.uast ├── except.py.uast ├── exec.py ├── exec.py.native ├── exec.py.sem.uast ├── exec.py.uast ├── for.py ├── for.py.native ├── for.py.sem.uast ├── for.py.uast ├── fstring_func.py ├── fstring_func.py.native ├── fstring_func.py.sem.uast ├── fstring_func.py.uast ├── func_with_comments.py ├── func_with_comments.py.native ├── func_with_comments.py.sem.uast ├── func_with_comments.py.uast ├── funcdef_defaults.py ├── funcdef_defaults.py.native ├── funcdef_defaults.py.sem.uast ├── funcdef_defaults.py.uast ├── funcdef_kwonlyargs.py ├── funcdef_kwonlyargs.py.native ├── funcdef_kwonlyargs.py.sem.uast ├── funcdef_kwonlyargs.py.uast ├── functioncalls.py ├── functioncalls.py.native ├── functioncalls.py.sem.uast ├── functioncalls.py.uast ├── hello.py ├── hello.py.native ├── hello.py.sem.uast ├── hello.py.uast ├── if.py ├── if.py.native ├── if.py.sem.uast ├── if.py.uast ├── ifexpression.py ├── ifexpression.py.native ├── ifexpression.py.sem.uast ├── ifexpression.py.uast ├── in.py ├── in.py.native ├── in.py.sem.uast ├── in.py.uast ├── issue102.py ├── issue102.py.native ├── issue102.py.sem.uast ├── issue102.py.uast ├── issue119.py ├── issue119.py.native ├── issue119.py.sem.uast ├── issue119.py.uast ├── issue130.py ├── issue130.py.native ├── issue130.py.sem.uast ├── issue130.py.uast ├── issue167.py ├── issue167.py.native ├── issue167.py.sem.uast ├── issue167.py.uast ├── issue177.py ├── issue177.py.native ├── issue177.py.sem.uast ├── issue177.py.uast ├── issue30.py ├── issue30.py.native ├── issue30.py.sem.uast ├── issue30.py.uast ├── issue51.py ├── issue51.py.native ├── issue51.py.sem.uast ├── issue51.py.uast ├── issue58.py ├── issue58.py.native ├── issue58.py.sem.uast ├── issue58.py.uast ├── issue62.py ├── issue62.py.native ├── issue62.py.sem.uast ├── issue62.py.uast ├── issue62_b.py ├── issue62_b.py.native ├── issue62_b.py.sem.uast ├── issue62_b.py.uast ├── issue76.py ├── issue76.py.native ├── issue76.py.sem.uast ├── issue76.py.uast ├── issue94.py ├── issue94.py.native ├── issue94.py.sem.uast ├── issue94.py.uast ├── issue96.py ├── issue96.py.native ├── issue96.py.sem.uast ├── issue96.py.uast ├── issue97_assign.py ├── issue97_assign.py.native ├── issue97_assign.py.sem.uast ├── issue97_assign.py.uast ├── issue97_equal.py ├── issue97_equal.py.native ├── issue97_equal.py.sem.uast ├── issue97_equal.py.uast ├── issue97_lessThan.py ├── issue97_lessThan.py.native ├── issue97_lessThan.py.sem.uast ├── issue97_lessThan.py.uast ├── issue_182.py ├── issue_182.py.native ├── issue_182.py.sem.uast ├── issue_182.py.uast ├── issue_server101.py ├── issue_server101.py.native ├── issue_server101.py.sem.uast ├── issue_server101.py.uast ├── lambda.py ├── lambda.py.native ├── lambda.py.sem.uast ├── lambda.py.uast ├── line_comment.py ├── line_comment.py.native ├── line_comment.py.sem.uast ├── line_comment.py.uast ├── literals_assign.py ├── literals_assign.py.native ├── literals_assign.py.sem.uast ├── literals_assign.py.uast ├── loop_if.py ├── loop_if.py.native ├── loop_if.py.sem.uast ├── loop_if.py.uast ├── other_statements.py ├── other_statements.py.native ├── other_statements.py.sem.uast ├── other_statements.py.uast ├── pass.py ├── pass.py.native ├── pass.py.sem.uast ├── pass.py.uast ├── print.py ├── print.py.native ├── print.py.sem.uast ├── print.py.uast ├── qualified.py ├── qualified.py.native ├── qualified.py.sem.uast ├── qualified.py.uast ├── receiver.py ├── receiver.py.native ├── receiver.py.sem.uast ├── receiver.py.uast ├── repr.py ├── repr.py.native ├── repr.py.sem.uast ├── repr.py.uast ├── sameline.py ├── sameline.py.native ├── sameline.py.sem.uast ├── sameline.py.uast ├── sorting.py ├── sorting.py.native ├── sorting.py.sem.uast ├── sorting.py.uast ├── string_format.py ├── string_format.py.native ├── string_format.py.sem.uast ├── string_format.py.uast ├── string_normal.py ├── string_normal.py.native ├── string_normal.py.sem.uast ├── string_normal.py.uast ├── string_triple.py ├── string_triple.py.native ├── string_triple.py.sem.uast ├── string_triple.py.uast ├── test.py ├── test.py.native ├── test.py.sem.uast ├── test.py.uast ├── u2_class_accessors.py ├── u2_class_accessors.py.native ├── u2_class_accessors.py.sem.uast ├── u2_class_accessors.py.uast ├── u2_class_constructor.py ├── u2_class_constructor.py.native ├── u2_class_constructor.py.sem.uast ├── u2_class_constructor.py.uast ├── u2_class_destructor.py ├── u2_class_destructor.py.native ├── u2_class_destructor.py.sem.uast ├── u2_class_destructor.py.uast ├── u2_class_doc.py ├── u2_class_doc.py.native ├── u2_class_doc.py.sem.uast ├── u2_class_doc.py.uast ├── u2_class_empty.py ├── u2_class_empty.py.native ├── u2_class_empty.py.sem.uast ├── u2_class_empty.py.uast ├── u2_class_field.py ├── u2_class_field.py.native ├── u2_class_field.py.sem.uast ├── u2_class_field.py.uast ├── u2_class_field_binding.py ├── u2_class_field_binding.py.native ├── u2_class_field_binding.py.sem.uast ├── u2_class_field_binding.py.uast ├── u2_class_field_qualifiers.py ├── u2_class_field_qualifiers.py.native ├── u2_class_field_qualifiers.py.sem.uast ├── u2_class_field_qualifiers.py.uast ├── u2_class_inherit.py ├── u2_class_inherit.py.native ├── u2_class_inherit.py.sem.uast ├── u2_class_inherit.py.uast ├── u2_class_inner.py ├── u2_class_inner.py.native ├── u2_class_inner.py.sem.uast ├── u2_class_inner.py.uast ├── u2_class_metaclass_python3.py ├── u2_class_metaclass_python3.py.native ├── u2_class_metaclass_python3.py.sem.uast ├── u2_class_metaclass_python3.py.uast ├── u2_class_method.py ├── u2_class_method.py.native ├── u2_class_method.py.sem.uast ├── u2_class_method.py.uast ├── u2_class_method_binding.py ├── u2_class_method_binding.py.native ├── u2_class_method_binding.py.sem.uast ├── u2_class_method_binding.py.uast ├── u2_class_method_private.py ├── u2_class_method_private.py.native ├── u2_class_method_private.py.sem.uast ├── u2_class_method_private.py.uast ├── u2_class_method_qualifiers.py ├── u2_class_method_qualifiers.py.native ├── u2_class_method_qualifiers.py.sem.uast ├── u2_class_method_qualifiers.py.uast ├── u2_class_specific_metaclass.py ├── u2_class_specific_metaclass.py.native ├── u2_class_specific_metaclass.py.sem.uast ├── u2_class_specific_metaclass.py.uast ├── u2_class_specific_slots.py ├── u2_class_specific_slots.py.native ├── u2_class_specific_slots.py.sem.uast ├── u2_class_specific_slots.py.uast ├── u2_class_tag.py ├── u2_class_tag.py.native ├── u2_class_tag.py.sem.uast ├── u2_class_tag.py.uast ├── u2_class_this.py ├── u2_class_this.py.native ├── u2_class_this.py.sem.uast ├── u2_class_this.py.uast ├── u2_func_annotated.py ├── u2_func_annotated.py.native ├── u2_func_annotated.py.sem.uast ├── u2_func_annotated.py.uast ├── u2_func_anonymous.py ├── u2_func_anonymous.py.native ├── u2_func_anonymous.py.sem.uast ├── u2_func_anonymous.py.uast ├── u2_func_async.py ├── u2_func_async.py.native ├── u2_func_async.py.sem.uast ├── u2_func_async.py.uast ├── u2_func_doc.py ├── u2_func_doc.py.native ├── u2_func_doc.py.sem.uast ├── u2_func_doc.py.uast ├── u2_func_empty.py ├── u2_func_empty.py.native ├── u2_func_empty.py.sem.uast ├── u2_func_empty.py.uast ├── u2_func_inner.py ├── u2_func_inner.py.native ├── u2_func_inner.py.sem.uast ├── u2_func_inner.py.uast ├── u2_func_params_default.py ├── u2_func_params_default.py.native ├── u2_func_params_default.py.sem.uast ├── u2_func_params_default.py.uast ├── u2_func_params_kwonlyargs.py ├── u2_func_params_kwonlyargs.py.native ├── u2_func_params_kwonlyargs.py.sem.uast ├── u2_func_params_kwonlyargs.py.uast ├── u2_func_params_kwonlyargs_default.py ├── u2_func_params_kwonlyargs_default.py.native ├── u2_func_params_kwonlyargs_default.py.sem.uast ├── u2_func_params_kwonlyargs_default.py.uast ├── u2_func_params_variadic_list.py ├── u2_func_params_variadic_list.py.native ├── u2_func_params_variadic_list.py.sem.uast ├── u2_func_params_variadic_list.py.uast ├── u2_func_params_variadic_map.py ├── u2_func_params_variadic_map.py.native ├── u2_func_params_variadic_map.py.sem.uast ├── u2_func_params_variadic_map.py.uast ├── u2_func_return_multiple.py ├── u2_func_return_multiple.py.native ├── u2_func_return_multiple.py.sem.uast ├── u2_func_return_multiple.py.uast ├── u2_func_simple.py ├── u2_func_simple.py.native ├── u2_func_simple.py.sem.uast ├── u2_func_simple.py.uast ├── u2_func_tagged.py ├── u2_func_tagged.py.native ├── u2_func_tagged.py.sem.uast ├── u2_func_tagged.py.uast ├── u2_import_module_alias.py ├── u2_import_module_alias.py.native ├── u2_import_module_alias.py.sem.uast ├── u2_import_module_alias.py.uast ├── u2_import_multiple.py ├── u2_import_multiple.py.native ├── u2_import_multiple.py.sem.uast ├── u2_import_multiple.py.uast ├── u2_import_path.py ├── u2_import_path.py.native ├── u2_import_path.py.sem.uast ├── u2_import_path.py.uast ├── u2_import_relativepath.py ├── u2_import_relativepath.py.native ├── u2_import_relativepath.py.sem.uast ├── u2_import_relativepath.py.uast ├── u2_import_rename.py ├── u2_import_rename.py.native ├── u2_import_rename.py.sem.uast ├── u2_import_rename.py.uast ├── u2_import_simple.py ├── u2_import_simple.py.native ├── u2_import_simple.py.sem.uast ├── u2_import_simple.py.uast ├── u2_import_subsymbol.py ├── u2_import_subsymbol.py.native ├── u2_import_subsymbol.py.sem.uast ├── u2_import_subsymbol.py.uast ├── u2_import_subsymbol_alias.py ├── u2_import_subsymbol_alias.py.native ├── u2_import_subsymbol_alias.py.sem.uast ├── u2_import_subsymbol_alias.py.uast ├── u2_import_subsymbols_namespaced.py ├── u2_import_subsymbols_namespaced.py.native ├── u2_import_subsymbols_namespaced.py.sem.uast ├── u2_import_subsymbols_namespaced.py.uast ├── unary.py ├── unary.py.native ├── unary.py.sem.uast ├── unary.py.uast ├── unicode.py ├── unicode.py.native ├── unicode.py.sem.uast ├── unicode.py.uast ├── vararg_python2.py ├── vararg_python2.py.native ├── vararg_python2.py.sem.uast ├── vararg_python2.py.uast ├── while.py ├── while.py.native ├── while.py.sem.uast ├── while.py.uast ├── with.py ├── with.py.native ├── with.py.sem.uast └── with.py.uast ├── go.mod ├── go.sum ├── manifest.toml ├── native ├── README.md ├── dev_deps │ └── README.md ├── gogen │ └── gogen.py ├── native.sh └── python_package │ ├── python_driver │ ├── __init__.py │ ├── __main__.py │ ├── astimprove.py │ ├── base_token.py │ ├── cli.py │ ├── locationfixer.py │ ├── noop_extractor.py │ ├── processor_configs.py │ ├── requestprocessor.py │ ├── types.py │ └── version.py │ ├── requirements.txt │ ├── setup.py │ └── test │ ├── coverage.sh │ ├── data │ └── helloworld.py │ ├── fixtures │ ├── detector.py │ └── exported_dict.py │ ├── integration_output.json │ ├── integration_test.sh │ ├── sendmsg.py │ ├── test_alpine.sh │ ├── test_nodocker.sh │ ├── test_python_driver.py │ ├── test_ubuntu.sh │ └── typecheck.sh ├── test.go └── update.go /.gitignore: -------------------------------------------------------------------------------- 1 | .sdk 2 | build 3 | .mypy_cache 4 | fixtures/*_got 5 | .local/* 6 | .cache/* 7 | vendor/* 8 | __pycache__ 9 | makebuild.sh 10 | vendor/* 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - '1.13.x' 5 | 6 | services: 7 | - docker 8 | 9 | env: 10 | global: 11 | - GO111MODULE=on 12 | - BBLFSHD_VERSION=v2.12.1 13 | 14 | install: 15 | - go mod download 16 | - docker pull bblfsh/bblfshd:$BBLFSHD_VERSION 17 | 18 | script: 19 | - go test ./driver/... 20 | - go run build.go ci-build 21 | - go run test.go --bblfshd $BBLFSHD_VERSION ci-build 22 | 23 | after_success: 24 | - go run github.com/bblfsh/sdk/v3/cmd/bblfsh-sdk push ci-build 25 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @bblfsh/maintainers 2 | -------------------------------------------------------------------------------- /DCO: -------------------------------------------------------------------------------- 1 | Developer's Certificate of Origin 1.1 2 | 3 | By making a contribution to this project, I certify that: 4 | 5 | (a) The contribution was created in whole or in part by me and I 6 | have the right to submit it under the open source license 7 | indicated in the file; or 8 | 9 | (b) The contribution is based upon previous work that, to the best 10 | of my knowledge, is covered under an appropriate open source 11 | license and I have the right under that license to submit that 12 | work with modifications, whether created in whole or in part 13 | by me, under the same open source license (unless I am 14 | permitted to submit under a different license), as indicated 15 | in the file; or 16 | 17 | (c) The contribution was provided directly to me by some other 18 | person who certified (a), (b) or (c) and I have not modified 19 | it. 20 | 21 | (d) I understand and agree that this project and the contribution 22 | are public and that a record of the contribution (including all 23 | personal information I submit with it, including my sign-off) is 24 | maintained indefinitely and may be redistributed consistent with 25 | this project or the open source license(s) involved. 26 | -------------------------------------------------------------------------------- /MAINTAINERS: -------------------------------------------------------------------------------- 1 | Denys Smirnov (@dennwc) 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python driver for [Babelfish](https://github.com/bblfsh/bblfshd) ![Driver Status](https://img.shields.io/badge/status-beta-dbd25c.svg) [![Build Status](https://travis-ci.org/bblfsh/python-driver.svg?branch=master)](https://travis-ci.org/bblfsh/python-driver) ![Native Version](https://img.shields.io/badge/python%20version-3.6-aa93ea.svg) ![Go Version](https://img.shields.io/badge/go%20version-1.13-63afbf.svg) 2 | 3 | Development Environment 4 | ----------------------- 5 | 6 | Requirements: 7 | - `docker` 8 | - Go 1.13+ 9 | 10 | To initialize the build system execute: `go test ./driver`, at the root of the project. This will generate the `Dockerfile` for this driver. 11 | 12 | To run the tests just execute `go run test.go`, this will start the test over the native and the Go components of the driver using Docker. 13 | 14 | The build is done executing `go run build.go`. To evaluate the result using a docker container, execute: 15 | `go run build.go test-driver && docker run -it test-driver`. 16 | 17 | If the project is located under `$GOPATH`, run all the above with `GO111MODULE=on` environment variable, 18 | or move the project to any other directory outside of `$GOPATH`. 19 | 20 | License 21 | ------- 22 | 23 | GPLv3, see [LICENSE](LICENSE) 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /build.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | 8 | "github.com/bblfsh/sdk/v3/build" 9 | ) 10 | 11 | func main() { 12 | flag.Parse() 13 | if err := runBuild("."); err != nil { 14 | fmt.Fprintln(os.Stderr, err) 15 | os.Exit(1) 16 | } 17 | } 18 | 19 | func runBuild(root string) error { 20 | args := flag.Args() 21 | name := "" 22 | if len(args) != 0 { 23 | name = args[0] 24 | } 25 | d, err := build.NewDriver(root) 26 | if err != nil { 27 | return err 28 | } 29 | id, err := d.Build(name) 30 | if err != nil { 31 | return err 32 | } 33 | fmt.Println(id) 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /build.yml: -------------------------------------------------------------------------------- 1 | sdk: '2' 2 | go-runtime: 3 | version: '1.13-alpine' 4 | native: 5 | image: 'python:3.6-alpine' 6 | deps: 7 | - 'apk add python2' 8 | static: 9 | - path: 'native.sh' 10 | dest: 'native' 11 | build: 12 | image: 'python:3.6-alpine' 13 | run: 14 | - 'pip3 install -U --prefix=./.local ./python_package' 15 | artifacts: 16 | - path: '/native/.local' 17 | dest: '.local' 18 | test: 19 | run: 20 | - 'cd ./python_package/test && PYTHONPATH=../../.local:$PYTHONPATH python3 -m unittest discover' 21 | -------------------------------------------------------------------------------- /driver/fixtures/fixtures_test.go: -------------------------------------------------------------------------------- 1 | package fixtures 2 | 3 | import ( 4 | "path/filepath" 5 | "testing" 6 | 7 | "github.com/bblfsh/python-driver/driver/normalizer" 8 | "github.com/bblfsh/sdk/v3/driver" 9 | "github.com/bblfsh/sdk/v3/driver/fixtures" 10 | "github.com/bblfsh/sdk/v3/driver/native" 11 | ) 12 | 13 | const projectRoot = "../../" 14 | 15 | var Suite = &fixtures.Suite{ 16 | Lang: "python", 17 | Ext: ".py", 18 | Path: filepath.Join(projectRoot, fixtures.Dir), 19 | NewDriver: func() driver.Native { 20 | return native.NewDriverAt(filepath.Join(projectRoot, "build/bin/native"), native.UTF8) 21 | }, 22 | Transforms: normalizer.Transforms, 23 | BenchName: "issue_server101", 24 | Semantic: fixtures.SemanticConfig{ 25 | BlacklistTypes: []string{ 26 | "AsyncFunctionDef", 27 | "Attribute", 28 | "BoolLiteral", 29 | "Bytes", 30 | "FunctionDef", 31 | "Import", 32 | "ImportFrom", 33 | "Name", 34 | "NoopLine", 35 | "NoopSameLine", 36 | "Str", 37 | "StringLiteral", 38 | "alias", 39 | "arg", 40 | "kwarg", 41 | "kwonly_arg", 42 | "vararg", 43 | }, 44 | }, 45 | } 46 | 47 | func TestPythonDriver(t *testing.T) { 48 | Suite.RunTests(t) 49 | } 50 | 51 | func BenchmarkPythonDriver(b *testing.B) { 52 | Suite.RunBenchmarks(b) 53 | } 54 | -------------------------------------------------------------------------------- /driver/impl/impl.go: -------------------------------------------------------------------------------- 1 | package impl 2 | 3 | import ( 4 | "github.com/bblfsh/sdk/v3/driver/native" 5 | "github.com/bblfsh/sdk/v3/driver/server" 6 | ) 7 | 8 | func init() { 9 | // Can be overridden to link a native driver into a Go driver server. 10 | server.DefaultDriver = native.NewDriver(native.UTF8) 11 | } 12 | -------------------------------------------------------------------------------- /driver/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "github.com/bblfsh/python-driver/driver/impl" 5 | "github.com/bblfsh/python-driver/driver/normalizer" 6 | 7 | "github.com/bblfsh/sdk/v3/driver/server" 8 | ) 9 | 10 | func main() { 11 | server.Run(normalizer.Transforms) 12 | } 13 | -------------------------------------------------------------------------------- /driver/normalizer/transforms.go: -------------------------------------------------------------------------------- 1 | package normalizer 2 | 3 | import "github.com/bblfsh/sdk/v3/driver" 4 | 5 | var Transforms = driver.Transforms{ 6 | Namespace: "python", 7 | Preprocess: Preprocess, 8 | PreprocessCode: PreprocessCode, 9 | Normalize: Normalize, 10 | Annotations: Native, 11 | } 12 | -------------------------------------------------------------------------------- /driver/sdk_test.go: -------------------------------------------------------------------------------- 1 | package main_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/bblfsh/sdk/v3/build" 7 | ) 8 | 9 | func TestSDKUpToDate(t *testing.T) { 10 | printf := func(format string, args ...interface{}) (int, error) { 11 | t.Logf(format, args...) 12 | return 0, nil 13 | } 14 | err := build.UpdateSDK("../", &build.UpdateOptions{ 15 | DryRun: true, 16 | Debug: printf, 17 | Notice: printf, 18 | Warning: printf, 19 | }) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /fixtures/_integration.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | pass 3 | -------------------------------------------------------------------------------- /fixtures/_integration.py.legacy: -------------------------------------------------------------------------------- 1 | Module { 2 | . Roles: File,Module 3 | . Children: { 4 | . . 0: ClassDef { 5 | . . . Roles: Type,Declaration,Identifier,Statement 6 | . . . TOKEN "testcls1" 7 | . . . StartPosition: { 8 | . . . . Offset: 6 9 | . . . . Line: 1 10 | . . . . Col: 7 11 | . . . } 12 | . . . EndPosition: { 13 | . . . . Offset: 14 14 | . . . . Line: 1 15 | . . . . Col: 15 16 | . . . } 17 | . . . Properties: { 18 | . . . . internalRole: body 19 | . . . } 20 | . . . Children: { 21 | . . . . 0: ClassDef.bases { 22 | . . . . . Roles: Type,Declaration,Base 23 | . . . . . Properties: { 24 | . . . . . . internalRole: bases 25 | . . . . . } 26 | . . . . } 27 | . . . . 1: ClassDef.decorator_list { 28 | . . . . . Roles: Type,Declaration,Call,Incomplete 29 | . . . . . Properties: { 30 | . . . . . . internalRole: decorator_list 31 | . . . . . } 32 | . . . . } 33 | . . . . 2: ClassDef.body { 34 | . . . . . Roles: Type,Declaration,Body 35 | . . . . . Properties: { 36 | . . . . . . internalRole: body 37 | . . . . . } 38 | . . . . . Children: { 39 | . . . . . . 0: Pass { 40 | . . . . . . . Roles: Noop,Statement 41 | . . . . . . . TOKEN "pass" 42 | . . . . . . . StartPosition: { 43 | . . . . . . . . Offset: 20 44 | . . . . . . . . Line: 2 45 | . . . . . . . . Col: 5 46 | . . . . . . . } 47 | . . . . . . . EndPosition: { 48 | . . . . . . . . Offset: 24 49 | . . . . . . . . Line: 2 50 | . . . . . . . . Col: 9 51 | . . . . . . . } 52 | . . . . . . . Properties: { 53 | . . . . . . . . internalRole: body_stmts 54 | . . . . . . . } 55 | . . . . . . } 56 | . . . . . } 57 | . . . . } 58 | . . . } 59 | . . } 60 | . } 61 | } 62 | -------------------------------------------------------------------------------- /fixtures/_integration.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | 'ast_type': "Pass", 11 | 'col_offset': 5, 12 | 'end_col_offset': 9, 13 | 'end_lineno': 2, 14 | lineno: 2, 15 | }, 16 | ], 17 | 'col_offset': 7, 18 | 'decorator_list': [], 19 | 'end_col_offset': 15, 20 | 'end_lineno': 1, 21 | keywords: [], 22 | lineno: 1, 23 | name: "testcls1", 24 | }, 25 | ], 26 | }, 27 | } -------------------------------------------------------------------------------- /fixtures/_integration.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:ClassDef", 7 | '@token': "testcls1", 8 | '@role': [Declaration, Identifier, Statement, Type], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 6, 12 | line: 1, 13 | col: 7, 14 | }, 15 | end: { '@type': "uast:Position", 16 | offset: 14, 17 | line: 1, 18 | col: 15, 19 | }, 20 | }, 21 | bases: { '@type': "python:ClassDef.bases", 22 | '@role': [Base, Declaration, Type], 23 | bases: [], 24 | }, 25 | body: { '@type': "python:ClassDef.body", 26 | '@role': [Body, Declaration, Type], 27 | 'body_stmts': [ 28 | { '@type': "python:Pass", 29 | '@token': "pass", 30 | '@role': [Noop, Statement], 31 | '@pos': { '@type': "uast:Positions", 32 | start: { '@type': "uast:Position", 33 | offset: 20, 34 | line: 2, 35 | col: 5, 36 | }, 37 | end: { '@type': "uast:Position", 38 | offset: 24, 39 | line: 2, 40 | col: 9, 41 | }, 42 | }, 43 | }, 44 | ], 45 | }, 46 | 'decorator_list': { '@type': "python:ClassDef.decorator_list", 47 | '@role': [Call, Declaration, Incomplete, Type], 48 | decorators: [], 49 | }, 50 | keywords: [], 51 | }, 52 | ], 53 | } -------------------------------------------------------------------------------- /fixtures/_integration.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "ClassDef", 7 | '@token': "testcls1", 8 | '@role': [Declaration, Identifier, Statement, Type], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 6, 12 | line: 1, 13 | col: 7, 14 | }, 15 | end: { '@type': "uast:Position", 16 | offset: 14, 17 | line: 1, 18 | col: 15, 19 | }, 20 | }, 21 | bases: { '@type': "ClassDef.bases", 22 | '@role': [Base, Declaration, Type], 23 | bases: [], 24 | }, 25 | body: { '@type': "ClassDef.body", 26 | '@role': [Body, Declaration, Type], 27 | 'body_stmts': [ 28 | { '@type': "Pass", 29 | '@token': "pass", 30 | '@role': [Noop, Statement], 31 | '@pos': { '@type': "uast:Positions", 32 | start: { '@type': "uast:Position", 33 | offset: 20, 34 | line: 2, 35 | col: 5, 36 | }, 37 | end: { '@type': "uast:Position", 38 | offset: 24, 39 | line: 2, 40 | col: 9, 41 | }, 42 | }, 43 | }, 44 | ], 45 | }, 46 | 'decorator_list': { '@type': "ClassDef.decorator_list", 47 | '@role': [Call, Declaration, Incomplete, Type], 48 | decorators: [], 49 | }, 50 | keywords: [], 51 | }, 52 | ], 53 | } -------------------------------------------------------------------------------- /fixtures/_syntax_error.py: -------------------------------------------------------------------------------- 1 | def testfnc1(a, b): 2 | = b 3 | return 1 4 | -------------------------------------------------------------------------------- /fixtures/annotations.py: -------------------------------------------------------------------------------- 1 | a: int = 1 2 | b: float 3 | def somefunc(a: int, b: str) -> float: 4 | return 0.0 5 | -------------------------------------------------------------------------------- /fixtures/aritmeticops.py: -------------------------------------------------------------------------------- 1 | 1+2 2 | 1-2 3 | 1*2 4 | 1/2 5 | 1//2 6 | 1%2 7 | 1**2 8 | # 1@2 FIXME: matmul 9 | -------------------------------------------------------------------------------- /fixtures/assert_constant.py: -------------------------------------------------------------------------------- 1 | assert(True) 2 | assert True 3 | assert True, "assert message" 4 | -------------------------------------------------------------------------------- /fixtures/assert_constant.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assert", 7 | 'col_offset': 1, 8 | 'end_col_offset': 7, 9 | 'end_lineno': 1, 10 | lineno: 1, 11 | msg: ~, 12 | test: { 13 | LiteralValue: "True", 14 | 'ast_type': "BoolLiteral", 15 | 'col_offset': 8, 16 | 'end_col_offset': 12, 17 | 'end_lineno': 1, 18 | lineno: 1, 19 | value: true, 20 | }, 21 | }, 22 | { 23 | 'ast_type': "Assert", 24 | 'col_offset': 1, 25 | 'end_col_offset': 7, 26 | 'end_lineno': 2, 27 | lineno: 2, 28 | msg: ~, 29 | test: { 30 | LiteralValue: "True", 31 | 'ast_type': "BoolLiteral", 32 | 'col_offset': 8, 33 | 'end_col_offset': 12, 34 | 'end_lineno': 2, 35 | lineno: 2, 36 | value: true, 37 | }, 38 | }, 39 | { 40 | 'ast_type': "Assert", 41 | 'col_offset': 1, 42 | 'end_col_offset': 7, 43 | 'end_lineno': 3, 44 | lineno: 3, 45 | msg: { 46 | 'ast_type': "Str", 47 | 'col_offset': 14, 48 | 'end_col_offset': 30, 49 | 'end_lineno': 3, 50 | lineno: 3, 51 | s: "assert message", 52 | }, 53 | test: { 54 | LiteralValue: "True", 55 | 'ast_type': "BoolLiteral", 56 | 'col_offset': 8, 57 | 'end_col_offset': 12, 58 | 'end_lineno': 3, 59 | lineno: 3, 60 | value: true, 61 | }, 62 | }, 63 | ], 64 | }, 65 | } -------------------------------------------------------------------------------- /fixtures/augassign.py: -------------------------------------------------------------------------------- 1 | a += 1 2 | a -= 1 3 | a *= 1 4 | a /= 1 5 | -------------------------------------------------------------------------------- /fixtures/bench_accumulator_factory.py: -------------------------------------------------------------------------------- 1 | def accumulator(sum): 2 | def f(n): 3 | nonlocal sum 4 | sum += n 5 | return sum 6 | return f 7 | 8 | x = accumulator(1) 9 | x(5) 10 | print(accumulator(3)) 11 | print(x(2.3)) 12 | -------------------------------------------------------------------------------- /fixtures/bench_binary_search.py: -------------------------------------------------------------------------------- 1 | def binary_search(l, value): 2 | low = 0 3 | high = len(l)-1 4 | while low <= high: 5 | mid = (low+high)//2 6 | if l[mid] > value: high = mid-1 7 | elif l[mid] < value: low = mid+1 8 | else: return mid 9 | return -1 10 | -------------------------------------------------------------------------------- /fixtures/bench_ethopian_multiplication.py: -------------------------------------------------------------------------------- 1 | tutor = True 2 | 3 | from itertools import izip, takewhile 4 | 5 | def iterate(function, arg): 6 | while 1: 7 | yield arg 8 | arg = function(arg) 9 | 10 | def halve(x): return x // 2 11 | def double(x): return x * 2 12 | def even(x): return x % 2 == 0 13 | 14 | def show_heading(multiplier, multiplicand): 15 | print "Multiplying %d by %d" % (multiplier, multiplicand), 16 | print "using Ethiopian multiplication:" 17 | print 18 | 19 | TABLE_FORMAT = "%8s %8s %8s %8s %8s" 20 | 21 | def show_table(table): 22 | for p, q in table: 23 | print TABLE_FORMAT % (p, q, "->", 24 | p, q if not even(p) else "-" * len(str(q))) 25 | 26 | def show_result(result): 27 | print TABLE_FORMAT % ('', '', '', '', "=" * (len(str(result)) + 1)) 28 | print TABLE_FORMAT % ('', '', '', '', result) 29 | 30 | def ethiopian(multiplier, multiplicand): 31 | def column1(x): return takewhile(lambda v: v >= 1, iterate(halve, x)) 32 | def column2(x): return iterate(double, x) 33 | def rows(x, y): return izip(column1(x), column2(y)) 34 | table = rows(multiplier, multiplicand) 35 | if tutor: 36 | table = list(table) 37 | show_heading(multiplier, multiplicand) 38 | show_table(table) 39 | result = sum(q for p, q in table if not even(p)) 40 | if tutor: 41 | show_result(result) 42 | return result 43 | -------------------------------------------------------------------------------- /fixtures/bench_fibonacci.py: -------------------------------------------------------------------------------- 1 | def fibRec(n): 2 | if n < 2: 3 | return n 4 | else: 5 | return fibRec(n-1) + fibRec(n-2) 6 | -------------------------------------------------------------------------------- /fixtures/bench_fizzbuzz.py: -------------------------------------------------------------------------------- 1 | for i in xrange(1, 101): 2 | if i % 15 == 0: 3 | print "FizzBuzz" 4 | elif i % 3 == 0: 5 | print "Fizz" 6 | elif i % 5 == 0: 7 | print "Buzz" 8 | else: 9 | print i 10 | -------------------------------------------------------------------------------- /fixtures/bench_gcd.py: -------------------------------------------------------------------------------- 1 | def gcd_bin(u, v): 2 | u, v = abs(u), abs(v) # u >= 0, v >= 0 3 | if u < v: 4 | u, v = v, u # u >= v >= 0 5 | if v == 0: 6 | return u 7 | 8 | # u >= v > 0 9 | k = 1 10 | while u & 1 == 0 and v & 1 == 0: # u, v - even 11 | u >>= 1; v >>= 1 12 | k <<= 1 13 | 14 | t = -v if u & 1 else u 15 | while t: 16 | while t & 1 == 0: 17 | t >>= 1 18 | if t > 0: 19 | u = t 20 | else: 21 | v = -t 22 | t = u - v 23 | return u * k 24 | -------------------------------------------------------------------------------- /fixtures/bench_happy_numbers.py: -------------------------------------------------------------------------------- 1 | def happy(n): 2 | past = set() 3 | while n != 1: 4 | n = sum(int(i)**2 for i in str(n)) 5 | if n in past: 6 | return False 7 | past.add(n) 8 | return True 9 | -------------------------------------------------------------------------------- /fixtures/bench_hundred_doors.py: -------------------------------------------------------------------------------- 1 | doors = [False] * 100 2 | for i in range(100): 3 | for j in range(i, 100, i+1): 4 | doors[j] = not doors[j] 5 | print("Door %d:" % (i+1), 'open' if doors[i] else 'close') 6 | -------------------------------------------------------------------------------- /fixtures/bench_is_prime.py: -------------------------------------------------------------------------------- 1 | def prime3(a): 2 | if a < 2: return False 3 | if a == 2 or a == 3: return True # manually test 2 and 3 4 | if a % 2 == 0 or a % 3 == 0: return False # exclude multiples of 2 and 3 5 | 6 | maxDivisor = a**0.5 7 | d, i = 5, 2 8 | while d <= maxDivisor: 9 | if a % d == 0: return False 10 | d += i 11 | i = 6 - i # this modifies 2 into 4 and viceversa 12 | 13 | return True 14 | -------------------------------------------------------------------------------- /fixtures/bench_mutual_recursion.py: -------------------------------------------------------------------------------- 1 | def F(n): return 1 if n == 0 else n - M(F(n-1)) 2 | def M(n): return 0 if n == 0 else n - F(M(n-1)) 3 | 4 | print ([ F(n) for n in range(20) ]) 5 | print ([ M(n) for n in range(20) ]) 6 | -------------------------------------------------------------------------------- /fixtures/bench_n_queens.py: -------------------------------------------------------------------------------- 1 | def queens(n): 2 | a = list(range(n)) 3 | up = [True]*(2*n - 1) 4 | down = [True]*(2*n - 1) 5 | def sub(i): 6 | if i == n: 7 | yield tuple(a) 8 | else: 9 | for k in range(i, n): 10 | j = a[k] 11 | p = i + j 12 | q = i - j + n - 1 13 | if up[p] and down[q]: 14 | up[p] = down[q] = False 15 | a[i], a[k] = a[k], a[i] 16 | yield from sub(i + 1) 17 | up[p] = down[q] = True 18 | a[i], a[k] = a[k], a[i] 19 | yield from sub(0) 20 | -------------------------------------------------------------------------------- /fixtures/bench_palindrome.py: -------------------------------------------------------------------------------- 1 | def is_palindrome_r(s): 2 | if len(s) <= 1: 3 | return True 4 | elif s[0] != s[-1]: 5 | return False 6 | else: 7 | return is_palindrome_r(s[1:-1]) 8 | -------------------------------------------------------------------------------- /fixtures/bench_pangram.py: -------------------------------------------------------------------------------- 1 | import string, sys 2 | if sys.version_info[0] < 3: 3 | input = raw_input 4 | 5 | def ispangram(sentence, alphabet=string.ascii_lowercase): 6 | alphaset = set(alphabet) 7 | return alphaset <= set(sentence.lower()) 8 | 9 | print ( ispangram(input('Sentence: ')) ) 10 | -------------------------------------------------------------------------------- /fixtures/bench_power_set.py: -------------------------------------------------------------------------------- 1 | def list_powerset(lst): 2 | # the power set of the empty set has one element, the empty set 3 | result = [[]] 4 | for x in lst: 5 | # for every additional element in our set 6 | # the power set consists of the subsets that don't 7 | # contain this element (just take the previous power set) 8 | # plus the subsets that do contain the element (use list 9 | # comprehension to add [x] onto everything in the 10 | # previous power set) 11 | result.extend([subset + [x] for subset in result]) 12 | return result 13 | 14 | # the above function in one statement 15 | def list_powerset2(lst): 16 | return reduce(lambda result, x: result + [subset + [x] for subset in result], 17 | lst, [[]]) 18 | 19 | def powerset(s): 20 | return frozenset(map(frozenset, list_powerset(list(s)))) 21 | -------------------------------------------------------------------------------- /fixtures/bench_towers_hanoi.py: -------------------------------------------------------------------------------- 1 | def hanoi(ndisks, startPeg=1, endPeg=3): 2 | if ndisks: 3 | hanoi(ndisks-1, startPeg, 6-startPeg-endPeg) 4 | print "Move disk %d from peg %d to peg %d" % (ndisks, startPeg, endPeg) 5 | hanoi(ndisks-1, 6-startPeg-endPeg, endPeg) 6 | 7 | hanoi(ndisks=4) 8 | -------------------------------------------------------------------------------- /fixtures/bitwise.py: -------------------------------------------------------------------------------- 1 | 1 & 2 2 | 1 | 2 3 | 1 ^ 2 4 | 1 << 2 5 | 1 >> 2 6 | 1 & 2 & 3 | 4 7 | (a + 1) | (d + 2) 8 | -------------------------------------------------------------------------------- /fixtures/comment_indented.py: -------------------------------------------------------------------------------- 1 | if True: 2 | # indented comment 3 | pass 4 | -------------------------------------------------------------------------------- /fixtures/comment_indented.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "If", 7 | body: [ 8 | { 9 | 'ast_type': "Pass", 10 | 'col_offset': 9, 11 | 'end_col_offset': 13, 12 | 'end_lineno': 3, 13 | lineno: 3, 14 | 'noops_previous': { 15 | 'ast_type': "PreviousNoops", 16 | 'col_offset': 1, 17 | 'end_col_offset': 26, 18 | 'end_lineno': 2, 19 | lineno: 2, 20 | lines: [ 21 | { 22 | 'ast_type': "NoopLine", 23 | 'col_offset': 1, 24 | lineno: 2, 25 | 'noop_line': " # indented comment\n", 26 | }, 27 | ], 28 | }, 29 | }, 30 | ], 31 | 'col_offset': 1, 32 | 'end_col_offset': 3, 33 | 'end_lineno': 1, 34 | lineno: 1, 35 | orelse: [], 36 | test: { 37 | LiteralValue: "True", 38 | 'ast_type': "BoolLiteral", 39 | 'col_offset': 4, 40 | 'end_col_offset': 8, 41 | 'end_lineno': 1, 42 | lineno: 1, 43 | value: true, 44 | }, 45 | }, 46 | ], 47 | }, 48 | } -------------------------------------------------------------------------------- /fixtures/comments.py: -------------------------------------------------------------------------------- 1 | # comment above 2 | # second comment above 3 | a = 1 # line trailing comment 4 | # file trailing comment 5 | 6 | 7 | 8 | # second file trailing comment 9 | -------------------------------------------------------------------------------- /fixtures/comparisonop.py: -------------------------------------------------------------------------------- 1 | 1 == 2 2 | 1 != 2 3 | not 1 4 | 1 == 2 == 3 5 | 1 < 2 > 3 6 | 1 < 2 != 3 7 | -------------------------------------------------------------------------------- /fixtures/complex.py: -------------------------------------------------------------------------------- 1 | a = 1j * 1j 2 | -------------------------------------------------------------------------------- /fixtures/complex.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assign", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | targets: [ 10 | { 11 | 'ast_type': "Name", 12 | 'col_offset': 1, 13 | ctx: "Store", 14 | 'end_col_offset': 2, 15 | 'end_lineno': 1, 16 | id: "a", 17 | lineno: 1, 18 | }, 19 | ], 20 | value: { 21 | 'ast_type': "BinOp", 22 | 'col_offset': 5, 23 | left: { 24 | 'ast_type': "Num", 25 | 'col_offset': 5, 26 | lineno: 1, 27 | 'n': { 28 | imag: 1, 29 | real: 0, 30 | }, 31 | }, 32 | lineno: 1, 33 | op: { 34 | 'ast_type': "Mult", 35 | }, 36 | right: { 37 | 'ast_type': "Num", 38 | 'col_offset': 10, 39 | lineno: 1, 40 | 'n': { 41 | imag: 1, 42 | real: 0, 43 | }, 44 | }, 45 | }, 46 | }, 47 | ], 48 | }, 49 | } -------------------------------------------------------------------------------- /fixtures/comprehension_dict.py: -------------------------------------------------------------------------------- 1 | {n: n*2 for n in somelist if n>2} 2 | -------------------------------------------------------------------------------- /fixtures/comprehension_list.py: -------------------------------------------------------------------------------- 1 | [i*2 for i in somelist if i>2] 2 | [i*2 for sublist in somelist for i in sublist] 3 | -------------------------------------------------------------------------------- /fixtures/comprehension_set.py: -------------------------------------------------------------------------------- 1 | {n*2 for n in somelist if n>2} 2 | -------------------------------------------------------------------------------- /fixtures/continue_break.py: -------------------------------------------------------------------------------- 1 | for i in [1,2,3]: 2 | if i == 2: 3 | continue 4 | if i == 3: 5 | break 6 | 7 | -------------------------------------------------------------------------------- /fixtures/declarations_annotated.py: -------------------------------------------------------------------------------- 1 | a: int = 3 2 | b: str = "foo" 3 | -------------------------------------------------------------------------------- /fixtures/declarations_annotated.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | annotation: { 7 | 'ast_type': "Name", 8 | 'col_offset': 4, 9 | ctx: "Load", 10 | 'end_col_offset': 7, 11 | 'end_lineno': 1, 12 | id: "int", 13 | lineno: 1, 14 | }, 15 | 'ast_type': "AnnAssign", 16 | 'col_offset': 1, 17 | lineno: 1, 18 | simple: 1, 19 | target: { 20 | 'ast_type': "Name", 21 | 'col_offset': 1, 22 | ctx: "Store", 23 | 'end_col_offset': 2, 24 | 'end_lineno': 1, 25 | id: "a", 26 | lineno: 1, 27 | }, 28 | value: { 29 | 'ast_type': "Num", 30 | 'col_offset': 10, 31 | 'end_col_offset': 11, 32 | 'end_lineno': 1, 33 | lineno: 1, 34 | 'n': 3, 35 | }, 36 | }, 37 | { 38 | annotation: { 39 | 'ast_type': "Name", 40 | 'col_offset': 4, 41 | ctx: "Load", 42 | 'end_col_offset': 7, 43 | 'end_lineno': 2, 44 | id: "str", 45 | lineno: 2, 46 | }, 47 | 'ast_type': "AnnAssign", 48 | 'col_offset': 1, 49 | lineno: 2, 50 | simple: 1, 51 | target: { 52 | 'ast_type': "Name", 53 | 'col_offset': 1, 54 | ctx: "Store", 55 | 'end_col_offset': 2, 56 | 'end_lineno': 2, 57 | id: "b", 58 | lineno: 2, 59 | }, 60 | value: { 61 | 'ast_type': "Str", 62 | 'col_offset': 10, 63 | 'end_col_offset': 15, 64 | 'end_lineno': 2, 65 | lineno: 2, 66 | s: "foo", 67 | }, 68 | }, 69 | ], 70 | }, 71 | } -------------------------------------------------------------------------------- /fixtures/ellipsis.py: -------------------------------------------------------------------------------- 1 | [..., 0] 2 | -------------------------------------------------------------------------------- /fixtures/ellipsis.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | 'ast_type': "List", 11 | 'col_offset': 1, 12 | ctx: "Load", 13 | elts: [ 14 | { 15 | 'ast_type': "Ellipsis", 16 | 'col_offset': 2, 17 | 'end_col_offset': 5, 18 | 'end_lineno': 1, 19 | lineno: 1, 20 | }, 21 | { 22 | 'ast_type': "Num", 23 | 'col_offset': 7, 24 | 'end_col_offset': 8, 25 | 'end_lineno': 1, 26 | lineno: 1, 27 | 'n': 0, 28 | }, 29 | ], 30 | lineno: 1, 31 | }, 32 | }, 33 | ], 34 | }, 35 | } -------------------------------------------------------------------------------- /fixtures/ellipsis.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "python:List", 16 | '@role': [Expression, List, Literal, Primitive], 17 | '@pos': { '@type': "uast:Positions", 18 | start: { '@type': "uast:Position", 19 | offset: 0, 20 | line: 1, 21 | col: 1, 22 | }, 23 | }, 24 | ctx: "Load", 25 | elts: [ 26 | { '@type': "python:Ellipsis", 27 | '@token': "...", 28 | '@role': [Identifier, Incomplete], 29 | '@pos': { '@type': "uast:Positions", 30 | start: { '@type': "uast:Position", 31 | offset: 1, 32 | line: 1, 33 | col: 2, 34 | }, 35 | end: { '@type': "uast:Position", 36 | offset: 4, 37 | line: 1, 38 | col: 5, 39 | }, 40 | }, 41 | }, 42 | { '@type': "python:Num", 43 | '@token': 0, 44 | '@role': [Expression, Literal, Number, Primitive], 45 | '@pos': { '@type': "uast:Positions", 46 | start: { '@type': "uast:Position", 47 | offset: 6, 48 | line: 1, 49 | col: 7, 50 | }, 51 | end: { '@type': "uast:Position", 52 | offset: 7, 53 | line: 1, 54 | col: 8, 55 | }, 56 | }, 57 | }, 58 | ], 59 | }, 60 | }, 61 | ], 62 | } -------------------------------------------------------------------------------- /fixtures/ellipsis.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "List", 16 | '@role': [Expression, List, Literal, Primitive], 17 | '@pos': { '@type': "uast:Positions", 18 | start: { '@type': "uast:Position", 19 | offset: 0, 20 | line: 1, 21 | col: 1, 22 | }, 23 | }, 24 | ctx: "Load", 25 | elts: [ 26 | { '@type': "Ellipsis", 27 | '@token': "...", 28 | '@role': [Identifier, Incomplete], 29 | '@pos': { '@type': "uast:Positions", 30 | start: { '@type': "uast:Position", 31 | offset: 1, 32 | line: 1, 33 | col: 2, 34 | }, 35 | end: { '@type': "uast:Position", 36 | offset: 4, 37 | line: 1, 38 | col: 5, 39 | }, 40 | }, 41 | }, 42 | { '@type': "Num", 43 | '@token': 0, 44 | '@role': [Expression, Literal, Number, Primitive], 45 | '@pos': { '@type': "uast:Positions", 46 | start: { '@type': "uast:Position", 47 | offset: 6, 48 | line: 1, 49 | col: 7, 50 | }, 51 | end: { '@type': "uast:Position", 52 | offset: 7, 53 | line: 1, 54 | col: 8, 55 | }, 56 | }, 57 | }, 58 | ], 59 | }, 60 | }, 61 | ], 62 | } -------------------------------------------------------------------------------- /fixtures/empty_comment.py: -------------------------------------------------------------------------------- 1 | # 2 | -------------------------------------------------------------------------------- /fixtures/empty_comment.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [], 5 | 'noops_remainder': { 6 | 'ast_type': "RemainderNoops", 7 | 'col_offset': 1, 8 | 'end_col_offset': 1, 9 | 'end_lineno': 1, 10 | lineno: 1, 11 | lines: [ 12 | { 13 | 'ast_type': "NoopLine", 14 | 'col_offset': 1, 15 | lineno: 1, 16 | 'noop_line': "#\n", 17 | }, 18 | ], 19 | }, 20 | }, 21 | } -------------------------------------------------------------------------------- /fixtures/empty_comment.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [], 6 | 'noops_remainder': { '@type': "python:RemainderNoops", 7 | '@role': [Noop], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | end: { '@type': "uast:Position", 15 | offset: 0, 16 | line: 1, 17 | col: 1, 18 | }, 19 | }, 20 | lines: [ 21 | { '@type': "uast:Comment", 22 | '@role': [Noop], 23 | '@pos': { '@type': "uast:Positions", 24 | start: { '@type': "uast:Position", 25 | offset: 0, 26 | line: 1, 27 | col: 1, 28 | }, 29 | }, 30 | Block: false, 31 | Prefix: "\n", 32 | Suffix: "", 33 | Tab: "", 34 | Text: "", 35 | }, 36 | ], 37 | }, 38 | } -------------------------------------------------------------------------------- /fixtures/empty_comment.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [], 6 | 'noops_remainder': { '@type': "RemainderNoops", 7 | '@role': [Noop], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | end: { '@type': "uast:Position", 15 | offset: 0, 16 | line: 1, 17 | col: 1, 18 | }, 19 | }, 20 | lines: [ 21 | { '@type': "NoopLine", 22 | '@token': "#\n", 23 | '@role': [Comment, Noop], 24 | '@pos': { '@type': "uast:Positions", 25 | start: { '@type': "uast:Position", 26 | offset: 0, 27 | line: 1, 28 | col: 1, 29 | }, 30 | }, 31 | }, 32 | ], 33 | }, 34 | } -------------------------------------------------------------------------------- /fixtures/except.py: -------------------------------------------------------------------------------- 1 | try: 2 | a = 1 3 | raise Exception("gogogo") 4 | except SomeException as e: 5 | print("someexception catched") 6 | except: 7 | print("ayyyy") 8 | finally: 9 | print("here we are") 10 | -------------------------------------------------------------------------------- /fixtures/exec.py: -------------------------------------------------------------------------------- 1 | exec("print 1") 2 | -------------------------------------------------------------------------------- /fixtures/exec.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | args: [ 11 | { 12 | 'ast_type': "Str", 13 | 'col_offset': 6, 14 | 'end_col_offset': 15, 15 | 'end_lineno': 1, 16 | lineno: 1, 17 | s: "print 1", 18 | }, 19 | ], 20 | 'ast_type': "Call", 21 | 'col_offset': 1, 22 | func: { 23 | 'ast_type': "Name", 24 | 'col_offset': 1, 25 | ctx: "Load", 26 | 'end_col_offset': 5, 27 | 'end_lineno': 1, 28 | id: "exec", 29 | lineno: 1, 30 | }, 31 | keywords: [], 32 | lineno: 1, 33 | }, 34 | }, 35 | ], 36 | }, 37 | } -------------------------------------------------------------------------------- /fixtures/exec.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "Call", 16 | '@role': [Call, Expression, Function], 17 | '@pos': { '@type': "uast:Positions", 18 | start: { '@type': "uast:Position", 19 | offset: 0, 20 | line: 1, 21 | col: 1, 22 | }, 23 | }, 24 | args: [ 25 | { '@type': "Str", 26 | '@token': "print 1", 27 | '@role': [Argument, Call, Expression, Function, Literal, Name, Positional, Primitive, String], 28 | '@pos': { '@type': "uast:Positions", 29 | start: { '@type': "uast:Position", 30 | offset: 5, 31 | line: 1, 32 | col: 6, 33 | }, 34 | end: { '@type': "uast:Position", 35 | offset: 14, 36 | line: 1, 37 | col: 15, 38 | }, 39 | }, 40 | }, 41 | ], 42 | func: { '@type': "Name", 43 | '@token': "exec", 44 | '@role': [Call, Callee, Expression, Identifier], 45 | '@pos': { '@type': "uast:Positions", 46 | start: { '@type': "uast:Position", 47 | offset: 0, 48 | line: 1, 49 | col: 1, 50 | }, 51 | end: { '@type': "uast:Position", 52 | offset: 4, 53 | line: 1, 54 | col: 5, 55 | }, 56 | }, 57 | ctx: "Load", 58 | }, 59 | keywords: [], 60 | }, 61 | }, 62 | ], 63 | } -------------------------------------------------------------------------------- /fixtures/for.py: -------------------------------------------------------------------------------- 1 | for i in [1,2,3]: 2 | a += 1 3 | print(i) 4 | -------------------------------------------------------------------------------- /fixtures/fstring_func.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def somefunc(i): return 1 4 | f"String with {somefunc(i)} and embedded call" 5 | -------------------------------------------------------------------------------- /fixtures/func_with_comments.py: -------------------------------------------------------------------------------- 1 | # comment above 2 | def foo(): # comment inline 3 | pass 4 | # comment after 5 | -------------------------------------------------------------------------------- /fixtures/func_with_comments.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [], 8 | 'ast_type': "arguments", 9 | }, 10 | 'ast_type': "FunctionDef", 11 | body: [ 12 | { 13 | 'ast_type': "Pass", 14 | 'col_offset': 5, 15 | 'end_col_offset': 9, 16 | 'end_lineno': 3, 17 | lineno: 3, 18 | 'noops_previous': { 19 | 'ast_type': "PreviousNoops", 20 | 'col_offset': 1, 21 | 'end_col_offset': 15, 22 | 'end_lineno': 1, 23 | lineno: 1, 24 | lines: [ 25 | { 26 | 'ast_type': "NoopLine", 27 | 'col_offset': 1, 28 | lineno: 1, 29 | 'noop_line': "# comment above\n", 30 | }, 31 | ], 32 | }, 33 | }, 34 | ], 35 | 'col_offset': 5, 36 | 'decorator_list': [], 37 | 'end_col_offset': 8, 38 | 'end_lineno': 2, 39 | lineno: 2, 40 | name: "foo", 41 | 'noops_sameline': { 42 | 'ast_type': "SameLineNoops", 43 | 'col_offset': 11, 44 | 'end_col_offset': 27, 45 | 'end_lineno': 2, 46 | lineno: 2, 47 | 'noop_lines': [ 48 | { 49 | 'ast_type': "NoopSameLine", 50 | s: "# comment inline", 51 | }, 52 | ], 53 | }, 54 | returns: ~, 55 | }, 56 | ], 57 | 'noops_remainder': { 58 | 'ast_type': "RemainderNoops", 59 | 'col_offset': 1, 60 | 'end_col_offset': 1, 61 | 'end_lineno': 4, 62 | lineno: 4, 63 | lines: [ 64 | { 65 | 'ast_type': "NoopLine", 66 | 'col_offset': 1, 67 | lineno: 4, 68 | 'noop_line': "# comment after\n", 69 | }, 70 | ], 71 | }, 72 | }, 73 | } -------------------------------------------------------------------------------- /fixtures/funcdef_defaults.py: -------------------------------------------------------------------------------- 1 | def testfnc1(a, b=1, c=2): pass 2 | -------------------------------------------------------------------------------- /fixtures/funcdef_kwonlyargs.py: -------------------------------------------------------------------------------- 1 | def testfnc1(a, b, *, c=1): pass 2 | -------------------------------------------------------------------------------- /fixtures/funcdef_kwonlyargs.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [ 8 | { 9 | '@token': "a", 10 | annotation: ~, 11 | 'ast_type': "arg", 12 | 'col_offset': 14, 13 | 'end_col_offset': 15, 14 | 'end_lineno': 1, 15 | lineno: 1, 16 | }, 17 | { 18 | '@token': "b", 19 | annotation: ~, 20 | 'ast_type': "arg", 21 | 'col_offset': 17, 22 | 'end_col_offset': 18, 23 | 'end_lineno': 1, 24 | lineno: 1, 25 | }, 26 | { 27 | '@token': "c", 28 | annotation: ~, 29 | 'ast_type': "kwonly_arg", 30 | 'col_offset': 23, 31 | default: { 32 | 'ast_type': "Num", 33 | 'col_offset': 25, 34 | 'end_col_offset': 26, 35 | 'end_lineno': 1, 36 | lineno: 1, 37 | 'n': 1, 38 | }, 39 | 'end_col_offset': 24, 40 | 'end_lineno': 1, 41 | lineno: 1, 42 | }, 43 | ], 44 | 'ast_type': "arguments", 45 | }, 46 | 'ast_type': "FunctionDef", 47 | body: [ 48 | { 49 | 'ast_type': "Pass", 50 | 'col_offset': 29, 51 | 'end_col_offset': 33, 52 | 'end_lineno': 1, 53 | lineno: 1, 54 | }, 55 | ], 56 | 'col_offset': 5, 57 | 'decorator_list': [], 58 | 'end_col_offset': 13, 59 | 'end_lineno': 1, 60 | lineno: 1, 61 | name: "testfnc1", 62 | returns: ~, 63 | }, 64 | ], 65 | }, 66 | } -------------------------------------------------------------------------------- /fixtures/functioncalls.py: -------------------------------------------------------------------------------- 1 | normalCall("something1", 42, somesymbbol) 2 | a.qualifiedCall("something", 42, somesymbol) 3 | keyCall(a, b=1, c=2) 4 | expandListCall(a, *expandedList) 5 | expandMapCall(a, **expandedMap) 6 | -------------------------------------------------------------------------------- /fixtures/hello.py: -------------------------------------------------------------------------------- 1 | print("hello world") 2 | -------------------------------------------------------------------------------- /fixtures/hello.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | args: [ 11 | { 12 | 'ast_type': "Str", 13 | 'col_offset': 7, 14 | 'end_col_offset': 20, 15 | 'end_lineno': 1, 16 | lineno: 1, 17 | s: "hello world", 18 | }, 19 | ], 20 | 'ast_type': "Call", 21 | 'col_offset': 1, 22 | func: { 23 | 'ast_type': "Name", 24 | 'col_offset': 1, 25 | ctx: "Load", 26 | 'end_col_offset': 6, 27 | 'end_lineno': 1, 28 | id: "print", 29 | lineno: 1, 30 | }, 31 | keywords: [], 32 | lineno: 1, 33 | }, 34 | }, 35 | ], 36 | }, 37 | } -------------------------------------------------------------------------------- /fixtures/hello.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "Call", 16 | '@role': [Call, Expression, Function], 17 | '@pos': { '@type': "uast:Positions", 18 | start: { '@type': "uast:Position", 19 | offset: 0, 20 | line: 1, 21 | col: 1, 22 | }, 23 | }, 24 | args: [ 25 | { '@type': "Str", 26 | '@token': "hello world", 27 | '@role': [Argument, Call, Expression, Function, Literal, Name, Positional, Primitive, String], 28 | '@pos': { '@type': "uast:Positions", 29 | start: { '@type': "uast:Position", 30 | offset: 6, 31 | line: 1, 32 | col: 7, 33 | }, 34 | end: { '@type': "uast:Position", 35 | offset: 19, 36 | line: 1, 37 | col: 20, 38 | }, 39 | }, 40 | }, 41 | ], 42 | func: { '@type': "Name", 43 | '@token': "print", 44 | '@role': [Call, Callee, Expression, Identifier], 45 | '@pos': { '@type': "uast:Positions", 46 | start: { '@type': "uast:Position", 47 | offset: 0, 48 | line: 1, 49 | col: 1, 50 | }, 51 | end: { '@type': "uast:Position", 52 | offset: 5, 53 | line: 1, 54 | col: 6, 55 | }, 56 | }, 57 | ctx: "Load", 58 | }, 59 | keywords: [], 60 | }, 61 | }, 62 | ], 63 | } -------------------------------------------------------------------------------- /fixtures/if.py: -------------------------------------------------------------------------------- 1 | if True: 2 | print(True) 3 | 4 | if functionCall(): 5 | print(True) 6 | 7 | if a > b: 8 | a = 1.1 9 | x = 1.2 10 | elif b == c: 11 | c = 2.1 12 | j = 2.2 13 | else: 14 | b = 3.1 15 | p = 3.2 16 | 17 | if a > b > c > d: 18 | pass 19 | -------------------------------------------------------------------------------- /fixtures/ifexpression.py: -------------------------------------------------------------------------------- 1 | a = 1 if 3 > 4 else 2 2 | -------------------------------------------------------------------------------- /fixtures/ifexpression.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assign", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | targets: [ 10 | { 11 | 'ast_type': "Name", 12 | 'col_offset': 1, 13 | ctx: "Store", 14 | 'end_col_offset': 2, 15 | 'end_lineno': 1, 16 | id: "a", 17 | lineno: 1, 18 | }, 19 | ], 20 | value: { 21 | 'ast_type': "IfExp", 22 | body: { 23 | 'ast_type': "Num", 24 | 'col_offset': 5, 25 | 'end_col_offset': 6, 26 | 'end_lineno': 1, 27 | lineno: 1, 28 | 'n': 1, 29 | }, 30 | 'col_offset': 5, 31 | lineno: 1, 32 | orelse: { 33 | 'ast_type': "Num", 34 | 'col_offset': 21, 35 | 'end_col_offset': 22, 36 | 'end_lineno': 1, 37 | lineno: 1, 38 | 'n': 2, 39 | }, 40 | test: { 41 | 'ast_type': "Compare", 42 | 'col_offset': 10, 43 | comparators: [ 44 | { 45 | 'ast_type': "Num", 46 | 'col_offset': 14, 47 | 'end_col_offset': 15, 48 | 'end_lineno': 1, 49 | lineno: 1, 50 | 'n': 4, 51 | }, 52 | ], 53 | left: { 54 | 'ast_type': "Num", 55 | 'col_offset': 10, 56 | 'end_col_offset': 11, 57 | 'end_lineno': 1, 58 | lineno: 1, 59 | 'n': 3, 60 | }, 61 | lineno: 1, 62 | ops: [ 63 | { 64 | 'ast_type': "Gt", 65 | }, 66 | ], 67 | }, 68 | }, 69 | }, 70 | ], 71 | }, 72 | } -------------------------------------------------------------------------------- /fixtures/in.py: -------------------------------------------------------------------------------- 1 | a in b 2 | -------------------------------------------------------------------------------- /fixtures/in.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | 'ast_type': "Compare", 11 | 'col_offset': 1, 12 | comparators: [ 13 | { 14 | 'ast_type': "Name", 15 | 'col_offset': 6, 16 | ctx: "Load", 17 | 'end_col_offset': 7, 18 | 'end_lineno': 1, 19 | id: "b", 20 | lineno: 1, 21 | }, 22 | ], 23 | left: { 24 | 'ast_type': "Name", 25 | 'col_offset': 1, 26 | ctx: "Load", 27 | 'end_col_offset': 2, 28 | 'end_lineno': 1, 29 | id: "a", 30 | lineno: 1, 31 | }, 32 | lineno: 1, 33 | ops: [ 34 | { 35 | 'ast_type': "In", 36 | }, 37 | ], 38 | }, 39 | }, 40 | ], 41 | }, 42 | } -------------------------------------------------------------------------------- /fixtures/issue102.py: -------------------------------------------------------------------------------- 1 | ''' 2 | select message.*, user.* from message, user 3 | where message.author_id = user.user_id and ( 4 | user.user_id = ? or 5 | user.user_id in (select whom_id from follower 6 | where who_id = ?)) 7 | order by message.pub_date desc limit ?''' 8 | -------------------------------------------------------------------------------- /fixtures/issue102.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 7, 9 | value: { 10 | 'ast_type': "Str", 11 | 'col_offset': 1, 12 | 'end_col_offset': 50, 13 | 'end_lineno': 7, 14 | lineno: 1, 15 | s: "\n select message.*, user.* from message, user\n where message.author_id = user.user_id and (\n user.user_id = ? or\n user.user_id in (select whom_id from follower\n where who_id = ?))\n order by message.pub_date desc limit ?", 16 | }, 17 | }, 18 | ], 19 | }, 20 | } -------------------------------------------------------------------------------- /fixtures/issue102.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 254, 11 | line: 7, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "python:BoxedStr", 16 | '@role': [Unannotated], 17 | 'boxed_value': { '@type': "uast:String", 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 303, 26 | line: 7, 27 | col: 50, 28 | }, 29 | }, 30 | Format: "", 31 | Value: "\n select message.*, user.* from message, user\n where message.author_id = user.user_id and (\n user.user_id = ? or\n user.user_id in (select whom_id from follower\n where who_id = ?))\n order by message.pub_date desc limit ?", 32 | }, 33 | }, 34 | }, 35 | ], 36 | } -------------------------------------------------------------------------------- /fixtures/issue102.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 254, 11 | line: 7, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "Str", 16 | '@token': "\n select message.*, user.* from message, user\n where message.author_id = user.user_id and (\n user.user_id = ? or\n user.user_id in (select whom_id from follower\n where who_id = ?))\n order by message.pub_date desc limit ?", 17 | '@role': [Expression, Literal, Primitive, String], 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 303, 26 | line: 7, 27 | col: 50, 28 | }, 29 | }, 30 | }, 31 | }, 32 | ], 33 | } -------------------------------------------------------------------------------- /fixtures/issue119.py: -------------------------------------------------------------------------------- 1 | def foo(): 2 | a = {'1': 1} 3 | b = {'2': 2} 4 | return {**a, **b} 5 | -------------------------------------------------------------------------------- /fixtures/issue130.py: -------------------------------------------------------------------------------- 1 | shutil.which(os.path.basename(target)) 2 | shutil.copyfile(os.path.join(cwd, "bin", "bigartm"), target) 3 | log.info("Installed %s", os.path.abspath(target)) 4 | -------------------------------------------------------------------------------- /fixtures/issue167.py: -------------------------------------------------------------------------------- 1 | # regular comment 2 | a = Animal() # line comment 3 | -------------------------------------------------------------------------------- /fixtures/issue167.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assign", 7 | 'col_offset': 1, 8 | lineno: 2, 9 | targets: [ 10 | { 11 | 'ast_type': "Name", 12 | 'col_offset': 1, 13 | ctx: "Store", 14 | 'end_col_offset': 2, 15 | 'end_lineno': 2, 16 | id: "a", 17 | lineno: 2, 18 | 'noops_previous': { 19 | 'ast_type': "PreviousNoops", 20 | 'col_offset': 1, 21 | 'end_col_offset': 17, 22 | 'end_lineno': 1, 23 | lineno: 1, 24 | lines: [ 25 | { 26 | 'ast_type': "NoopLine", 27 | 'col_offset': 1, 28 | lineno: 1, 29 | 'noop_line': "# regular comment\n", 30 | }, 31 | ], 32 | }, 33 | 'noops_sameline': { 34 | 'ast_type': "SameLineNoops", 35 | 'col_offset': 13, 36 | 'end_col_offset': 27, 37 | 'end_lineno': 2, 38 | lineno: 2, 39 | 'noop_lines': [ 40 | { 41 | 'ast_type': "NoopSameLine", 42 | s: "# line comment", 43 | }, 44 | ], 45 | }, 46 | }, 47 | ], 48 | value: { 49 | args: [], 50 | 'ast_type': "Call", 51 | 'col_offset': 5, 52 | func: { 53 | 'ast_type': "Name", 54 | 'col_offset': 5, 55 | ctx: "Load", 56 | 'end_col_offset': 11, 57 | 'end_lineno': 2, 58 | id: "Animal", 59 | lineno: 2, 60 | }, 61 | keywords: [], 62 | lineno: 2, 63 | }, 64 | }, 65 | ], 66 | }, 67 | } -------------------------------------------------------------------------------- /fixtures/issue177.py: -------------------------------------------------------------------------------- 1 | def testfnc1(**options): 2 | print "force python2" 3 | -------------------------------------------------------------------------------- /fixtures/issue177.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY2AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [ 8 | { 9 | '@token': "options", 10 | annotation: ~, 11 | 'ast_type': "kwarg", 12 | 'col_offset': 16, 13 | 'end_col_offset': 23, 14 | 'end_lineno': 1, 15 | lineno: 1, 16 | }, 17 | ], 18 | 'ast_type': "arguments", 19 | }, 20 | 'ast_type': "FunctionDef", 21 | body: [ 22 | { 23 | 'ast_type': "Print", 24 | 'col_offset': 5, 25 | dest: ~, 26 | 'end_col_offset': 10, 27 | 'end_lineno': 2, 28 | lineno: 2, 29 | nl: true, 30 | values: [ 31 | { 32 | 'ast_type': "Str", 33 | 'col_offset': 11, 34 | 'end_col_offset': 26, 35 | 'end_lineno': 2, 36 | lineno: 2, 37 | s: "force python2", 38 | }, 39 | ], 40 | }, 41 | ], 42 | 'col_offset': 5, 43 | 'decorator_list': [], 44 | 'end_col_offset': 13, 45 | 'end_lineno': 1, 46 | lineno: 1, 47 | name: "testfnc1", 48 | }, 49 | ], 50 | }, 51 | } -------------------------------------------------------------------------------- /fixtures/issue30.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.stdout.write("Hello world!\n") 3 | -------------------------------------------------------------------------------- /fixtures/issue51.py: -------------------------------------------------------------------------------- 1 | plt.figure() 2 | -------------------------------------------------------------------------------- /fixtures/issue51.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | args: [], 11 | 'ast_type': "Call", 12 | 'col_offset': 1, 13 | func: { 14 | 'ast_type': "QualifiedIdentifier", 15 | 'col_offset': 2, 16 | ctx: "Load", 17 | 'end_col_offset': 5, 18 | 'end_lineno': 1, 19 | identifiers: [ 20 | { 21 | 'ast_type': "Name", 22 | 'col_offset': 1, 23 | ctx: "Load", 24 | 'end_col_offset': 4, 25 | 'end_lineno': 1, 26 | id: "plt", 27 | lineno: 1, 28 | }, 29 | { 30 | 'ast_type': "Attribute", 31 | attr: "figure", 32 | 'col_offset': 1, 33 | ctx: "Load", 34 | lineno: 1, 35 | }, 36 | ], 37 | lineno: 1, 38 | }, 39 | keywords: [], 40 | lineno: 1, 41 | }, 42 | }, 43 | ], 44 | }, 45 | } -------------------------------------------------------------------------------- /fixtures/issue58.py: -------------------------------------------------------------------------------- 1 | a, b = 0, None 2 | -------------------------------------------------------------------------------- /fixtures/issue58.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assign", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | targets: [ 10 | { 11 | 'ast_type': "Tuple", 12 | 'col_offset': 1, 13 | ctx: "Store", 14 | elts: [ 15 | { 16 | 'ast_type': "Name", 17 | 'col_offset': 1, 18 | ctx: "Store", 19 | 'end_col_offset': 2, 20 | 'end_lineno': 1, 21 | id: "a", 22 | lineno: 1, 23 | }, 24 | { 25 | 'ast_type': "Name", 26 | 'col_offset': 4, 27 | ctx: "Store", 28 | 'end_col_offset': 5, 29 | 'end_lineno': 1, 30 | id: "b", 31 | lineno: 1, 32 | }, 33 | ], 34 | lineno: 1, 35 | }, 36 | ], 37 | value: { 38 | 'ast_type': "Tuple", 39 | 'col_offset': 8, 40 | ctx: "Load", 41 | elts: [ 42 | { 43 | 'ast_type': "Num", 44 | 'col_offset': 8, 45 | 'end_col_offset': 9, 46 | 'end_lineno': 1, 47 | lineno: 1, 48 | 'n': 0, 49 | }, 50 | { 51 | LiteralValue: "None", 52 | 'ast_type': "NoneLiteral", 53 | 'col_offset': 11, 54 | 'end_col_offset': 15, 55 | 'end_lineno': 1, 56 | lineno: 1, 57 | value: ~, 58 | }, 59 | ], 60 | lineno: 1, 61 | }, 62 | }, 63 | ], 64 | }, 65 | } -------------------------------------------------------------------------------- /fixtures/issue62.py: -------------------------------------------------------------------------------- 1 | from os import path 2 | import sys 3 | 4 | import numpy as np 5 | -------------------------------------------------------------------------------- /fixtures/issue62.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ImportFrom", 7 | 'col_offset': 1, 8 | 'end_col_offset': 8, 9 | 'end_lineno': 1, 10 | level: 0, 11 | lineno: 1, 12 | module: "os", 13 | names: [ 14 | { 15 | asname: ~, 16 | 'ast_type': "alias", 17 | name: "path", 18 | }, 19 | ], 20 | }, 21 | { 22 | 'ast_type': "Import", 23 | 'col_offset': 1, 24 | lineno: 2, 25 | names: [ 26 | { 27 | asname: ~, 28 | 'ast_type': "alias", 29 | name: "sys", 30 | }, 31 | ], 32 | }, 33 | { 34 | 'ast_type': "Import", 35 | 'col_offset': 1, 36 | lineno: 4, 37 | names: [ 38 | { 39 | asname: "np", 40 | 'ast_type': "alias", 41 | name: "numpy", 42 | }, 43 | ], 44 | 'noops_previous': { 45 | 'ast_type': "PreviousNoops", 46 | 'col_offset': 1, 47 | 'end_col_offset': 1, 48 | 'end_lineno': 3, 49 | lineno: 3, 50 | lines: [], 51 | }, 52 | }, 53 | ], 54 | }, 55 | } -------------------------------------------------------------------------------- /fixtures/issue62.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "uast:RuntimeImport", 7 | '@pos': { '@type': "uast:Positions", 8 | start: { '@type': "uast:Position", 9 | offset: 0, 10 | line: 1, 11 | col: 1, 12 | }, 13 | end: { '@type': "uast:Position", 14 | offset: 7, 15 | line: 1, 16 | col: 8, 17 | }, 18 | }, 19 | All: false, 20 | Names: [ 21 | { '@type': "uast:Identifier", 22 | '@pos': { '@type': "uast:Positions", 23 | }, 24 | Name: "path", 25 | }, 26 | ], 27 | Path: { '@type': "uast:Identifier", 28 | '@pos': { '@type': "uast:Positions", 29 | }, 30 | Name: "os", 31 | }, 32 | Target: ~, 33 | }, 34 | { '@type': "uast:RuntimeImport", 35 | '@pos': { '@type': "uast:Positions", 36 | start: { '@type': "uast:Position", 37 | offset: 20, 38 | line: 2, 39 | col: 1, 40 | }, 41 | }, 42 | All: false, 43 | Names: ~, 44 | Path: { '@type': "uast:Identifier", 45 | '@pos': { '@type': "uast:Positions", 46 | }, 47 | Name: "sys", 48 | }, 49 | Target: ~, 50 | }, 51 | { '@type': "uast:RuntimeImport", 52 | '@pos': { '@type': "uast:Positions", 53 | start: { '@type': "uast:Position", 54 | offset: 32, 55 | line: 4, 56 | col: 1, 57 | }, 58 | }, 59 | All: false, 60 | Names: ~, 61 | Path: { '@type': "uast:Alias", 62 | '@pos': { '@type': "uast:Positions", 63 | }, 64 | Name: { '@type': "uast:Identifier", 65 | '@pos': { '@type': "uast:Positions", 66 | }, 67 | Name: "np", 68 | }, 69 | Node: { '@type': "uast:Identifier", 70 | '@pos': { '@type': "uast:Positions", 71 | }, 72 | Name: "numpy", 73 | }, 74 | }, 75 | Target: ~, 76 | }, 77 | ], 78 | } -------------------------------------------------------------------------------- /fixtures/issue62_b.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | from ast2vec.bblfsh_roles import SIMPLE_IDENTIFIER 4 | from ast2vec.repo2.base import Repo2Base 5 | 6 | 7 | class Repo2IdModel: 8 | NAME = "Repo2IdModel" 9 | 10 | 11 | class Repo2IdCounter(Repo2Base): 12 | """ 13 | Print all SIMPLE_IDENTIFIERs (and counters) from repository 14 | """ 15 | MODEL_CLASS = Repo2IdModel 16 | 17 | def collect_id_cnt(self, root, id_cnt): 18 | for ch in root.children: 19 | if SIMPLE_IDENTIFIER in ch.roles: 20 | id_cnt[ch.token] += 1 21 | self.collect_id_cnt(ch, id_cnt) 22 | 23 | def convert_uasts(self, file_uast_generator): 24 | for file_uast in file_uast_generator: 25 | print("-" * 20 + " " + str(file_uast.filepath)) 26 | id_cnt = Counter() 27 | self.collect_id_cnt(file_uast.response.uast, id_cnt) 28 | print(id_cnt) 29 | 30 | 31 | if __name__ == "__main__": 32 | repo = "test/imports/" 33 | c2v = Repo2IdCounter(linguist="path/to/enry", bblfsh_endpoint="0.0.0.0:9432") 34 | c2v.convert_repository(repo) 35 | -------------------------------------------------------------------------------- /fixtures/issue76.py: -------------------------------------------------------------------------------- 1 | with open(os.path.join(args.output, "row_vocab.txt"), "w") as out: 2 | out.write('\n'.join(chosen_words)) 3 | -------------------------------------------------------------------------------- /fixtures/issue94.py: -------------------------------------------------------------------------------- 1 | import lib1 2 | import lib2.lib21 3 | import lib3 as lib3_alias 4 | from lib4 import lib41 5 | from lib5.lib51 import lib511 6 | from lib6 import lib61 as lib611 7 | 8 | var1 = None 9 | var2 = None 10 | 11 | class class1: 12 | var11 = None 13 | 14 | def __init__(self): 15 | self.var101 = None 16 | 17 | def func11(self): 18 | class1.var111 = None 19 | self.var112 = None 20 | var113 = None 21 | 22 | def func12(): 23 | def func121(): 24 | pass 25 | 26 | class class2: 27 | var21 = None 28 | def func21(self): 29 | None 30 | def func22(self, arg1): 31 | None 32 | def func23(): 33 | None 34 | 35 | class class3: 36 | pass 37 | -------------------------------------------------------------------------------- /fixtures/issue96.py: -------------------------------------------------------------------------------- 1 | import lib1 2 | import lib2.lib21 3 | import lib3 as lib3_alias 4 | from lib4 import lib41 5 | from lib5.lib51 import lib511 6 | from lib6 import lib61 as lib611 7 | 8 | var1 = None 9 | var2 = None 10 | 11 | class class1: 12 | var11 = None 13 | 14 | def __init__(self): 15 | self.var101 = None 16 | 17 | def func11(self): 18 | class1.var111 = None 19 | self.var112 = None 20 | var113 = None 21 | 22 | def func12(): 23 | def func121(): 24 | pass 25 | 26 | class class2: 27 | var21 = None 28 | def func21(self): 29 | None 30 | def func22(self, arg1): 31 | None 32 | def func23(): 33 | None 34 | 35 | class class3: 36 | pass 37 | -------------------------------------------------------------------------------- /fixtures/issue97_assign.py: -------------------------------------------------------------------------------- 1 | a = b = c 2 | -------------------------------------------------------------------------------- /fixtures/issue97_assign.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assign", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | targets: [ 10 | { 11 | 'ast_type': "Name", 12 | 'col_offset': 1, 13 | ctx: "Store", 14 | 'end_col_offset': 2, 15 | 'end_lineno': 1, 16 | id: "a", 17 | lineno: 1, 18 | }, 19 | { 20 | 'ast_type': "Name", 21 | 'col_offset': 5, 22 | ctx: "Store", 23 | 'end_col_offset': 6, 24 | 'end_lineno': 1, 25 | id: "b", 26 | lineno: 1, 27 | }, 28 | ], 29 | value: { 30 | 'ast_type': "Name", 31 | 'col_offset': 9, 32 | ctx: "Load", 33 | 'end_col_offset': 10, 34 | 'end_lineno': 1, 35 | id: "c", 36 | lineno: 1, 37 | }, 38 | }, 39 | ], 40 | }, 41 | } -------------------------------------------------------------------------------- /fixtures/issue97_assign.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Assign", 7 | '@role': [Assignment, Binary, Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | targets: [ 16 | { '@type': "Name", 17 | '@token': "a", 18 | '@role': [Expression, Identifier, Left], 19 | '@pos': { '@type': "uast:Positions", 20 | start: { '@type': "uast:Position", 21 | offset: 0, 22 | line: 1, 23 | col: 1, 24 | }, 25 | end: { '@type': "uast:Position", 26 | offset: 1, 27 | line: 1, 28 | col: 2, 29 | }, 30 | }, 31 | ctx: "Store", 32 | }, 33 | { '@type': "Name", 34 | '@token': "b", 35 | '@role': [Expression, Identifier, Left], 36 | '@pos': { '@type': "uast:Positions", 37 | start: { '@type': "uast:Position", 38 | offset: 4, 39 | line: 1, 40 | col: 5, 41 | }, 42 | end: { '@type': "uast:Position", 43 | offset: 5, 44 | line: 1, 45 | col: 6, 46 | }, 47 | }, 48 | ctx: "Store", 49 | }, 50 | ], 51 | value: { '@type': "Name", 52 | '@token': "c", 53 | '@role': [Expression, Identifier, Right], 54 | '@pos': { '@type': "uast:Positions", 55 | start: { '@type': "uast:Position", 56 | offset: 8, 57 | line: 1, 58 | col: 9, 59 | }, 60 | end: { '@type': "uast:Position", 61 | offset: 9, 62 | line: 1, 63 | col: 10, 64 | }, 65 | }, 66 | ctx: "Load", 67 | }, 68 | }, 69 | ], 70 | } -------------------------------------------------------------------------------- /fixtures/issue97_equal.py: -------------------------------------------------------------------------------- 1 | var1 == var2 == var3 2 | -------------------------------------------------------------------------------- /fixtures/issue97_equal.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | 'ast_type': "Compare", 11 | 'col_offset': 1, 12 | comparators: [ 13 | { 14 | 'ast_type': "Name", 15 | 'col_offset': 9, 16 | ctx: "Load", 17 | 'end_col_offset': 13, 18 | 'end_lineno': 1, 19 | id: "var2", 20 | lineno: 1, 21 | }, 22 | { 23 | 'ast_type': "Name", 24 | 'col_offset': 17, 25 | ctx: "Load", 26 | 'end_col_offset': 21, 27 | 'end_lineno': 1, 28 | id: "var3", 29 | lineno: 1, 30 | }, 31 | ], 32 | left: { 33 | 'ast_type': "Name", 34 | 'col_offset': 1, 35 | ctx: "Load", 36 | 'end_col_offset': 5, 37 | 'end_lineno': 1, 38 | id: "var1", 39 | lineno: 1, 40 | }, 41 | lineno: 1, 42 | ops: [ 43 | { 44 | 'ast_type': "Eq", 45 | }, 46 | { 47 | 'ast_type': "Eq", 48 | }, 49 | ], 50 | }, 51 | }, 52 | ], 53 | }, 54 | } -------------------------------------------------------------------------------- /fixtures/issue97_lessThan.py: -------------------------------------------------------------------------------- 1 | var4 < var5 < var6 2 | -------------------------------------------------------------------------------- /fixtures/issue97_lessThan.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | 'ast_type': "Compare", 11 | 'col_offset': 1, 12 | comparators: [ 13 | { 14 | 'ast_type': "Name", 15 | 'col_offset': 8, 16 | ctx: "Load", 17 | 'end_col_offset': 12, 18 | 'end_lineno': 1, 19 | id: "var5", 20 | lineno: 1, 21 | }, 22 | { 23 | 'ast_type': "Name", 24 | 'col_offset': 15, 25 | ctx: "Load", 26 | 'end_col_offset': 19, 27 | 'end_lineno': 1, 28 | id: "var6", 29 | lineno: 1, 30 | }, 31 | ], 32 | left: { 33 | 'ast_type': "Name", 34 | 'col_offset': 1, 35 | ctx: "Load", 36 | 'end_col_offset': 5, 37 | 'end_lineno': 1, 38 | id: "var4", 39 | lineno: 1, 40 | }, 41 | lineno: 1, 42 | ops: [ 43 | { 44 | 'ast_type': "Lt", 45 | }, 46 | { 47 | 'ast_type': "Lt", 48 | }, 49 | ], 50 | }, 51 | }, 52 | ], 53 | }, 54 | } -------------------------------------------------------------------------------- /fixtures/issue_182.py: -------------------------------------------------------------------------------- 1 | _POS_INF = 1e10000 2 | -------------------------------------------------------------------------------- /fixtures/issue_182.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assign", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | targets: [ 10 | { 11 | 'ast_type': "Name", 12 | 'col_offset': 1, 13 | ctx: "Store", 14 | 'end_col_offset': 9, 15 | 'end_lineno': 1, 16 | id: "_POS_INF", 17 | lineno: 1, 18 | }, 19 | ], 20 | value: { 21 | 'ast_type': "Num", 22 | 'col_offset': 12, 23 | lineno: 1, 24 | 'n': "inf", 25 | }, 26 | }, 27 | ], 28 | }, 29 | } -------------------------------------------------------------------------------- /fixtures/issue_182.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:Assign", 7 | '@role': [Assignment, Binary, Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | targets: [ 16 | { '@type': "python:BoxedName", 17 | '@role': [Left], 18 | 'boxed_value': { '@type': "uast:Identifier", 19 | '@pos': { '@type': "uast:Positions", 20 | start: { '@type': "uast:Position", 21 | offset: 0, 22 | line: 1, 23 | col: 1, 24 | }, 25 | end: { '@type': "uast:Position", 26 | offset: 8, 27 | line: 1, 28 | col: 9, 29 | }, 30 | }, 31 | Name: "_POS_INF", 32 | }, 33 | ctx: "Store", 34 | }, 35 | ], 36 | value: { '@type': "python:Num", 37 | '@token': "inf", 38 | '@role': [Expression, Literal, Number, Primitive, Right], 39 | '@pos': { '@type': "uast:Positions", 40 | start: { '@type': "uast:Position", 41 | offset: 11, 42 | line: 1, 43 | col: 12, 44 | }, 45 | }, 46 | }, 47 | }, 48 | ], 49 | } -------------------------------------------------------------------------------- /fixtures/issue_182.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Assign", 7 | '@role': [Assignment, Binary, Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | targets: [ 16 | { '@type': "Name", 17 | '@token': "_POS_INF", 18 | '@role': [Expression, Identifier, Left], 19 | '@pos': { '@type': "uast:Positions", 20 | start: { '@type': "uast:Position", 21 | offset: 0, 22 | line: 1, 23 | col: 1, 24 | }, 25 | end: { '@type': "uast:Position", 26 | offset: 8, 27 | line: 1, 28 | col: 9, 29 | }, 30 | }, 31 | ctx: "Store", 32 | }, 33 | ], 34 | value: { '@type': "Num", 35 | '@token': "inf", 36 | '@role': [Expression, Literal, Number, Primitive, Right], 37 | '@pos': { '@type': "uast:Positions", 38 | start: { '@type': "uast:Position", 39 | offset: 11, 40 | line: 1, 41 | col: 12, 42 | }, 43 | }, 44 | }, 45 | }, 46 | ], 47 | } -------------------------------------------------------------------------------- /fixtures/lambda.py: -------------------------------------------------------------------------------- 1 | lambda x: x+1 2 | -------------------------------------------------------------------------------- /fixtures/lambda.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | args: { 11 | args: [ 12 | { 13 | '@token': "x", 14 | annotation: ~, 15 | 'ast_type': "arg", 16 | 'col_offset': 8, 17 | 'end_col_offset': 9, 18 | 'end_lineno': 1, 19 | lineno: 1, 20 | }, 21 | ], 22 | 'ast_type': "arguments", 23 | }, 24 | 'ast_type': "Lambda", 25 | body: { 26 | 'ast_type': "BinOp", 27 | 'col_offset': 11, 28 | left: { 29 | 'ast_type': "Name", 30 | 'col_offset': 11, 31 | ctx: "Load", 32 | 'end_col_offset': 12, 33 | 'end_lineno': 1, 34 | id: "x", 35 | lineno: 1, 36 | }, 37 | lineno: 1, 38 | op: { 39 | 'ast_type': "Add", 40 | }, 41 | right: { 42 | 'ast_type': "Num", 43 | 'col_offset': 13, 44 | 'end_col_offset': 14, 45 | 'end_lineno': 1, 46 | lineno: 1, 47 | 'n': 1, 48 | }, 49 | }, 50 | 'col_offset': 1, 51 | 'end_col_offset': 7, 52 | 'end_lineno': 1, 53 | lineno: 1, 54 | }, 55 | }, 56 | ], 57 | }, 58 | } -------------------------------------------------------------------------------- /fixtures/line_comment.py: -------------------------------------------------------------------------------- 1 | # thse are 2 | # previous comments 3 | pass # sameline comment 4 | 5 | # remainder comment and newline 6 | # last remainder comment line 7 | -------------------------------------------------------------------------------- /fixtures/line_comment.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Pass", 7 | 'col_offset': 1, 8 | 'end_col_offset': 5, 9 | 'end_lineno': 3, 10 | lineno: 3, 11 | 'noops_previous': { 12 | 'ast_type': "PreviousNoops", 13 | 'col_offset': 1, 14 | 'end_col_offset': 19, 15 | 'end_lineno': 2, 16 | lineno: 1, 17 | lines: [ 18 | { 19 | 'ast_type': "NoopLine", 20 | 'col_offset': 1, 21 | lineno: 1, 22 | 'noop_line': "# thse are\n", 23 | }, 24 | { 25 | 'ast_type': "NoopLine", 26 | 'col_offset': 1, 27 | lineno: 2, 28 | 'noop_line': "# previous comments\n", 29 | }, 30 | ], 31 | }, 32 | 'noops_sameline': { 33 | 'ast_type': "SameLineNoops", 34 | 'col_offset': 5, 35 | 'end_col_offset': 23, 36 | 'end_lineno': 3, 37 | lineno: 3, 38 | 'noop_lines': [ 39 | { 40 | 'ast_type': "NoopSameLine", 41 | s: "# sameline comment", 42 | }, 43 | ], 44 | }, 45 | }, 46 | ], 47 | 'noops_remainder': { 48 | 'ast_type': "RemainderNoops", 49 | 'col_offset': 1, 50 | 'end_col_offset': 1, 51 | 'end_lineno': 6, 52 | lineno: 4, 53 | lines: [ 54 | { 55 | 'ast_type': "NoopLine", 56 | 'col_offset': 1, 57 | lineno: 5, 58 | 'noop_line': "# remainder comment and newline\n", 59 | }, 60 | { 61 | 'ast_type': "NoopLine", 62 | 'col_offset': 1, 63 | lineno: 6, 64 | 'noop_line': "# last remainder comment line\n", 65 | }, 66 | ], 67 | }, 68 | }, 69 | } -------------------------------------------------------------------------------- /fixtures/literals_assign.py: -------------------------------------------------------------------------------- 1 | a = 3 # int 2 | b = 3.14 # float 3 | c = "somestring" # string 4 | d = None # None 5 | e = [1, 2, 3] # list literal 6 | f = (1, 2, 3) # tuple literal 7 | g = {1, 2, 3} # set literal 8 | h = {'a': 1, 'b': 2} # dict literal 9 | i = a + b - int(d) # expression assignment 10 | -------------------------------------------------------------------------------- /fixtures/loop_if.py: -------------------------------------------------------------------------------- 1 | for i in something: 2 | pass 3 | else: 4 | print("Python fors have elses") 5 | -------------------------------------------------------------------------------- /fixtures/other_statements.py: -------------------------------------------------------------------------------- 1 | a = 1 2 | b = 2 3 | del a 4 | def f(): 5 | global a 6 | nonlocal b 7 | yield b 8 | -------------------------------------------------------------------------------- /fixtures/pass.py: -------------------------------------------------------------------------------- 1 | pass # easy 2 | 3 | def somefun(): pass 4 | 5 | def otherfun(): 6 | pass 7 | -------------------------------------------------------------------------------- /fixtures/print.py: -------------------------------------------------------------------------------- 1 | print(1) 2 | print 2 3 | -------------------------------------------------------------------------------- /fixtures/print.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY2AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Print", 7 | 'col_offset': 1, 8 | dest: ~, 9 | 'end_col_offset': 6, 10 | 'end_lineno': 1, 11 | lineno: 1, 12 | nl: true, 13 | values: [ 14 | { 15 | 'ast_type': "Num", 16 | 'col_offset': 7, 17 | 'end_col_offset': 8, 18 | 'end_lineno': 1, 19 | lineno: 1, 20 | 'n': 1, 21 | }, 22 | ], 23 | }, 24 | { 25 | 'ast_type': "Print", 26 | 'col_offset': 1, 27 | dest: ~, 28 | 'end_col_offset': 6, 29 | 'end_lineno': 2, 30 | lineno: 2, 31 | nl: true, 32 | values: [ 33 | { 34 | 'ast_type': "Num", 35 | 'col_offset': 7, 36 | 'end_col_offset': 8, 37 | 'end_lineno': 2, 38 | lineno: 2, 39 | 'n': 2, 40 | }, 41 | ], 42 | }, 43 | ], 44 | }, 45 | } -------------------------------------------------------------------------------- /fixtures/qualified.py: -------------------------------------------------------------------------------- 1 | obj.method() 2 | a.b = 1 3 | a.b.c.d.e = 5 4 | x.y.z 5 | -------------------------------------------------------------------------------- /fixtures/receiver.py: -------------------------------------------------------------------------------- 1 | a.b(1) 2 | -------------------------------------------------------------------------------- /fixtures/receiver.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | args: [ 11 | { 12 | 'ast_type': "Num", 13 | 'col_offset': 5, 14 | 'end_col_offset': 6, 15 | 'end_lineno': 1, 16 | lineno: 1, 17 | 'n': 1, 18 | }, 19 | ], 20 | 'ast_type': "Call", 21 | 'col_offset': 1, 22 | func: { 23 | 'ast_type': "QualifiedIdentifier", 24 | 'col_offset': 2, 25 | ctx: "Load", 26 | 'end_col_offset': 3, 27 | 'end_lineno': 1, 28 | identifiers: [ 29 | { 30 | 'ast_type': "Name", 31 | 'col_offset': 1, 32 | ctx: "Load", 33 | 'end_col_offset': 2, 34 | 'end_lineno': 1, 35 | id: "a", 36 | lineno: 1, 37 | }, 38 | { 39 | 'ast_type': "Attribute", 40 | attr: "b", 41 | 'col_offset': 1, 42 | ctx: "Load", 43 | lineno: 1, 44 | }, 45 | ], 46 | lineno: 1, 47 | }, 48 | keywords: [], 49 | lineno: 1, 50 | }, 51 | }, 52 | ], 53 | }, 54 | } -------------------------------------------------------------------------------- /fixtures/repr.py: -------------------------------------------------------------------------------- 1 | repr(1) 2 | -------------------------------------------------------------------------------- /fixtures/repr.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | args: [ 11 | { 12 | 'ast_type': "Num", 13 | 'col_offset': 6, 14 | 'end_col_offset': 7, 15 | 'end_lineno': 1, 16 | lineno: 1, 17 | 'n': 1, 18 | }, 19 | ], 20 | 'ast_type': "Call", 21 | 'col_offset': 1, 22 | func: { 23 | 'ast_type': "Name", 24 | 'col_offset': 1, 25 | ctx: "Load", 26 | 'end_col_offset': 5, 27 | 'end_lineno': 1, 28 | id: "repr", 29 | lineno: 1, 30 | }, 31 | keywords: [], 32 | lineno: 1, 33 | }, 34 | }, 35 | ], 36 | }, 37 | } -------------------------------------------------------------------------------- /fixtures/repr.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "python:Call", 16 | '@role': [Call, Expression, Function], 17 | '@pos': { '@type': "uast:Positions", 18 | start: { '@type': "uast:Position", 19 | offset: 0, 20 | line: 1, 21 | col: 1, 22 | }, 23 | }, 24 | args: [ 25 | { '@type': "python:Num", 26 | '@token': 1, 27 | '@role': [Argument, Call, Expression, Function, Literal, Name, Number, Positional, Primitive], 28 | '@pos': { '@type': "uast:Positions", 29 | start: { '@type': "uast:Position", 30 | offset: 5, 31 | line: 1, 32 | col: 6, 33 | }, 34 | end: { '@type': "uast:Position", 35 | offset: 6, 36 | line: 1, 37 | col: 7, 38 | }, 39 | }, 40 | }, 41 | ], 42 | func: { '@type': "python:BoxedName", 43 | '@role': [Call, Callee], 44 | 'boxed_value': { '@type': "uast:Identifier", 45 | '@pos': { '@type': "uast:Positions", 46 | start: { '@type': "uast:Position", 47 | offset: 0, 48 | line: 1, 49 | col: 1, 50 | }, 51 | end: { '@type': "uast:Position", 52 | offset: 4, 53 | line: 1, 54 | col: 5, 55 | }, 56 | }, 57 | Name: "repr", 58 | }, 59 | ctx: "Load", 60 | }, 61 | keywords: [], 62 | }, 63 | }, 64 | ], 65 | } -------------------------------------------------------------------------------- /fixtures/repr.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "Call", 16 | '@role': [Call, Expression, Function], 17 | '@pos': { '@type': "uast:Positions", 18 | start: { '@type': "uast:Position", 19 | offset: 0, 20 | line: 1, 21 | col: 1, 22 | }, 23 | }, 24 | args: [ 25 | { '@type': "Num", 26 | '@token': 1, 27 | '@role': [Argument, Call, Expression, Function, Literal, Name, Number, Positional, Primitive], 28 | '@pos': { '@type': "uast:Positions", 29 | start: { '@type': "uast:Position", 30 | offset: 5, 31 | line: 1, 32 | col: 6, 33 | }, 34 | end: { '@type': "uast:Position", 35 | offset: 6, 36 | line: 1, 37 | col: 7, 38 | }, 39 | }, 40 | }, 41 | ], 42 | func: { '@type': "Name", 43 | '@token': "repr", 44 | '@role': [Call, Callee, Expression, Identifier], 45 | '@pos': { '@type': "uast:Positions", 46 | start: { '@type': "uast:Position", 47 | offset: 0, 48 | line: 1, 49 | col: 1, 50 | }, 51 | end: { '@type': "uast:Position", 52 | offset: 4, 53 | line: 1, 54 | col: 5, 55 | }, 56 | }, 57 | ctx: "Load", 58 | }, 59 | keywords: [], 60 | }, 61 | }, 62 | ], 63 | } -------------------------------------------------------------------------------- /fixtures/sameline.py: -------------------------------------------------------------------------------- 1 | print("same line test"); print("another call") 2 | -------------------------------------------------------------------------------- /fixtures/sameline.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | args: [ 11 | { 12 | 'ast_type': "Str", 13 | 'col_offset': 7, 14 | 'end_col_offset': 23, 15 | 'end_lineno': 1, 16 | lineno: 1, 17 | s: "same line test", 18 | }, 19 | ], 20 | 'ast_type': "Call", 21 | 'col_offset': 1, 22 | func: { 23 | 'ast_type': "Name", 24 | 'col_offset': 1, 25 | ctx: "Load", 26 | 'end_col_offset': 6, 27 | 'end_lineno': 1, 28 | id: "print", 29 | lineno: 1, 30 | }, 31 | keywords: [], 32 | lineno: 1, 33 | }, 34 | }, 35 | { 36 | 'ast_type': "Expr", 37 | 'col_offset': 26, 38 | lineno: 1, 39 | value: { 40 | args: [ 41 | { 42 | 'ast_type': "Str", 43 | 'col_offset': 32, 44 | 'end_col_offset': 46, 45 | 'end_lineno': 1, 46 | lineno: 1, 47 | s: "another call", 48 | }, 49 | ], 50 | 'ast_type': "Call", 51 | 'col_offset': 26, 52 | func: { 53 | 'ast_type': "Name", 54 | 'col_offset': 26, 55 | ctx: "Load", 56 | 'end_col_offset': 31, 57 | 'end_lineno': 1, 58 | id: "print", 59 | lineno: 1, 60 | }, 61 | keywords: [], 62 | lineno: 1, 63 | }, 64 | }, 65 | ], 66 | }, 67 | } -------------------------------------------------------------------------------- /fixtures/sorting.py: -------------------------------------------------------------------------------- 1 | # before comment 2 | 1+2 # linetrailing comment 3 | # remaining comment 4 | -------------------------------------------------------------------------------- /fixtures/string_format.py: -------------------------------------------------------------------------------- 1 | "first string {w} a value".format(w=value) 2 | "second string {0} {1}".format('with', 'positional') 3 | "third string {} {}".format('with', 'positional') 4 | -------------------------------------------------------------------------------- /fixtures/string_normal.py: -------------------------------------------------------------------------------- 1 | "Normal double quoted string" 2 | 'Normal single quoted string' 3 | -------------------------------------------------------------------------------- /fixtures/string_normal.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | 'ast_type': "Str", 11 | 'col_offset': 1, 12 | 'end_col_offset': 30, 13 | 'end_lineno': 1, 14 | lineno: 1, 15 | s: "Normal double quoted string", 16 | }, 17 | }, 18 | { 19 | 'ast_type': "Expr", 20 | 'col_offset': 1, 21 | lineno: 2, 22 | value: { 23 | 'ast_type': "Str", 24 | 'col_offset': 1, 25 | 'end_col_offset': 30, 26 | 'end_lineno': 2, 27 | lineno: 2, 28 | s: "Normal single quoted string", 29 | }, 30 | }, 31 | ], 32 | }, 33 | } -------------------------------------------------------------------------------- /fixtures/string_normal.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "python:BoxedStr", 16 | '@role': [Unannotated], 17 | 'boxed_value': { '@type': "uast:String", 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 29, 26 | line: 1, 27 | col: 30, 28 | }, 29 | }, 30 | Format: "", 31 | Value: "Normal double quoted string", 32 | }, 33 | }, 34 | }, 35 | { '@type': "python:Expr", 36 | '@role': [Expression], 37 | '@pos': { '@type': "uast:Positions", 38 | start: { '@type': "uast:Position", 39 | offset: 30, 40 | line: 2, 41 | col: 1, 42 | }, 43 | }, 44 | value: { '@type': "python:BoxedStr", 45 | '@role': [Unannotated], 46 | 'boxed_value': { '@type': "uast:String", 47 | '@pos': { '@type': "uast:Positions", 48 | start: { '@type': "uast:Position", 49 | offset: 30, 50 | line: 2, 51 | col: 1, 52 | }, 53 | end: { '@type': "uast:Position", 54 | offset: 59, 55 | line: 2, 56 | col: 30, 57 | }, 58 | }, 59 | Format: "", 60 | Value: "Normal single quoted string", 61 | }, 62 | }, 63 | }, 64 | ], 65 | } -------------------------------------------------------------------------------- /fixtures/string_normal.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "Str", 16 | '@token': "Normal double quoted string", 17 | '@role': [Expression, Literal, Primitive, String], 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 29, 26 | line: 1, 27 | col: 30, 28 | }, 29 | }, 30 | }, 31 | }, 32 | { '@type': "Expr", 33 | '@role': [Expression], 34 | '@pos': { '@type': "uast:Positions", 35 | start: { '@type': "uast:Position", 36 | offset: 30, 37 | line: 2, 38 | col: 1, 39 | }, 40 | }, 41 | value: { '@type': "Str", 42 | '@token': "Normal single quoted string", 43 | '@role': [Expression, Literal, Primitive, String], 44 | '@pos': { '@type': "uast:Positions", 45 | start: { '@type': "uast:Position", 46 | offset: 30, 47 | line: 2, 48 | col: 1, 49 | }, 50 | end: { '@type': "uast:Position", 51 | offset: 59, 52 | line: 2, 53 | col: 30, 54 | }, 55 | }, 56 | }, 57 | }, 58 | ], 59 | } -------------------------------------------------------------------------------- /fixtures/string_triple.py: -------------------------------------------------------------------------------- 1 | """ 2 | Triple double-quoted string 3 | Second line 4 | """ 5 | ''' 6 | Triple single-quoted string 7 | Second line 8 | ''' 9 | -------------------------------------------------------------------------------- /fixtures/string_triple.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 4, 9 | value: { 10 | 'ast_type': "Str", 11 | 'col_offset': 1, 12 | 'end_col_offset': 4, 13 | 'end_lineno': 4, 14 | lineno: 1, 15 | s: "\nTriple double-quoted string\nSecond line\n", 16 | }, 17 | }, 18 | { 19 | 'ast_type': "Expr", 20 | 'col_offset': 1, 21 | lineno: 8, 22 | value: { 23 | 'ast_type': "Str", 24 | 'col_offset': 1, 25 | 'end_col_offset': 4, 26 | 'end_lineno': 8, 27 | lineno: 5, 28 | s: "\nTriple single-quoted string\nSecond line\n", 29 | }, 30 | }, 31 | ], 32 | }, 33 | } -------------------------------------------------------------------------------- /fixtures/string_triple.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 44, 11 | line: 4, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "python:BoxedStr", 16 | '@role': [Unannotated], 17 | 'boxed_value': { '@type': "uast:String", 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 47, 26 | line: 4, 27 | col: 4, 28 | }, 29 | }, 30 | Format: "", 31 | Value: "\nTriple double-quoted string\nSecond line\n", 32 | }, 33 | }, 34 | }, 35 | { '@type': "python:Expr", 36 | '@role': [Expression], 37 | '@pos': { '@type': "uast:Positions", 38 | start: { '@type': "uast:Position", 39 | offset: 92, 40 | line: 8, 41 | col: 1, 42 | }, 43 | }, 44 | value: { '@type': "python:BoxedStr", 45 | '@role': [Unannotated], 46 | 'boxed_value': { '@type': "uast:String", 47 | '@pos': { '@type': "uast:Positions", 48 | start: { '@type': "uast:Position", 49 | offset: 48, 50 | line: 5, 51 | col: 1, 52 | }, 53 | end: { '@type': "uast:Position", 54 | offset: 95, 55 | line: 8, 56 | col: 4, 57 | }, 58 | }, 59 | Format: "", 60 | Value: "\nTriple single-quoted string\nSecond line\n", 61 | }, 62 | }, 63 | }, 64 | ], 65 | } -------------------------------------------------------------------------------- /fixtures/string_triple.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 44, 11 | line: 4, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "Str", 16 | '@token': "\nTriple double-quoted string\nSecond line\n", 17 | '@role': [Expression, Literal, Primitive, String], 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 47, 26 | line: 4, 27 | col: 4, 28 | }, 29 | }, 30 | }, 31 | }, 32 | { '@type': "Expr", 33 | '@role': [Expression], 34 | '@pos': { '@type': "uast:Positions", 35 | start: { '@type': "uast:Position", 36 | offset: 92, 37 | line: 8, 38 | col: 1, 39 | }, 40 | }, 41 | value: { '@type': "Str", 42 | '@token': "\nTriple single-quoted string\nSecond line\n", 43 | '@role': [Expression, Literal, Primitive, String], 44 | '@pos': { '@type': "uast:Positions", 45 | start: { '@type': "uast:Position", 46 | offset: 48, 47 | line: 5, 48 | col: 1, 49 | }, 50 | end: { '@type': "uast:Position", 51 | offset: 95, 52 | line: 8, 53 | col: 4, 54 | }, 55 | }, 56 | }, 57 | }, 58 | ], 59 | } -------------------------------------------------------------------------------- /fixtures/test.py: -------------------------------------------------------------------------------- 1 | if 1 > 2: 2 | pass 3 | -------------------------------------------------------------------------------- /fixtures/test.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "If", 7 | body: [ 8 | { 9 | 'ast_type': "Pass", 10 | 'col_offset': 5, 11 | 'end_col_offset': 9, 12 | 'end_lineno': 2, 13 | lineno: 2, 14 | }, 15 | ], 16 | 'col_offset': 1, 17 | 'end_col_offset': 3, 18 | 'end_lineno': 1, 19 | lineno: 1, 20 | orelse: [], 21 | test: { 22 | 'ast_type': "Compare", 23 | 'col_offset': 4, 24 | comparators: [ 25 | { 26 | 'ast_type': "Num", 27 | 'col_offset': 8, 28 | 'end_col_offset': 9, 29 | 'end_lineno': 1, 30 | lineno: 1, 31 | 'n': 2, 32 | }, 33 | ], 34 | left: { 35 | 'ast_type': "Num", 36 | 'col_offset': 4, 37 | 'end_col_offset': 5, 38 | 'end_lineno': 1, 39 | lineno: 1, 40 | 'n': 1, 41 | }, 42 | lineno: 1, 43 | ops: [ 44 | { 45 | 'ast_type': "Gt", 46 | }, 47 | ], 48 | }, 49 | }, 50 | ], 51 | }, 52 | } -------------------------------------------------------------------------------- /fixtures/u2_class_accessors.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | def __init__(self): 3 | self.__x = 0 4 | @property 5 | def x(self): 6 | return self.__x 7 | @x.setter 8 | def x(self, value): 9 | self.__x = value 10 | -------------------------------------------------------------------------------- /fixtures/u2_class_constructor.py: -------------------------------------------------------------------------------- 1 | def testcls1(): 2 | def __init__(self): 3 | pass 4 | 5 | def __new__(self): 6 | pass 7 | -------------------------------------------------------------------------------- /fixtures/u2_class_destructor.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | def __del__(self): 3 | pass 4 | -------------------------------------------------------------------------------- /fixtures/u2_class_destructor.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | args: { 11 | args: [ 12 | { 13 | '@token': "self", 14 | annotation: ~, 15 | 'ast_type': "arg", 16 | 'col_offset': 17, 17 | 'end_col_offset': 21, 18 | 'end_lineno': 2, 19 | lineno: 2, 20 | }, 21 | ], 22 | 'ast_type': "arguments", 23 | }, 24 | 'ast_type': "FunctionDef", 25 | body: [ 26 | { 27 | 'ast_type': "Pass", 28 | 'col_offset': 9, 29 | 'end_col_offset': 13, 30 | 'end_lineno': 3, 31 | lineno: 3, 32 | }, 33 | ], 34 | 'col_offset': 9, 35 | 'decorator_list': [], 36 | 'end_col_offset': 16, 37 | 'end_lineno': 2, 38 | lineno: 2, 39 | name: "__del__", 40 | returns: ~, 41 | }, 42 | ], 43 | 'col_offset': 7, 44 | 'decorator_list': [], 45 | 'end_col_offset': 15, 46 | 'end_lineno': 1, 47 | keywords: [], 48 | lineno: 1, 49 | name: "testcls1", 50 | }, 51 | ], 52 | }, 53 | } -------------------------------------------------------------------------------- /fixtures/u2_class_doc.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | """ 3 | This is the docstring 4 | """ 5 | -------------------------------------------------------------------------------- /fixtures/u2_class_doc.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | 'ast_type': "Expr", 11 | 'col_offset': 1, 12 | lineno: 4, 13 | value: { 14 | 'ast_type': "Str", 15 | 'col_offset': 5, 16 | 'end_col_offset': 8, 17 | 'end_lineno': 4, 18 | lineno: 2, 19 | s: "\n This is the docstring\n ", 20 | }, 21 | }, 22 | ], 23 | 'col_offset': 7, 24 | 'decorator_list': [], 25 | 'end_col_offset': 15, 26 | 'end_lineno': 1, 27 | keywords: [], 28 | lineno: 1, 29 | name: "testcls1", 30 | }, 31 | ], 32 | }, 33 | } -------------------------------------------------------------------------------- /fixtures/u2_class_doc.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "ClassDef", 7 | '@token': "testcls1", 8 | '@role': [Declaration, Identifier, Statement, Type], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 6, 12 | line: 1, 13 | col: 7, 14 | }, 15 | end: { '@type': "uast:Position", 16 | offset: 14, 17 | line: 1, 18 | col: 15, 19 | }, 20 | }, 21 | bases: { '@type': "ClassDef.bases", 22 | '@role': [Base, Declaration, Type], 23 | bases: [], 24 | }, 25 | body: { '@type': "ClassDef.body", 26 | '@role': [Body, Declaration, Type], 27 | 'body_stmts': [ 28 | { '@type': "Expr", 29 | '@role': [Expression], 30 | '@pos': { '@type': "uast:Positions", 31 | start: { '@type': "uast:Position", 32 | offset: 50, 33 | line: 4, 34 | col: 1, 35 | }, 36 | }, 37 | value: { '@type': "Str", 38 | '@token': "\n This is the docstring\n ", 39 | '@role': [Expression, Literal, Primitive, String], 40 | '@pos': { '@type': "uast:Positions", 41 | start: { '@type': "uast:Position", 42 | offset: 20, 43 | line: 2, 44 | col: 5, 45 | }, 46 | end: { '@type': "uast:Position", 47 | offset: 57, 48 | line: 4, 49 | col: 8, 50 | }, 51 | }, 52 | }, 53 | }, 54 | ], 55 | }, 56 | 'decorator_list': { '@type': "ClassDef.decorator_list", 57 | '@role': [Call, Declaration, Incomplete, Type], 58 | decorators: [], 59 | }, 60 | keywords: [], 61 | }, 62 | ], 63 | } -------------------------------------------------------------------------------- /fixtures/u2_class_empty.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | pass 3 | -------------------------------------------------------------------------------- /fixtures/u2_class_empty.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | 'ast_type': "Pass", 11 | 'col_offset': 5, 12 | 'end_col_offset': 9, 13 | 'end_lineno': 2, 14 | lineno: 2, 15 | }, 16 | ], 17 | 'col_offset': 7, 18 | 'decorator_list': [], 19 | 'end_col_offset': 15, 20 | 'end_lineno': 1, 21 | keywords: [], 22 | lineno: 1, 23 | name: "testcls1", 24 | }, 25 | ], 26 | }, 27 | } -------------------------------------------------------------------------------- /fixtures/u2_class_empty.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:ClassDef", 7 | '@token': "testcls1", 8 | '@role': [Declaration, Identifier, Statement, Type], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 6, 12 | line: 1, 13 | col: 7, 14 | }, 15 | end: { '@type': "uast:Position", 16 | offset: 14, 17 | line: 1, 18 | col: 15, 19 | }, 20 | }, 21 | bases: { '@type': "python:ClassDef.bases", 22 | '@role': [Base, Declaration, Type], 23 | bases: [], 24 | }, 25 | body: { '@type': "python:ClassDef.body", 26 | '@role': [Body, Declaration, Type], 27 | 'body_stmts': [ 28 | { '@type': "python:Pass", 29 | '@token': "pass", 30 | '@role': [Noop, Statement], 31 | '@pos': { '@type': "uast:Positions", 32 | start: { '@type': "uast:Position", 33 | offset: 20, 34 | line: 2, 35 | col: 5, 36 | }, 37 | end: { '@type': "uast:Position", 38 | offset: 24, 39 | line: 2, 40 | col: 9, 41 | }, 42 | }, 43 | }, 44 | ], 45 | }, 46 | 'decorator_list': { '@type': "python:ClassDef.decorator_list", 47 | '@role': [Call, Declaration, Incomplete, Type], 48 | decorators: [], 49 | }, 50 | keywords: [], 51 | }, 52 | ], 53 | } -------------------------------------------------------------------------------- /fixtures/u2_class_empty.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "ClassDef", 7 | '@token': "testcls1", 8 | '@role': [Declaration, Identifier, Statement, Type], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 6, 12 | line: 1, 13 | col: 7, 14 | }, 15 | end: { '@type': "uast:Position", 16 | offset: 14, 17 | line: 1, 18 | col: 15, 19 | }, 20 | }, 21 | bases: { '@type': "ClassDef.bases", 22 | '@role': [Base, Declaration, Type], 23 | bases: [], 24 | }, 25 | body: { '@type': "ClassDef.body", 26 | '@role': [Body, Declaration, Type], 27 | 'body_stmts': [ 28 | { '@type': "Pass", 29 | '@token': "pass", 30 | '@role': [Noop, Statement], 31 | '@pos': { '@type': "uast:Positions", 32 | start: { '@type': "uast:Position", 33 | offset: 20, 34 | line: 2, 35 | col: 5, 36 | }, 37 | end: { '@type': "uast:Position", 38 | offset: 24, 39 | line: 2, 40 | col: 9, 41 | }, 42 | }, 43 | }, 44 | ], 45 | }, 46 | 'decorator_list': { '@type': "ClassDef.decorator_list", 47 | '@role': [Call, Declaration, Incomplete, Type], 48 | decorators: [], 49 | }, 50 | keywords: [], 51 | }, 52 | ], 53 | } -------------------------------------------------------------------------------- /fixtures/u2_class_field.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | def __init__(self): 3 | self.instance_member = 2 4 | -------------------------------------------------------------------------------- /fixtures/u2_class_field_binding.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | classvar = 1 3 | -------------------------------------------------------------------------------- /fixtures/u2_class_field_binding.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | 'ast_type': "Assign", 11 | 'col_offset': 5, 12 | lineno: 2, 13 | targets: [ 14 | { 15 | 'ast_type': "Name", 16 | 'col_offset': 5, 17 | ctx: "Store", 18 | 'end_col_offset': 13, 19 | 'end_lineno': 2, 20 | id: "classvar", 21 | lineno: 2, 22 | }, 23 | ], 24 | value: { 25 | 'ast_type': "Num", 26 | 'col_offset': 16, 27 | 'end_col_offset': 17, 28 | 'end_lineno': 2, 29 | lineno: 2, 30 | 'n': 1, 31 | }, 32 | }, 33 | ], 34 | 'col_offset': 7, 35 | 'decorator_list': [], 36 | 'end_col_offset': 15, 37 | 'end_lineno': 1, 38 | keywords: [], 39 | lineno: 1, 40 | name: "testcls1", 41 | }, 42 | ], 43 | }, 44 | } -------------------------------------------------------------------------------- /fixtures/u2_class_field_qualifiers.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | def __init__(self): 3 | self.__private = 1 4 | -------------------------------------------------------------------------------- /fixtures/u2_class_inherit.py: -------------------------------------------------------------------------------- 1 | class A: pass 2 | class B: pass 3 | class testcls1(A): pass 4 | class testcls2(A, B): pass 5 | -------------------------------------------------------------------------------- /fixtures/u2_class_inner.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | class testcls2: 3 | pass 4 | -------------------------------------------------------------------------------- /fixtures/u2_class_inner.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | 'ast_type': "ClassDef", 11 | bases: [], 12 | body: [ 13 | { 14 | 'ast_type': "Pass", 15 | 'col_offset': 9, 16 | 'end_col_offset': 13, 17 | 'end_lineno': 3, 18 | lineno: 3, 19 | }, 20 | ], 21 | 'col_offset': 11, 22 | 'decorator_list': [], 23 | 'end_col_offset': 19, 24 | 'end_lineno': 2, 25 | keywords: [], 26 | lineno: 2, 27 | name: "testcls2", 28 | }, 29 | ], 30 | 'col_offset': 7, 31 | 'decorator_list': [], 32 | 'end_col_offset': 15, 33 | 'end_lineno': 1, 34 | keywords: [], 35 | lineno: 1, 36 | name: "testcls1", 37 | }, 38 | ], 39 | }, 40 | } -------------------------------------------------------------------------------- /fixtures/u2_class_metaclass_python3.py: -------------------------------------------------------------------------------- 1 | class meta(type): pass 2 | class cls1(metaclass=meta): pass 3 | -------------------------------------------------------------------------------- /fixtures/u2_class_metaclass_python3.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [ 8 | { 9 | 'ast_type': "Name", 10 | 'col_offset': 12, 11 | ctx: "Load", 12 | 'end_col_offset': 16, 13 | 'end_lineno': 1, 14 | id: "type", 15 | lineno: 1, 16 | }, 17 | ], 18 | body: [ 19 | { 20 | 'ast_type': "Pass", 21 | 'col_offset': 19, 22 | 'end_col_offset': 23, 23 | 'end_lineno': 1, 24 | lineno: 1, 25 | }, 26 | ], 27 | 'col_offset': 7, 28 | 'decorator_list': [], 29 | 'end_col_offset': 11, 30 | 'end_lineno': 1, 31 | keywords: [], 32 | lineno: 1, 33 | name: "meta", 34 | }, 35 | { 36 | 'ast_type': "ClassDef", 37 | bases: [], 38 | body: [ 39 | { 40 | 'ast_type': "Pass", 41 | 'col_offset': 29, 42 | 'end_col_offset': 33, 43 | 'end_lineno': 2, 44 | lineno: 2, 45 | }, 46 | ], 47 | 'col_offset': 7, 48 | 'decorator_list': [], 49 | 'end_col_offset': 11, 50 | 'end_lineno': 2, 51 | keywords: [ 52 | { 53 | arg: "metaclass", 54 | 'ast_type': "keyword", 55 | value: { 56 | 'ast_type': "Name", 57 | 'col_offset': 22, 58 | ctx: "Load", 59 | 'end_col_offset': 26, 60 | 'end_lineno': 2, 61 | id: "meta", 62 | lineno: 2, 63 | }, 64 | }, 65 | ], 66 | lineno: 2, 67 | name: "cls1", 68 | }, 69 | ], 70 | }, 71 | } -------------------------------------------------------------------------------- /fixtures/u2_class_method.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | def testfnc1(self): 3 | pass 4 | -------------------------------------------------------------------------------- /fixtures/u2_class_method.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | args: { 11 | args: [ 12 | { 13 | '@token': "self", 14 | annotation: ~, 15 | 'ast_type': "arg", 16 | 'col_offset': 18, 17 | 'end_col_offset': 22, 18 | 'end_lineno': 2, 19 | lineno: 2, 20 | }, 21 | ], 22 | 'ast_type': "arguments", 23 | }, 24 | 'ast_type': "FunctionDef", 25 | body: [ 26 | { 27 | 'ast_type': "Pass", 28 | 'col_offset': 9, 29 | 'end_col_offset': 13, 30 | 'end_lineno': 3, 31 | lineno: 3, 32 | }, 33 | ], 34 | 'col_offset': 9, 35 | 'decorator_list': [], 36 | 'end_col_offset': 17, 37 | 'end_lineno': 2, 38 | lineno: 2, 39 | name: "testfnc1", 40 | returns: ~, 41 | }, 42 | ], 43 | 'col_offset': 7, 44 | 'decorator_list': [], 45 | 'end_col_offset': 15, 46 | 'end_lineno': 1, 47 | keywords: [], 48 | lineno: 1, 49 | name: "testcls1", 50 | }, 51 | ], 52 | }, 53 | } -------------------------------------------------------------------------------- /fixtures/u2_class_method_binding.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | @classmethod 3 | def testfnc1(cls): 4 | pass 5 | @staticmethod 6 | def testfnc2(): 7 | pass 8 | -------------------------------------------------------------------------------- /fixtures/u2_class_method_private.py: -------------------------------------------------------------------------------- 1 | class cls1: 2 | def __pseudoprivate(self): pass 3 | -------------------------------------------------------------------------------- /fixtures/u2_class_method_private.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | args: { 11 | args: [ 12 | { 13 | '@token': "self", 14 | annotation: ~, 15 | 'ast_type': "arg", 16 | 'col_offset': 25, 17 | 'end_col_offset': 29, 18 | 'end_lineno': 2, 19 | lineno: 2, 20 | }, 21 | ], 22 | 'ast_type': "arguments", 23 | }, 24 | 'ast_type': "FunctionDef", 25 | body: [ 26 | { 27 | 'ast_type': "Pass", 28 | 'col_offset': 32, 29 | 'end_col_offset': 36, 30 | 'end_lineno': 2, 31 | lineno: 2, 32 | }, 33 | ], 34 | 'col_offset': 9, 35 | 'decorator_list': [], 36 | 'end_col_offset': 24, 37 | 'end_lineno': 2, 38 | lineno: 2, 39 | name: "__pseudoprivate", 40 | returns: ~, 41 | }, 42 | ], 43 | 'col_offset': 7, 44 | 'decorator_list': [], 45 | 'end_col_offset': 11, 46 | 'end_lineno': 1, 47 | keywords: [], 48 | lineno: 1, 49 | name: "cls1", 50 | }, 51 | ], 52 | }, 53 | } -------------------------------------------------------------------------------- /fixtures/u2_class_method_qualifiers.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | def __testfnc3(): 3 | pass 4 | -------------------------------------------------------------------------------- /fixtures/u2_class_method_qualifiers.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | args: { 11 | args: [], 12 | 'ast_type': "arguments", 13 | }, 14 | 'ast_type': "FunctionDef", 15 | body: [ 16 | { 17 | 'ast_type': "Pass", 18 | 'col_offset': 9, 19 | 'end_col_offset': 13, 20 | 'end_lineno': 3, 21 | lineno: 3, 22 | }, 23 | ], 24 | 'col_offset': 9, 25 | 'decorator_list': [], 26 | 'end_col_offset': 19, 27 | 'end_lineno': 2, 28 | lineno: 2, 29 | name: "__testfnc3", 30 | returns: ~, 31 | }, 32 | ], 33 | 'col_offset': 7, 34 | 'decorator_list': [], 35 | 'end_col_offset': 15, 36 | 'end_lineno': 1, 37 | keywords: [], 38 | lineno: 1, 39 | name: "testcls1", 40 | }, 41 | ], 42 | }, 43 | } -------------------------------------------------------------------------------- /fixtures/u2_class_specific_metaclass.py: -------------------------------------------------------------------------------- 1 | class testcls1(object): 2 | __metaclass__ = object 3 | -------------------------------------------------------------------------------- /fixtures/u2_class_specific_metaclass.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [ 8 | { 9 | 'ast_type': "Name", 10 | 'col_offset': 16, 11 | ctx: "Load", 12 | 'end_col_offset': 22, 13 | 'end_lineno': 1, 14 | id: "object", 15 | lineno: 1, 16 | }, 17 | ], 18 | body: [ 19 | { 20 | 'ast_type': "Assign", 21 | 'col_offset': 5, 22 | lineno: 2, 23 | targets: [ 24 | { 25 | 'ast_type': "Name", 26 | 'col_offset': 5, 27 | ctx: "Store", 28 | 'end_col_offset': 18, 29 | 'end_lineno': 2, 30 | id: "__metaclass__", 31 | lineno: 2, 32 | }, 33 | ], 34 | value: { 35 | 'ast_type': "Name", 36 | 'col_offset': 21, 37 | ctx: "Load", 38 | 'end_col_offset': 27, 39 | 'end_lineno': 2, 40 | id: "object", 41 | lineno: 2, 42 | }, 43 | }, 44 | ], 45 | 'col_offset': 7, 46 | 'decorator_list': [], 47 | 'end_col_offset': 15, 48 | 'end_lineno': 1, 49 | keywords: [], 50 | lineno: 1, 51 | name: "testcls1", 52 | }, 53 | ], 54 | }, 55 | } -------------------------------------------------------------------------------- /fixtures/u2_class_specific_slots.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | __slots__ = ['a', 'b'] 3 | -------------------------------------------------------------------------------- /fixtures/u2_class_specific_slots.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ClassDef", 7 | bases: [], 8 | body: [ 9 | { 10 | 'ast_type': "Assign", 11 | 'col_offset': 5, 12 | lineno: 2, 13 | targets: [ 14 | { 15 | 'ast_type': "Name", 16 | 'col_offset': 5, 17 | ctx: "Store", 18 | 'end_col_offset': 14, 19 | 'end_lineno': 2, 20 | id: "__slots__", 21 | lineno: 2, 22 | }, 23 | ], 24 | value: { 25 | 'ast_type': "List", 26 | 'col_offset': 17, 27 | ctx: "Load", 28 | elts: [ 29 | { 30 | 'ast_type': "Str", 31 | 'col_offset': 18, 32 | 'end_col_offset': 21, 33 | 'end_lineno': 2, 34 | lineno: 2, 35 | s: "a", 36 | }, 37 | { 38 | 'ast_type': "Str", 39 | 'col_offset': 23, 40 | 'end_col_offset': 26, 41 | 'end_lineno': 2, 42 | lineno: 2, 43 | s: "b", 44 | }, 45 | ], 46 | lineno: 2, 47 | }, 48 | }, 49 | ], 50 | 'col_offset': 7, 51 | 'decorator_list': [], 52 | 'end_col_offset': 15, 53 | 'end_lineno': 1, 54 | keywords: [], 55 | lineno: 1, 56 | name: "testcls1", 57 | }, 58 | ], 59 | }, 60 | } -------------------------------------------------------------------------------- /fixtures/u2_class_tag.py: -------------------------------------------------------------------------------- 1 | @testtag1 2 | class testcls1: 3 | pass 4 | 5 | @testtag2(1, 2) 6 | class testcls2: 7 | pass 8 | -------------------------------------------------------------------------------- /fixtures/u2_class_this.py: -------------------------------------------------------------------------------- 1 | class testcls1: 2 | def testfnc1(self): 3 | a = self.__class__ 4 | self.var = 1 5 | -------------------------------------------------------------------------------- /fixtures/u2_func_annotated.py: -------------------------------------------------------------------------------- 1 | def testfnc1(a: int, b: str, c: List, d: MyType) -> str: 2 | pass 3 | 4 | def testfnc2(a, b, c:int, d, e, f:str) -> str: 5 | pass 6 | 7 | def testfnc3(handler: Callable[..., Any]) -> Callable[..., Any]: 8 | pass 9 | -------------------------------------------------------------------------------- /fixtures/u2_func_anonymous.py: -------------------------------------------------------------------------------- 1 | lambda a, b, c: a + b + c 2 | -------------------------------------------------------------------------------- /fixtures/u2_func_async.py: -------------------------------------------------------------------------------- 1 | async def testfnc1(): 2 | pass 3 | -------------------------------------------------------------------------------- /fixtures/u2_func_async.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [], 8 | 'ast_type': "arguments", 9 | }, 10 | 'ast_type': "AsyncFunctionDef", 11 | body: [ 12 | { 13 | 'ast_type': "Pass", 14 | 'col_offset': 5, 15 | 'end_col_offset': 9, 16 | 'end_lineno': 2, 17 | lineno: 2, 18 | }, 19 | ], 20 | 'col_offset': 11, 21 | 'decorator_list': [], 22 | 'end_col_offset': 19, 23 | 'end_lineno': 1, 24 | lineno: 1, 25 | name: "testfnc1", 26 | returns: ~, 27 | }, 28 | ], 29 | }, 30 | } -------------------------------------------------------------------------------- /fixtures/u2_func_async.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "AsyncFunctionDef", 7 | '@token': "testfnc1", 8 | '@role': [Declaration, Function, Identifier, Incomplete, Name], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 10, 12 | line: 1, 13 | col: 11, 14 | }, 15 | end: { '@type': "uast:Position", 16 | offset: 18, 17 | line: 1, 18 | col: 19, 19 | }, 20 | }, 21 | args: { '@type': "arguments", 22 | '@role': [Argument, Declaration, Function, Incomplete], 23 | '@pos': { '@type': "uast:Positions", 24 | }, 25 | args: [], 26 | }, 27 | body: { '@type': "FunctionDef.body", 28 | '@role': [Body, Declaration, Function], 29 | 'body_stmts': [ 30 | { '@type': "Pass", 31 | '@token': "pass", 32 | '@role': [Noop, Statement], 33 | '@pos': { '@type': "uast:Positions", 34 | start: { '@type': "uast:Position", 35 | offset: 26, 36 | line: 2, 37 | col: 5, 38 | }, 39 | end: { '@type': "uast:Position", 40 | offset: 30, 41 | line: 2, 42 | col: 9, 43 | }, 44 | }, 45 | }, 46 | ], 47 | }, 48 | 'decorator_list': { '@type': "FunctionDef.decorators", 49 | '@role': [Declaration, Function, Incomplete], 50 | decorators: [], 51 | }, 52 | returns: ~, 53 | }, 54 | ], 55 | } -------------------------------------------------------------------------------- /fixtures/u2_func_doc.py: -------------------------------------------------------------------------------- 1 | def testfnc1(): 2 | """ 3 | Docstring 4 | """ 5 | pass 6 | -------------------------------------------------------------------------------- /fixtures/u2_func_doc.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [], 8 | 'ast_type': "arguments", 9 | }, 10 | 'ast_type': "FunctionDef", 11 | body: [ 12 | { 13 | 'ast_type': "Expr", 14 | 'col_offset': 1, 15 | lineno: 4, 16 | value: { 17 | 'ast_type': "Str", 18 | 'col_offset': 5, 19 | 'end_col_offset': 8, 20 | 'end_lineno': 4, 21 | lineno: 2, 22 | s: "\n Docstring\n ", 23 | }, 24 | }, 25 | { 26 | 'ast_type': "Pass", 27 | 'col_offset': 5, 28 | 'end_col_offset': 9, 29 | 'end_lineno': 5, 30 | lineno: 5, 31 | }, 32 | ], 33 | 'col_offset': 5, 34 | 'decorator_list': [], 35 | 'end_col_offset': 13, 36 | 'end_lineno': 1, 37 | lineno: 1, 38 | name: "testfnc1", 39 | returns: ~, 40 | }, 41 | ], 42 | }, 43 | } -------------------------------------------------------------------------------- /fixtures/u2_func_empty.py: -------------------------------------------------------------------------------- 1 | def testfnc1(): pass 2 | -------------------------------------------------------------------------------- /fixtures/u2_func_empty.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [], 8 | 'ast_type': "arguments", 9 | }, 10 | 'ast_type': "FunctionDef", 11 | body: [ 12 | { 13 | 'ast_type': "Pass", 14 | 'col_offset': 17, 15 | 'end_col_offset': 21, 16 | 'end_lineno': 1, 17 | lineno: 1, 18 | }, 19 | ], 20 | 'col_offset': 5, 21 | 'decorator_list': [], 22 | 'end_col_offset': 13, 23 | 'end_lineno': 1, 24 | lineno: 1, 25 | name: "testfnc1", 26 | returns: ~, 27 | }, 28 | ], 29 | }, 30 | } -------------------------------------------------------------------------------- /fixtures/u2_func_empty.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "FunctionDef", 7 | '@token': "testfnc1", 8 | '@role': [Declaration, Function, Identifier, Name], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 4, 12 | line: 1, 13 | col: 5, 14 | }, 15 | end: { '@type': "uast:Position", 16 | offset: 12, 17 | line: 1, 18 | col: 13, 19 | }, 20 | }, 21 | args: { '@type': "arguments", 22 | '@role': [Argument, Declaration, Function, Incomplete], 23 | '@pos': { '@type': "uast:Positions", 24 | }, 25 | args: [], 26 | }, 27 | body: { '@type': "FunctionDef.body", 28 | '@role': [Body, Declaration, Function], 29 | 'body_stmts': [ 30 | { '@type': "Pass", 31 | '@token': "pass", 32 | '@role': [Noop, Statement], 33 | '@pos': { '@type': "uast:Positions", 34 | start: { '@type': "uast:Position", 35 | offset: 16, 36 | line: 1, 37 | col: 17, 38 | }, 39 | end: { '@type': "uast:Position", 40 | offset: 20, 41 | line: 1, 42 | col: 21, 43 | }, 44 | }, 45 | }, 46 | ], 47 | }, 48 | 'decorator_list': { '@type': "FunctionDef.decorators", 49 | '@role': [Declaration, Function, Incomplete], 50 | decorators: [], 51 | }, 52 | returns: ~, 53 | }, 54 | ], 55 | } -------------------------------------------------------------------------------- /fixtures/u2_func_inner.py: -------------------------------------------------------------------------------- 1 | def testfnc1(): 2 | def testfnc2(): 3 | pass 4 | 5 | def testfnc3(): 6 | def testfnc4(): 7 | def testfnc5(): 8 | pass 9 | -------------------------------------------------------------------------------- /fixtures/u2_func_params_default.py: -------------------------------------------------------------------------------- 1 | def testfn1(a, b=1): pass 2 | -------------------------------------------------------------------------------- /fixtures/u2_func_params_default.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [ 8 | { 9 | '@token': "a", 10 | annotation: ~, 11 | 'ast_type': "arg", 12 | 'col_offset': 13, 13 | 'end_col_offset': 14, 14 | 'end_lineno': 1, 15 | lineno: 1, 16 | }, 17 | { 18 | '@token': "b", 19 | annotation: ~, 20 | 'ast_type': "arg", 21 | 'col_offset': 16, 22 | default: { 23 | 'ast_type': "Num", 24 | 'col_offset': 18, 25 | 'end_col_offset': 19, 26 | 'end_lineno': 1, 27 | lineno: 1, 28 | 'n': 1, 29 | }, 30 | 'end_col_offset': 17, 31 | 'end_lineno': 1, 32 | lineno: 1, 33 | }, 34 | ], 35 | 'ast_type': "arguments", 36 | }, 37 | 'ast_type': "FunctionDef", 38 | body: [ 39 | { 40 | 'ast_type': "Pass", 41 | 'col_offset': 22, 42 | 'end_col_offset': 26, 43 | 'end_lineno': 1, 44 | lineno: 1, 45 | }, 46 | ], 47 | 'col_offset': 5, 48 | 'decorator_list': [], 49 | 'end_col_offset': 12, 50 | 'end_lineno': 1, 51 | lineno: 1, 52 | name: "testfn1", 53 | returns: ~, 54 | }, 55 | ], 56 | }, 57 | } -------------------------------------------------------------------------------- /fixtures/u2_func_params_kwonlyargs.py: -------------------------------------------------------------------------------- 1 | def testfnc1(*, a, b): pass 2 | -------------------------------------------------------------------------------- /fixtures/u2_func_params_kwonlyargs.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [ 8 | { 9 | '@token': "a", 10 | annotation: ~, 11 | 'ast_type': "kwonly_arg", 12 | 'col_offset': 17, 13 | default: { 14 | LiteralValue: "None", 15 | 'ast_type': "NoneLiteral", 16 | }, 17 | 'end_col_offset': 18, 18 | 'end_lineno': 1, 19 | lineno: 1, 20 | }, 21 | { 22 | '@token': "b", 23 | annotation: ~, 24 | 'ast_type': "kwonly_arg", 25 | 'col_offset': 20, 26 | default: { 27 | LiteralValue: "None", 28 | 'ast_type': "NoneLiteral", 29 | }, 30 | 'end_col_offset': 21, 31 | 'end_lineno': 1, 32 | lineno: 1, 33 | }, 34 | ], 35 | 'ast_type': "arguments", 36 | }, 37 | 'ast_type': "FunctionDef", 38 | body: [ 39 | { 40 | 'ast_type': "Pass", 41 | 'col_offset': 24, 42 | 'end_col_offset': 28, 43 | 'end_lineno': 1, 44 | lineno: 1, 45 | }, 46 | ], 47 | 'col_offset': 5, 48 | 'decorator_list': [], 49 | 'end_col_offset': 13, 50 | 'end_lineno': 1, 51 | lineno: 1, 52 | name: "testfnc1", 53 | returns: ~, 54 | }, 55 | ], 56 | }, 57 | } -------------------------------------------------------------------------------- /fixtures/u2_func_params_kwonlyargs_default.py: -------------------------------------------------------------------------------- 1 | def testfnc1(*, a, b=1, c=2): pass 2 | -------------------------------------------------------------------------------- /fixtures/u2_func_params_variadic_list.py: -------------------------------------------------------------------------------- 1 | def testfnc1(*a): pass 2 | -------------------------------------------------------------------------------- /fixtures/u2_func_params_variadic_list.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [ 8 | { 9 | '@token': "a", 10 | annotation: ~, 11 | 'ast_type': "vararg", 12 | 'col_offset': 15, 13 | 'end_col_offset': 16, 14 | 'end_lineno': 1, 15 | lineno: 1, 16 | }, 17 | ], 18 | 'ast_type': "arguments", 19 | }, 20 | 'ast_type': "FunctionDef", 21 | body: [ 22 | { 23 | 'ast_type': "Pass", 24 | 'col_offset': 19, 25 | 'end_col_offset': 23, 26 | 'end_lineno': 1, 27 | lineno: 1, 28 | }, 29 | ], 30 | 'col_offset': 5, 31 | 'decorator_list': [], 32 | 'end_col_offset': 13, 33 | 'end_lineno': 1, 34 | lineno: 1, 35 | name: "testfnc1", 36 | returns: ~, 37 | }, 38 | ], 39 | }, 40 | } -------------------------------------------------------------------------------- /fixtures/u2_func_params_variadic_map.py: -------------------------------------------------------------------------------- 1 | def testfnc1(**kwargs): pass 2 | -------------------------------------------------------------------------------- /fixtures/u2_func_params_variadic_map.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [ 8 | { 9 | '@token': "kwargs", 10 | annotation: ~, 11 | 'ast_type': "kwarg", 12 | 'col_offset': 16, 13 | 'end_col_offset': 22, 14 | 'end_lineno': 1, 15 | lineno: 1, 16 | }, 17 | ], 18 | 'ast_type': "arguments", 19 | }, 20 | 'ast_type': "FunctionDef", 21 | body: [ 22 | { 23 | 'ast_type': "Pass", 24 | 'col_offset': 25, 25 | 'end_col_offset': 29, 26 | 'end_lineno': 1, 27 | lineno: 1, 28 | }, 29 | ], 30 | 'col_offset': 5, 31 | 'decorator_list': [], 32 | 'end_col_offset': 13, 33 | 'end_lineno': 1, 34 | lineno: 1, 35 | name: "testfnc1", 36 | returns: ~, 37 | }, 38 | ], 39 | }, 40 | } -------------------------------------------------------------------------------- /fixtures/u2_func_return_multiple.py: -------------------------------------------------------------------------------- 1 | def testfnc1(): 2 | return 1, 2 3 | -------------------------------------------------------------------------------- /fixtures/u2_func_return_multiple.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | args: { 7 | args: [], 8 | 'ast_type': "arguments", 9 | }, 10 | 'ast_type': "FunctionDef", 11 | body: [ 12 | { 13 | 'ast_type': "Return", 14 | 'col_offset': 5, 15 | 'end_col_offset': 11, 16 | 'end_lineno': 2, 17 | lineno: 2, 18 | value: { 19 | 'ast_type': "Tuple", 20 | 'col_offset': 12, 21 | ctx: "Load", 22 | elts: [ 23 | { 24 | 'ast_type': "Num", 25 | 'col_offset': 12, 26 | 'end_col_offset': 13, 27 | 'end_lineno': 2, 28 | lineno: 2, 29 | 'n': 1, 30 | }, 31 | { 32 | 'ast_type': "Num", 33 | 'col_offset': 15, 34 | 'end_col_offset': 16, 35 | 'end_lineno': 2, 36 | lineno: 2, 37 | 'n': 2, 38 | }, 39 | ], 40 | lineno: 2, 41 | }, 42 | }, 43 | ], 44 | 'col_offset': 5, 45 | 'decorator_list': [], 46 | 'end_col_offset': 13, 47 | 'end_lineno': 1, 48 | lineno: 1, 49 | name: "testfnc1", 50 | returns: ~, 51 | }, 52 | ], 53 | }, 54 | } -------------------------------------------------------------------------------- /fixtures/u2_func_simple.py: -------------------------------------------------------------------------------- 1 | def testfnc1(a, b): 2 | a = b 3 | return 1 4 | -------------------------------------------------------------------------------- /fixtures/u2_func_tagged.py: -------------------------------------------------------------------------------- 1 | @testtag1 2 | def testfnc1(): pass 3 | 4 | @testtag2(1, 2) 5 | @testtag3 6 | def testfnc2(): pass 7 | -------------------------------------------------------------------------------- /fixtures/u2_import_module_alias.py: -------------------------------------------------------------------------------- 1 | import x as y 2 | -------------------------------------------------------------------------------- /fixtures/u2_import_module_alias.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Import", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | names: [ 10 | { 11 | asname: "y", 12 | 'ast_type': "alias", 13 | name: "x", 14 | }, 15 | ], 16 | }, 17 | ], 18 | }, 19 | } -------------------------------------------------------------------------------- /fixtures/u2_import_module_alias.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "uast:RuntimeImport", 7 | '@pos': { '@type': "uast:Positions", 8 | start: { '@type': "uast:Position", 9 | offset: 0, 10 | line: 1, 11 | col: 1, 12 | }, 13 | }, 14 | All: false, 15 | Names: ~, 16 | Path: { '@type': "uast:Alias", 17 | '@pos': { '@type': "uast:Positions", 18 | }, 19 | Name: { '@type': "uast:Identifier", 20 | '@pos': { '@type': "uast:Positions", 21 | }, 22 | Name: "y", 23 | }, 24 | Node: { '@type': "uast:Identifier", 25 | '@pos': { '@type': "uast:Positions", 26 | }, 27 | Name: "x", 28 | }, 29 | }, 30 | Target: ~, 31 | }, 32 | ], 33 | } -------------------------------------------------------------------------------- /fixtures/u2_import_module_alias.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Import", 7 | '@token': "import", 8 | '@role': [Declaration, Import, Statement], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 0, 12 | line: 1, 13 | col: 1, 14 | }, 15 | }, 16 | names: { '@type': "ImportFrom.names", 17 | '@role': [Identifier, Import, Incomplete, Pathname], 18 | 'name_list': [ 19 | { '@type': "alias", 20 | '@token': "x", 21 | '@role': [Identifier, Import, Pathname], 22 | '@pos': { '@type': "uast:Positions", 23 | }, 24 | asname: { '@type': "alias.asname", 25 | '@token': "y", 26 | '@role': [Alias, Identifier, Import, Pathname], 27 | }, 28 | }, 29 | ], 30 | }, 31 | }, 32 | ], 33 | } -------------------------------------------------------------------------------- /fixtures/u2_import_multiple.py: -------------------------------------------------------------------------------- 1 | import a, b, c 2 | -------------------------------------------------------------------------------- /fixtures/u2_import_multiple.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Import", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | names: [ 10 | { 11 | asname: ~, 12 | 'ast_type': "alias", 13 | name: "a", 14 | }, 15 | { 16 | asname: ~, 17 | 'ast_type': "alias", 18 | name: "b", 19 | }, 20 | { 21 | asname: ~, 22 | 'ast_type': "alias", 23 | name: "c", 24 | }, 25 | ], 26 | }, 27 | ], 28 | }, 29 | } -------------------------------------------------------------------------------- /fixtures/u2_import_multiple.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "uast:Group", 7 | '@pos': { '@type': "uast:Positions", 8 | start: { '@type': "uast:Position", 9 | offset: 0, 10 | line: 1, 11 | col: 1, 12 | }, 13 | }, 14 | Nodes: [ 15 | { '@type': "uast:RuntimeImport", 16 | All: false, 17 | Names: ~, 18 | Path: { '@type': "uast:Identifier", 19 | '@pos': { '@type': "uast:Positions", 20 | }, 21 | Name: "a", 22 | }, 23 | Target: ~, 24 | }, 25 | { '@type': "uast:RuntimeImport", 26 | All: false, 27 | Names: ~, 28 | Path: { '@type': "uast:Identifier", 29 | '@pos': { '@type': "uast:Positions", 30 | }, 31 | Name: "b", 32 | }, 33 | Target: ~, 34 | }, 35 | { '@type': "uast:RuntimeImport", 36 | All: false, 37 | Names: ~, 38 | Path: { '@type': "uast:Identifier", 39 | '@pos': { '@type': "uast:Positions", 40 | }, 41 | Name: "c", 42 | }, 43 | Target: ~, 44 | }, 45 | ], 46 | }, 47 | ], 48 | } -------------------------------------------------------------------------------- /fixtures/u2_import_multiple.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Import", 7 | '@token': "import", 8 | '@role': [Declaration, Import, Statement], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 0, 12 | line: 1, 13 | col: 1, 14 | }, 15 | }, 16 | names: { '@type': "ImportFrom.names", 17 | '@role': [Identifier, Import, Incomplete, Pathname], 18 | 'name_list': [ 19 | { '@type': "alias", 20 | '@token': "a", 21 | '@role': [Identifier, Import, Pathname], 22 | '@pos': { '@type': "uast:Positions", 23 | }, 24 | asname: { '@type': "alias.asname", 25 | '@role': [Alias, Identifier, Import, Pathname], 26 | '@token': ~, 27 | }, 28 | }, 29 | { '@type': "alias", 30 | '@token': "b", 31 | '@role': [Identifier, Import, Pathname], 32 | '@pos': { '@type': "uast:Positions", 33 | }, 34 | asname: { '@type': "alias.asname", 35 | '@role': [Alias, Identifier, Import, Pathname], 36 | '@token': ~, 37 | }, 38 | }, 39 | { '@type': "alias", 40 | '@token': "c", 41 | '@role': [Identifier, Import, Pathname], 42 | '@pos': { '@type': "uast:Positions", 43 | }, 44 | asname: { '@type': "alias.asname", 45 | '@role': [Alias, Identifier, Import, Pathname], 46 | '@token': ~, 47 | }, 48 | }, 49 | ], 50 | }, 51 | }, 52 | ], 53 | } -------------------------------------------------------------------------------- /fixtures/u2_import_path.py: -------------------------------------------------------------------------------- 1 | a = __import__('/a/b/c/d') 2 | from c import x 3 | -------------------------------------------------------------------------------- /fixtures/u2_import_path.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Assign", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | targets: [ 10 | { 11 | 'ast_type': "Name", 12 | 'col_offset': 1, 13 | ctx: "Store", 14 | 'end_col_offset': 2, 15 | 'end_lineno': 1, 16 | id: "a", 17 | lineno: 1, 18 | }, 19 | ], 20 | value: { 21 | args: [ 22 | { 23 | 'ast_type': "Str", 24 | 'col_offset': 16, 25 | 'end_col_offset': 26, 26 | 'end_lineno': 1, 27 | lineno: 1, 28 | s: "/a/b/c/d", 29 | }, 30 | ], 31 | 'ast_type': "Call", 32 | 'col_offset': 5, 33 | func: { 34 | 'ast_type': "Name", 35 | 'col_offset': 5, 36 | ctx: "Load", 37 | 'end_col_offset': 15, 38 | 'end_lineno': 1, 39 | id: "__import__", 40 | lineno: 1, 41 | }, 42 | keywords: [], 43 | lineno: 1, 44 | }, 45 | }, 46 | { 47 | 'ast_type': "ImportFrom", 48 | 'col_offset': 1, 49 | 'end_col_offset': 7, 50 | 'end_lineno': 2, 51 | level: 0, 52 | lineno: 2, 53 | module: "c", 54 | names: [ 55 | { 56 | asname: ~, 57 | 'ast_type': "alias", 58 | name: "x", 59 | }, 60 | ], 61 | }, 62 | ], 63 | }, 64 | } -------------------------------------------------------------------------------- /fixtures/u2_import_relativepath.py: -------------------------------------------------------------------------------- 1 | from .a import b 2 | from ..c.d import e 3 | from ... import f 4 | -------------------------------------------------------------------------------- /fixtures/u2_import_relativepath.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ImportFrom", 7 | 'col_offset': 1, 8 | 'end_col_offset': 8, 9 | 'end_lineno': 1, 10 | level: 1, 11 | lineno: 1, 12 | module: "a", 13 | names: [ 14 | { 15 | asname: ~, 16 | 'ast_type': "alias", 17 | name: "b", 18 | }, 19 | ], 20 | }, 21 | { 22 | 'ast_type': "ImportFrom", 23 | 'col_offset': 1, 24 | level: 2, 25 | lineno: 2, 26 | module: "c.d", 27 | names: [ 28 | { 29 | asname: ~, 30 | 'ast_type': "alias", 31 | name: "e", 32 | }, 33 | ], 34 | }, 35 | { 36 | 'ast_type': "ImportFrom", 37 | 'col_offset': 1, 38 | level: 3, 39 | lineno: 3, 40 | module: ~, 41 | names: [ 42 | { 43 | asname: ~, 44 | 'ast_type': "alias", 45 | name: "f", 46 | }, 47 | ], 48 | }, 49 | ], 50 | }, 51 | } -------------------------------------------------------------------------------- /fixtures/u2_import_rename.py: -------------------------------------------------------------------------------- 1 | import a as b 2 | from c import e as f 3 | -------------------------------------------------------------------------------- /fixtures/u2_import_rename.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Import", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | names: [ 10 | { 11 | asname: "b", 12 | 'ast_type': "alias", 13 | name: "a", 14 | }, 15 | ], 16 | }, 17 | { 18 | 'ast_type': "ImportFrom", 19 | 'col_offset': 1, 20 | 'end_col_offset': 7, 21 | 'end_lineno': 2, 22 | level: 0, 23 | lineno: 2, 24 | module: "c", 25 | names: [ 26 | { 27 | asname: "f", 28 | 'ast_type': "alias", 29 | name: "e", 30 | }, 31 | ], 32 | }, 33 | ], 34 | }, 35 | } -------------------------------------------------------------------------------- /fixtures/u2_import_rename.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "uast:RuntimeImport", 7 | '@pos': { '@type': "uast:Positions", 8 | start: { '@type': "uast:Position", 9 | offset: 0, 10 | line: 1, 11 | col: 1, 12 | }, 13 | }, 14 | All: false, 15 | Names: ~, 16 | Path: { '@type': "uast:Alias", 17 | '@pos': { '@type': "uast:Positions", 18 | }, 19 | Name: { '@type': "uast:Identifier", 20 | '@pos': { '@type': "uast:Positions", 21 | }, 22 | Name: "b", 23 | }, 24 | Node: { '@type': "uast:Identifier", 25 | '@pos': { '@type': "uast:Positions", 26 | }, 27 | Name: "a", 28 | }, 29 | }, 30 | Target: ~, 31 | }, 32 | { '@type': "uast:RuntimeImport", 33 | '@pos': { '@type': "uast:Positions", 34 | start: { '@type': "uast:Position", 35 | offset: 14, 36 | line: 2, 37 | col: 1, 38 | }, 39 | end: { '@type': "uast:Position", 40 | offset: 20, 41 | line: 2, 42 | col: 7, 43 | }, 44 | }, 45 | All: false, 46 | Names: [ 47 | { '@type': "uast:Alias", 48 | '@pos': { '@type': "uast:Positions", 49 | }, 50 | Name: { '@type': "uast:Identifier", 51 | '@pos': { '@type': "uast:Positions", 52 | }, 53 | Name: "f", 54 | }, 55 | Node: { '@type': "uast:Identifier", 56 | '@pos': { '@type': "uast:Positions", 57 | }, 58 | Name: "e", 59 | }, 60 | }, 61 | ], 62 | Path: { '@type': "uast:Identifier", 63 | '@pos': { '@type': "uast:Positions", 64 | }, 65 | Name: "c", 66 | }, 67 | Target: ~, 68 | }, 69 | ], 70 | } -------------------------------------------------------------------------------- /fixtures/u2_import_simple.py: -------------------------------------------------------------------------------- 1 | import a 2 | import b 3 | -------------------------------------------------------------------------------- /fixtures/u2_import_simple.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Import", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | names: [ 10 | { 11 | asname: ~, 12 | 'ast_type': "alias", 13 | name: "a", 14 | }, 15 | ], 16 | }, 17 | { 18 | 'ast_type': "Import", 19 | 'col_offset': 1, 20 | lineno: 2, 21 | names: [ 22 | { 23 | asname: ~, 24 | 'ast_type': "alias", 25 | name: "b", 26 | }, 27 | ], 28 | }, 29 | ], 30 | }, 31 | } -------------------------------------------------------------------------------- /fixtures/u2_import_simple.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "uast:RuntimeImport", 7 | '@pos': { '@type': "uast:Positions", 8 | start: { '@type': "uast:Position", 9 | offset: 0, 10 | line: 1, 11 | col: 1, 12 | }, 13 | }, 14 | All: false, 15 | Names: ~, 16 | Path: { '@type': "uast:Identifier", 17 | '@pos': { '@type': "uast:Positions", 18 | }, 19 | Name: "a", 20 | }, 21 | Target: ~, 22 | }, 23 | { '@type': "uast:RuntimeImport", 24 | '@pos': { '@type': "uast:Positions", 25 | start: { '@type': "uast:Position", 26 | offset: 9, 27 | line: 2, 28 | col: 1, 29 | }, 30 | }, 31 | All: false, 32 | Names: ~, 33 | Path: { '@type': "uast:Identifier", 34 | '@pos': { '@type': "uast:Positions", 35 | }, 36 | Name: "b", 37 | }, 38 | Target: ~, 39 | }, 40 | ], 41 | } -------------------------------------------------------------------------------- /fixtures/u2_import_simple.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Import", 7 | '@token': "import", 8 | '@role': [Declaration, Import, Statement], 9 | '@pos': { '@type': "uast:Positions", 10 | start: { '@type': "uast:Position", 11 | offset: 0, 12 | line: 1, 13 | col: 1, 14 | }, 15 | }, 16 | names: { '@type': "ImportFrom.names", 17 | '@role': [Identifier, Import, Incomplete, Pathname], 18 | 'name_list': [ 19 | { '@type': "alias", 20 | '@token': "a", 21 | '@role': [Identifier, Import, Pathname], 22 | '@pos': { '@type': "uast:Positions", 23 | }, 24 | asname: { '@type': "alias.asname", 25 | '@role': [Alias, Identifier, Import, Pathname], 26 | '@token': ~, 27 | }, 28 | }, 29 | ], 30 | }, 31 | }, 32 | { '@type': "Import", 33 | '@token': "import", 34 | '@role': [Declaration, Import, Statement], 35 | '@pos': { '@type': "uast:Positions", 36 | start: { '@type': "uast:Position", 37 | offset: 9, 38 | line: 2, 39 | col: 1, 40 | }, 41 | }, 42 | names: { '@type': "ImportFrom.names", 43 | '@role': [Identifier, Import, Incomplete, Pathname], 44 | 'name_list': [ 45 | { '@type': "alias", 46 | '@token': "b", 47 | '@role': [Identifier, Import, Pathname], 48 | '@pos': { '@type': "uast:Positions", 49 | }, 50 | asname: { '@type': "alias.asname", 51 | '@role': [Alias, Identifier, Import, Pathname], 52 | '@token': ~, 53 | }, 54 | }, 55 | ], 56 | }, 57 | }, 58 | ], 59 | } -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbol.py: -------------------------------------------------------------------------------- 1 | import a.b 2 | from f import g 3 | from h import i, j, k 4 | -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbol.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Import", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | names: [ 10 | { 11 | asname: ~, 12 | 'ast_type': "alias", 13 | name: "a.b", 14 | }, 15 | ], 16 | }, 17 | { 18 | 'ast_type': "ImportFrom", 19 | 'col_offset': 1, 20 | 'end_col_offset': 7, 21 | 'end_lineno': 2, 22 | level: 0, 23 | lineno: 2, 24 | module: "f", 25 | names: [ 26 | { 27 | asname: ~, 28 | 'ast_type': "alias", 29 | name: "g", 30 | }, 31 | ], 32 | }, 33 | { 34 | 'ast_type': "ImportFrom", 35 | 'col_offset': 1, 36 | 'end_col_offset': 7, 37 | 'end_lineno': 3, 38 | level: 0, 39 | lineno: 3, 40 | module: "h", 41 | names: [ 42 | { 43 | asname: ~, 44 | 'ast_type': "alias", 45 | name: "i", 46 | }, 47 | { 48 | asname: ~, 49 | 'ast_type': "alias", 50 | name: "j", 51 | }, 52 | { 53 | asname: ~, 54 | 'ast_type': "alias", 55 | name: "k", 56 | }, 57 | ], 58 | }, 59 | ], 60 | }, 61 | } -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbol_alias.py: -------------------------------------------------------------------------------- 1 | import x.y as z 2 | from a.b import c as d 3 | -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbol_alias.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Import", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | names: [ 10 | { 11 | asname: "z", 12 | 'ast_type': "alias", 13 | name: "x.y", 14 | }, 15 | ], 16 | }, 17 | { 18 | 'ast_type': "ImportFrom", 19 | 'col_offset': 1, 20 | level: 0, 21 | lineno: 2, 22 | module: "a.b", 23 | names: [ 24 | { 25 | asname: "d", 26 | 'ast_type': "alias", 27 | name: "c", 28 | }, 29 | ], 30 | }, 31 | ], 32 | }, 33 | } -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbols_namespaced.py: -------------------------------------------------------------------------------- 1 | from a import * 2 | -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbols_namespaced.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "ImportFrom", 7 | 'col_offset': 1, 8 | 'end_col_offset': 7, 9 | 'end_lineno': 1, 10 | level: 0, 11 | lineno: 1, 12 | module: "a", 13 | names: [ 14 | { 15 | asname: ~, 16 | 'ast_type': "alias", 17 | name: "*", 18 | }, 19 | ], 20 | }, 21 | ], 22 | }, 23 | } -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbols_namespaced.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "uast:RuntimeImport", 7 | '@pos': { '@type': "uast:Positions", 8 | start: { '@type': "uast:Position", 9 | offset: 0, 10 | line: 1, 11 | col: 1, 12 | }, 13 | end: { '@type': "uast:Position", 14 | offset: 6, 15 | line: 1, 16 | col: 7, 17 | }, 18 | }, 19 | All: true, 20 | Names: ~, 21 | Path: { '@type': "uast:Identifier", 22 | '@pos': { '@type': "uast:Positions", 23 | }, 24 | Name: "a", 25 | }, 26 | Target: ~, 27 | }, 28 | ], 29 | } -------------------------------------------------------------------------------- /fixtures/u2_import_subsymbols_namespaced.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "ImportFrom", 7 | '@role': [Declaration, Import, Statement], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | end: { '@type': "uast:Position", 15 | offset: 6, 16 | line: 1, 17 | col: 7, 18 | }, 19 | }, 20 | level: { '@type': "ImportFrom.level", 21 | '@token': "", 22 | '@role': [Import, Incomplete], 23 | }, 24 | module: { '@type': "ImportFrom.module", 25 | '@token': "a", 26 | '@role': [Identifier, Import, Pathname], 27 | }, 28 | names: { '@type': "ImportFrom.names", 29 | '@role': [Identifier, Import, Incomplete, Pathname], 30 | 'name_list': [ 31 | { '@type': "alias", 32 | '@token': "*", 33 | '@role': [Identifier, Import, Pathname], 34 | '@pos': { '@type': "uast:Positions", 35 | }, 36 | asname: { '@type': "alias.asname", 37 | '@role': [Alias, Identifier, Import, Pathname], 38 | '@token': ~, 39 | }, 40 | }, 41 | ], 42 | }, 43 | 'num_level': 0, 44 | }, 45 | ], 46 | } -------------------------------------------------------------------------------- /fixtures/unary.py: -------------------------------------------------------------------------------- 1 | ~1 2 | -a 3 | +a 4 | -------------------------------------------------------------------------------- /fixtures/unary.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | 'ast_type': "UnaryOp", 11 | 'col_offset': 1, 12 | lineno: 1, 13 | op: { 14 | 'ast_type': "Invert", 15 | }, 16 | operand: { 17 | 'ast_type': "Num", 18 | 'col_offset': 2, 19 | 'end_col_offset': 3, 20 | 'end_lineno': 1, 21 | lineno: 1, 22 | 'n': 1, 23 | }, 24 | }, 25 | }, 26 | { 27 | 'ast_type': "Expr", 28 | 'col_offset': 1, 29 | lineno: 2, 30 | value: { 31 | 'ast_type': "UnaryOp", 32 | 'col_offset': 1, 33 | lineno: 2, 34 | op: { 35 | 'ast_type': "USub", 36 | }, 37 | operand: { 38 | 'ast_type': "Name", 39 | 'col_offset': 2, 40 | ctx: "Load", 41 | 'end_col_offset': 3, 42 | 'end_lineno': 2, 43 | id: "a", 44 | lineno: 2, 45 | }, 46 | }, 47 | }, 48 | { 49 | 'ast_type': "Expr", 50 | 'col_offset': 1, 51 | lineno: 3, 52 | value: { 53 | 'ast_type': "UnaryOp", 54 | 'col_offset': 1, 55 | lineno: 3, 56 | op: { 57 | 'ast_type': "UAdd", 58 | }, 59 | operand: { 60 | 'ast_type': "Name", 61 | 'col_offset': 2, 62 | ctx: "Load", 63 | 'end_col_offset': 3, 64 | 'end_lineno': 3, 65 | id: "a", 66 | lineno: 3, 67 | }, 68 | }, 69 | }, 70 | ], 71 | }, 72 | } -------------------------------------------------------------------------------- /fixtures/unicode.py: -------------------------------------------------------------------------------- 1 | "𝓏" -------------------------------------------------------------------------------- /fixtures/unicode.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "Expr", 7 | 'col_offset': 1, 8 | lineno: 1, 9 | value: { 10 | 'ast_type': "Str", 11 | 'col_offset': 1, 12 | 'end_col_offset': 4, 13 | 'end_lineno': 1, 14 | lineno: 1, 15 | 'noops_sameline': { 16 | 'ast_type': "SameLineNoops", 17 | 'col_offset': 3, 18 | 'end_col_offset': 4, 19 | 'end_lineno': 1, 20 | lineno: 1, 21 | 'noop_lines': [ 22 | { 23 | 'ast_type': "NoopSameLine", 24 | s: "", 25 | }, 26 | ], 27 | }, 28 | s: "𝓏", 29 | }, 30 | }, 31 | ], 32 | }, 33 | } -------------------------------------------------------------------------------- /fixtures/unicode.py.sem.uast: -------------------------------------------------------------------------------- 1 | { '@type': "python:Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "python:Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "python:BoxedStr", 16 | '@role': [Unannotated], 17 | 'boxed_value': { '@type': "uast:String", 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 3, 26 | line: 1, 27 | col: 4, 28 | }, 29 | }, 30 | Format: "", 31 | Value: "𝓏", 32 | }, 33 | 'noops_sameline': ~, 34 | }, 35 | }, 36 | ], 37 | } -------------------------------------------------------------------------------- /fixtures/unicode.py.uast: -------------------------------------------------------------------------------- 1 | { '@type': "Module", 2 | '@role': [File, Module], 3 | '@pos': { '@type': "uast:Positions", 4 | }, 5 | body: [ 6 | { '@type': "Expr", 7 | '@role': [Expression], 8 | '@pos': { '@type': "uast:Positions", 9 | start: { '@type': "uast:Position", 10 | offset: 0, 11 | line: 1, 12 | col: 1, 13 | }, 14 | }, 15 | value: { '@type': "Str", 16 | '@token': "𝓏", 17 | '@role': [Expression, Literal, Primitive, String], 18 | '@pos': { '@type': "uast:Positions", 19 | start: { '@type': "uast:Position", 20 | offset: 0, 21 | line: 1, 22 | col: 1, 23 | }, 24 | end: { '@type': "uast:Position", 25 | offset: 3, 26 | line: 1, 27 | col: 4, 28 | }, 29 | }, 30 | 'noops_sameline': { '@type': "SameLineNoops", 31 | '@role': [Comment], 32 | '@pos': { '@type': "uast:Positions", 33 | start: { '@type': "uast:Position", 34 | offset: 2, 35 | line: 1, 36 | col: 3, 37 | }, 38 | end: { '@type': "uast:Position", 39 | offset: 3, 40 | line: 1, 41 | col: 4, 42 | }, 43 | }, 44 | 'noop_lines': [ 45 | { '@type': "NoopSameLine", 46 | '@token': "", 47 | '@role': [Comment, Noop], 48 | '@pos': { '@type': "uast:Positions", 49 | }, 50 | }, 51 | ], 52 | }, 53 | }, 54 | }, 55 | ], 56 | } -------------------------------------------------------------------------------- /fixtures/vararg_python2.py: -------------------------------------------------------------------------------- 1 | def function6(a, *param): 2 | print "variadicArgs" 3 | 4 | def function7(a, *args, **kwargs): 5 | print "variadicAndKeywordArgs" -------------------------------------------------------------------------------- /fixtures/while.py: -------------------------------------------------------------------------------- 1 | while 3 > 2: 2 | print("surely here") 3 | break 4 | else: 5 | print("while's else") 6 | -------------------------------------------------------------------------------- /fixtures/with.py: -------------------------------------------------------------------------------- 1 | with something as s: 2 | a = s 3 | -------------------------------------------------------------------------------- /fixtures/with.py.native: -------------------------------------------------------------------------------- 1 | { 2 | 'PY3AST': { 3 | 'ast_type': "Module", 4 | body: [ 5 | { 6 | 'ast_type': "With", 7 | body: [ 8 | { 9 | 'ast_type': "Assign", 10 | 'col_offset': 5, 11 | lineno: 2, 12 | targets: [ 13 | { 14 | 'ast_type': "Name", 15 | 'col_offset': 5, 16 | ctx: "Store", 17 | 'end_col_offset': 6, 18 | 'end_lineno': 2, 19 | id: "a", 20 | lineno: 2, 21 | }, 22 | ], 23 | value: { 24 | 'ast_type': "Name", 25 | 'col_offset': 9, 26 | ctx: "Load", 27 | 'end_col_offset': 10, 28 | 'end_lineno': 2, 29 | id: "s", 30 | lineno: 2, 31 | }, 32 | }, 33 | ], 34 | 'col_offset': 1, 35 | 'end_col_offset': 5, 36 | 'end_lineno': 1, 37 | items: [ 38 | { 39 | 'ast_type': "withitem", 40 | 'context_expr': { 41 | 'ast_type': "Name", 42 | 'col_offset': 6, 43 | ctx: "Load", 44 | 'end_col_offset': 15, 45 | 'end_lineno': 1, 46 | id: "something", 47 | lineno: 1, 48 | }, 49 | 'optional_vars': { 50 | 'ast_type': "Name", 51 | 'col_offset': 19, 52 | ctx: "Store", 53 | 'end_col_offset': 20, 54 | 'end_lineno': 1, 55 | id: "s", 56 | lineno: 1, 57 | }, 58 | }, 59 | ], 60 | lineno: 1, 61 | }, 62 | ], 63 | }, 64 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/bblfsh/python-driver 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/bblfsh/sdk/v3 v3.3.1 7 | github.com/google/go-cmp v0.3.0 // indirect 8 | github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect 9 | github.com/opencontainers/runc v1.0.0-rc6 // indirect 10 | github.com/uber/jaeger-client-go v2.16.0+incompatible // indirect 11 | github.com/uber/jaeger-lib v2.0.0+incompatible // indirect 12 | golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect 13 | golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect 14 | google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610 // indirect 15 | google.golang.org/grpc v1.22.0 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /manifest.toml: -------------------------------------------------------------------------------- 1 | name = "Python" 2 | language = "python" 3 | status = "beta" 4 | features = ["ast","uast","roles"] 5 | 6 | [runtime] 7 | os = "alpine" 8 | go_version = "1.12" 9 | native_version = ["3.6.2"] 10 | -------------------------------------------------------------------------------- /native/README.md: -------------------------------------------------------------------------------- 1 | The native driver (the one producing the native AST) should be located here. 2 | 3 | See: 4 | 5 | https://doc.bblf.sh/driver/sdk.html 6 | -------------------------------------------------------------------------------- /native/dev_deps/README.md: -------------------------------------------------------------------------------- 1 | If a pydetector directory exists here, it will be installed to the driver 2 | container image instead of the one from PyPI. This way you can test pydetector 3 | features related to the driver without publishing new versions. 4 | 5 | Note that Docker doesn't allow to `ADD` symlinks so the directory 6 | must be copied, not linked. 7 | -------------------------------------------------------------------------------- /native/native.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # cd to script dir 3 | cd ${0%/*} 4 | 5 | if [ -x ".local/bin/python_driver" ] 6 | then 7 | export PATH=.local/bin:$PATH 8 | export PYTHONPATH=.local/lib/python3.6/site-packages:$PYTHONPATH 9 | python3 .local/bin/python_driver 10 | else 11 | python3 python_driver 12 | fi 13 | -------------------------------------------------------------------------------- /native/python_package/python_driver/__init__.py: -------------------------------------------------------------------------------- 1 | from python_driver.version import __version__ 2 | from python_driver.cli import get_processor_instance 3 | 4 | __prog_name__ = "python_driver" 5 | __version__ = __version__ 6 | get_processor_instance = get_processor_instance 7 | 8 | -------------------------------------------------------------------------------- /native/python_package/python_driver/__main__.py: -------------------------------------------------------------------------------- 1 | from python_driver.cli import main 2 | main() 3 | -------------------------------------------------------------------------------- /native/python_package/python_driver/cli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import signal 5 | import logging 6 | from traceback import print_exc 7 | from python_driver.processor_configs import ProcessorConfigs 8 | from python_driver.requestprocessor import RequestProcessor, InBuffer, OutBuffer 9 | from typing import Any, Tuple, Optional 10 | 11 | logging.basicConfig(level=logging.ERROR) 12 | 13 | 14 | class RequestInstantiationException(Exception): 15 | pass 16 | 17 | 18 | # Gracefully handle control c without adding another try-except on top of the loop 19 | def ctrlc_signal_handler(sgn: int, frame: Any) -> None: 20 | sys.exit(0) 21 | signal.signal(signal.SIGINT, ctrlc_signal_handler) 22 | 23 | 24 | def get_processor_instance(format_: str, custom_inbuffer: InBuffer=None, 25 | custom_outbuffer: OutBuffer=None) -> Tuple[Any, Any]: 26 | """ 27 | Get a processor instance. The class and buffers will be selected based on the 28 | python_driver.ProcessorConfigs dictionary. The input and output buffers can 29 | be overriden using the custom_inbuffer and custom_outbuffer parameters. This 30 | is mainly useful for unittesting. 31 | """ 32 | conf = ProcessorConfigs.get(format_) 33 | if not conf: 34 | raise RequestInstantiationException('No RequestProcessor found for format %s' % format_) 35 | 36 | inbuffer = custom_inbuffer if custom_inbuffer else conf['inbuffer'] 37 | outbuffer = custom_outbuffer if custom_outbuffer else conf['outbuffer'] 38 | instance = conf['class'](outbuffer) # type: ignore 39 | 40 | return instance, inbuffer 41 | 42 | 43 | def main() -> None: 44 | format_ = 'json' 45 | 46 | processor, inbuffer = get_processor_instance(format_) 47 | try: 48 | processor.process_requests(inbuffer) 49 | except UnicodeDecodeError: 50 | print_exc() 51 | print('Error while trying to decode the message, are you sure you are not ' 52 | 'using a different input format that the currently configured (%s)?' % format_) 53 | 54 | 55 | if __name__ == '__main__': 56 | main() 57 | -------------------------------------------------------------------------------- /native/python_package/python_driver/processor_configs.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from python_driver.requestprocessor import RequestProcessorJSON 3 | 4 | ProcessorConfigs = { 5 | 'json': { 6 | 'class': RequestProcessorJSON, 7 | 'inbuffer': sys.stdin, 8 | 'outbuffer': sys.stdout 9 | }, 10 | } 11 | -------------------------------------------------------------------------------- /native/python_package/python_driver/types.py: -------------------------------------------------------------------------------- 1 | from typing import Tuple, Dict, Union, Any, List 2 | 3 | Pos = Tuple[int, int] 4 | Node = Dict[str, Any] 5 | AstDict = Dict[Any, Any] 6 | VisitResult = Union[Node, List[Node]] 7 | -------------------------------------------------------------------------------- /native/python_package/python_driver/version.py: -------------------------------------------------------------------------------- 1 | __version__ = '1.1' 2 | -------------------------------------------------------------------------------- /native/python_package/requirements.txt: -------------------------------------------------------------------------------- 1 | pydetector-bblfsh==0.14.3 2 | -------------------------------------------------------------------------------- /native/python_package/setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from setuptools import setup, find_packages 4 | from codecs import open 5 | from os import path 6 | 7 | here = path.abspath(path.dirname(__file__)) 8 | 9 | description = "Python driver for the bblfsh project" 10 | 11 | main_ns = {} 12 | with open("python_driver/version.py") as ver_file: 13 | exec(ver_file.read(), main_ns) 14 | 15 | version = main_ns['__version__'] 16 | setup( 17 | name="python_driver", 18 | version=version, 19 | description=description, 20 | long_description=description, 21 | license="GPL3", 22 | test_suite="test", 23 | url="https://github.com/bblfsh/python-driver", 24 | download_url="https://github.com/bblfsh/python-driver/archive/master.zip", 25 | author="Juanjo Alvarez", 26 | author_email="juanjo@sourced.tech", 27 | packages=find_packages(exclude=["tests"]), 28 | entry_points={ 29 | "console_scripts": [ 30 | "python_driver = python_driver.cli:main" 31 | ] 32 | }, 33 | install_requires=[ 34 | "pydetector-bblfsh==0.14.3" 35 | ], 36 | classifiers=[ 37 | "Development Status :: 4 - Beta", 38 | "Environment :: Console", 39 | "Intended Audience :: Developers", 40 | "Topic :: Software Development :: Compilers", 41 | "Topic :: Software Development :: Disassemblers", 42 | "License :: OSI Approved :: GPL3 License", 43 | "Operating System :: OS Independent", 44 | "Programming Language :: Python :: 3.6" 45 | ] 46 | ) 47 | -------------------------------------------------------------------------------- /native/python_package/test/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Note: This must be run from the parent directory, not from tests 3 | coverage run --source=python_driver/,. --omit=sendmsg.py -m unittest discover 4 | coverage report 5 | -------------------------------------------------------------------------------- /native/python_package/test/data/helloworld.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | """ 4 | Very small code to test that the python_driver works. Tests for 5 | version detection and AST generation should be done on 6 | the pydetector module tests so this is keept simple 7 | so we can tests the receive/reply cycle of the main module 8 | """ 9 | 10 | 11 | def main(): 12 | files = os.listdir('.') 13 | if files: 14 | print('Yep, there are files') 15 | 16 | else: 17 | raise Exception('no files!') 18 | 19 | if __name__ == '__main__': 20 | main() 21 | -------------------------------------------------------------------------------- /native/python_package/test/integration_output.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bblfsh/python-driver/bd9ed8a91e103187a50ec13b1f8c706a3b0fa800/native/python_package/test/integration_output.json -------------------------------------------------------------------------------- /native/python_package/test/integration_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Running integration test... this usually takes about 30 seconds" 3 | cd test 2> /dev/null 4 | PY3PKGDIR=`python3 -c "import os, sys;sys.stdout.write(os.path.dirname(os.__file__))"` 5 | PY2PKGDIR=`python2 -c "import os, sys;sys.stdout.write(os.path.dirname(os.__file__))"` 6 | 7 | ./sendmsg.py $PY2PKGDIR/*.py $PY3PKGDIR/*.py|python3 -m python_driver > integration_output.json 8 | CMDOUT=$? 9 | cat integration_output.json | egrep '"status": "(error|fatal)"' > /dev/null 10 | EGREPOUT=$? 11 | 12 | if [ $CMDOUT -ne 0 ] || [ $EGREPOUT -eq 0 ] 13 | then 14 | echo "The integration test failed. Some produced JSON outputs contain fatal" \ 15 | "or error status" 16 | echo "Batch file parse output status: $CMDOUT" 17 | echo "Grep for errors output status (1 == no error or fatal matches): $EGREPOUT" 18 | exit 1 19 | else 20 | echo "Integration test completed successfully" 21 | exit 0 22 | fi 23 | -------------------------------------------------------------------------------- /native/python_package/test/sendmsg.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Script to help test and debug. It will create a babelfish message 4 | with the code of the files passed as argument and output them 5 | on stdout so you can pipe them to python_driver or the docker image like 6 | this: 7 | 8 | $ ./sendmsg.py [source_file.py]|python_driver.py 9 | 10 | Or with the Docker image: 11 | 12 | $ ./sendmsg.py [source_file.py]|docker run -it --rm python_driver:latest 13 | """ 14 | import sys 15 | import json 16 | import logging 17 | sys.path.append('../bin') 18 | 19 | 20 | def main(): 21 | filesidx = 1 22 | outbuffer = sys.stdout 23 | 24 | files = sys.argv[filesidx:] 25 | 26 | d = { 27 | 'action': 'ParseAST', 28 | 'filepath': '', 29 | 'content': '', 30 | 'language': 'python', 31 | } 32 | 33 | for f in files: 34 | content = '' 35 | logging.info(f) 36 | for encoding in ('utf_8', 'iso8859_15', 'iso8859_15', 'gb2313', 37 | 'cp1251', 'cp1252', 'cp1250', 'shift-jis', 'gbk', 'cp1256', 38 | 'iso8859-2', 'euc_jp', 'big5', 'cp874', 'euc_kr', 'iso8859_7', 39 | 'cp1255'): 40 | with open(f, encoding=encoding) as infile: 41 | try: 42 | content = infile.read() 43 | break 44 | except UnicodeDecodeError: 45 | continue 46 | 47 | d.update({ 48 | 'filepath': f, 49 | 'content': content, 50 | }) 51 | 52 | json.dump(d, sys.stdout, ensure_ascii=False) 53 | outbuffer.write('\n') 54 | outbuffer.close() 55 | 56 | 57 | if __name__ == '__main__': 58 | main() 59 | -------------------------------------------------------------------------------- /native/python_package/test/test_alpine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Alpine 3.6: 3 | time sh -c './sendmsg.py /usr/lib/python2.7/*.py | docker run -i --name python_driver --rm 1edcc008c3f6 /opt/driver/bin/native > /dev/null' 4 | -------------------------------------------------------------------------------- /native/python_package/test/test_nodocker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PY3PKGDIR=`python3 -c "import os, sys;sys.stdout.write(os.path.dirname(os.__file__))"` 3 | PY2PKGDIR=`python2 -c "import os, sys;sys.stdout.write(os.path.dirname(os.__file__))"` 4 | echo $PY3PKGDIR 5 | echo $PY2PKGDIR 6 | 7 | time sh -c "./sendmsg.py $PY2PKGDIR/*.py $PY3PKGDIR/*.py|python_driver > /dev/null" 8 | -------------------------------------------------------------------------------- /native/python_package/test/test_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | time sh -c './sendmsg.py /usr/lib/python2.7/*.py | docker run -i --name python_driver --rm python_driver_ubuntu:latest > /dev/null' 3 | -------------------------------------------------------------------------------- /native/python_package/test/typecheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # call this from the parent directory 3 | mypy --ignore-missing-imports --follow-imports silent --disallow-untyped-calls \ 4 | --disallow-untyped-defs --check-untyped-defs --warn-unused-ignores \ 5 | --strict-optional python_driver/*.py 6 | -------------------------------------------------------------------------------- /test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | 8 | "github.com/bblfsh/sdk/v3/build" 9 | ) 10 | 11 | var ( 12 | fBblfshd = flag.String("bblfshd", "", "bblfshd version to test with") 13 | fBench = flag.Bool("bench", false, "benchmark the driver") 14 | ) 15 | 16 | func main() { 17 | flag.Parse() 18 | if err := runTest("."); err != nil { 19 | fmt.Fprintln(os.Stderr, err) 20 | os.Exit(1) 21 | } 22 | } 23 | 24 | func runTest(root string) error { 25 | args := flag.Args() 26 | image := "" 27 | if len(args) != 0 { 28 | image = args[0] 29 | } 30 | d, err := build.NewDriver(root) 31 | if err != nil { 32 | return err 33 | } 34 | return d.Test(*fBblfshd, image, *fBench) 35 | } 36 | -------------------------------------------------------------------------------- /update.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | 8 | "github.com/bblfsh/sdk/v3/build" 9 | ) 10 | 11 | func main() { 12 | flag.Parse() 13 | if err := runUpdate("."); err != nil { 14 | fmt.Fprintln(os.Stderr, err) 15 | os.Exit(1) 16 | } 17 | } 18 | 19 | func runUpdate(root string) error { 20 | return build.UpdateSDK(root, &build.UpdateOptions{ 21 | Notice: fmt.Printf, 22 | Warning: fmt.Printf, 23 | }) 24 | } 25 | --------------------------------------------------------------------------------