Giter Club home page Giter Club logo

libsa4py's People

Contributors

gousiosg avatar mir-am avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

libsa4py's Issues

Type-checking source code files after processing in the pipeline

In the pipeline, an optional argument can be added to type-check processed source code file.
Here are the required changes:

  • Add the field tc to modules in JSON files. Has either True or False value.
  • Add the argument --tc to the process command.
  • Add helper classes to a new module, type-check.py.
  • Update the Pipeline class to run the type-checker (e.g. mypy)

Extracting fully qualified type names

Currently, type names are extracted from its slot without considering the module from which it's imported. For instance:

from typing import List

x: List[int] = []

The type of x should be extracted as typing.List[int].

Add qualified names for classes

To uniquely identify classes within a file, a qualified name is required.
To add this feature, a new field, i.e., q_name, will be added to both class representation and the final JSON output.

Add type annotations coverage for processed projects

  • Add type annotations coverage for each processed source code file (i.e. a module)
  • Add type annotations coverage for each processed project, i.e. a JSON field type_annot_cove
  • Update the docs in the JSONOutput.md file accordingly

Improvements to the type propagation across a source code file

It is expected to see all usages of a typed variable in a file to have its types. See the unit test test_propagated_types_file and the file exp_outputs/propagated_types.py in tests branch.

The TypeAdder class in cst_transformations.py should be improved.

`TypeApplier` fails to annotate consecutive identically named variables in separate functions

MRE:

import textwrap
from pprint import pprint

import libcst
from libcst import metadata

from libsa4py.cst_extractor import Extractor
from libsa4py.cst_transformers import TypeAnnotationRemover, TypeApplier


mod = libcst.parse_module(
    textwrap.dedent(
        """
def f():
    x: int = 10

def g():
    x: str = "Hello World"
"""
    )
)
mod_annotations = Extractor.extract(mod.code).to_dict()
pprint(mod_annotations["funcs"])

annoless = mod.visit(TypeAnnotationRemover())
annotated = metadata.MetadataWrapper(annoless, unsafe_skip_copy=True).visit(
    TypeApplier(mod_annotations, apply_nlp=False)
)
new_annotations = Extractor.extract(annotated.code).to_dict()
pprint(new_annotations["funcs"])

Output:

[{'docstring': {'func': None, 'long_descr': None, 'ret': None},
  'fn_lc': ((2, 0), (3, 24)),
  'fn_var_ln': {'x': ((3, 4), (3, 5))},
  'fn_var_occur': {'x': [['x', 'builtins', 'int']]},
  'name': 'f',
  'params': {},
  'params_descr': {},
  'params_occur': {},
  'q_name': 'f',
  'ret_exprs': [],
  'ret_type': '',
  'variables': {'x': 'builtins.int'}},
 {'docstring': {'func': None, 'long_descr': None, 'ret': None},
  'fn_lc': ((5, 0), (6, 35)),
  'fn_var_ln': {'x': ((6, 4), (6, 5))},
  'fn_var_occur': {'x': [['x', 'builtins', 'str']]},
  'name': 'g',
  'params': {},
  'params_descr': {},
  'params_occur': {},
  'q_name': 'g',
  'ret_exprs': [],
  'ret_type': '',
  'variables': {'x': 'builtins.str'}}]
[{'docstring': {'func': None, 'long_descr': None, 'ret': None},
  'fn_lc': ((3, 0), (4, 24)),
  'fn_var_ln': {'x': ((4, 4), (4, 5))},
  'fn_var_occur': {'x': [['x', 'builtins', 'int']]},
  'name': 'f',
  'params': {},
  'params_descr': {},
  'params_occur': {},
  'q_name': 'f',
  'ret_exprs': [],
  'ret_type': '',
  'variables': {'x': 'builtins.int'}},
 {'docstring': {'func': None, 'long_descr': None, 'ret': None},
  'fn_lc': ((6, 0), (7, 21)),
  'fn_var_ln': {'x': ((7, 4), (7, 5))},
  'fn_var_occur': {'x': []},
  'name': 'g',
  'params': {},
  'params_descr': {},
  'params_occur': {},
  'q_name': 'g',
  'ret_exprs': [],
  'ret_type': '',
  'variables': {'x': ''}}]

Note that the second dict for the function g does not contain a type for the variable x, despite the original clearly finding the anntotation builtins.str

A tentative fix that I applied was to add the following to the leave_FunctionDef method of TypeApplier, but I am unsure of its correctness.

self.last_visited_assign_t_name = None
self.last_visited_assign_t_count = 0

Some resetting of self.last_visited_assign_t_name seems to be in order, or perhaps this should be assigned a fully qualified name instead of just the variable's name.

I hope this helps (or that I have made a mistake :) )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.