Python

Frontend CLI Args #

The following arguments are specific to the pysrc2cpg frontend.

ArgDescriptionTypeExampleHidden
venvDirVirtual environment directory. If not absolute it is interpreted relative to input-dirString--venvDir "/some/path/venv/"true
venvDirsVirtual environment directories. If not absolute it is interpreted relative to input-dirList<String>--venvDirs "/some/path/venv1/, /some/path/venv2"false
ignoreVenvDirSpecifies whether venv-dir is ignored. Default to true---ignoreVenvDirfalse
ignore-pathsIgnores specified paths from analysis. If not absolute it is interpreted relative to input-dirList<String>--ignore-paths "/path/to/ignore1, /path/to/ignore2"false
ignore-dir-namesExclude all files where the relative path from input-dir contains at least one of the names specifiedList<String>--ignore-dir-names "rel/path/ignore1, rel/path/ignore2"true
no-dummyTypesDisables the generation of dummy types during type propagation---no-dummyTypestrue
type-prop-iterationsMaximum iterations of type propagationInteger--type-prop-iterations 2true

Calls #

The section below shows how different call ASTs are modelled in Python.

The following is a simple call in Python

class Foo:
  def bar(self, param1, param2, param3):
    pass 

  def baz():
    self.bar("1", 2, "3")

Image of a simple call AST for a function in the same class in Python The structure of the call AST:

CallNode
├── Receiver: self.bar
├── MethodName: bar
└── Arguments
    ├── Argument[-1]:self.bar 
    ├── Argument[0]: self 
    ├── Argument[1]: param1
    ├── Argument[2]: param2
    └── Argument[3]: param3

Simple calls are modelled slightly different in dynamic languages (such as Python) when compared to static languages. In dynamic languages arg[0] is no longer the receiver of the call, but instead is the object that holds the property which is the receiver of the call. There is also a 5th argument introduced, which is arg[-1]. In Python, the self argument is the same as the this argument in other languages.

The following is a member call in Python

class Foo:
  def bar(self):
    bazObj = Baz()
    bazObj.baz("1", 2, "3")

class Baz:
  def baz(self, param1, param2, param3):
    pass

Image of a simple call AST for a function in a different class in Python The structure of the call AST is mostly the same as for a simple call, with the receiver of the call now just being Baz.baz instead of self.bar.