Skip to content

Crash if func_name is None #18

@paulschreiber

Description

@paulschreiber

Description

When running code like so:

>>> from staticfg import CFGBuilder
>>> cfg = CFGBuilder().build_from_file('blah.py', './blah.py')

The CFGBuilder crashes if func_name is None.

  File "/opt/homebrew/lib/python3.12/site-packages/staticfg/builder.py", line 275, in visit_Call
    func_name = visit_func(func)
                ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/staticfg/builder.py", line 267, in visit_func
    func_name += "." + node.attr
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'

The relevant code:

    def visit_Call(self, node):
        def visit_func(node):
            if type(node) == ast.Name:
                return node.id
            elif type(node) == ast.Attribute:
                # Recursion on series of calls to attributes.
                func_name = visit_func(node.value)
                func_name += "." + node.attr
                return func_name

I can work around this like so:

            elif type(node) == ast.Attribute:
                # Recursion on series of calls to attributes.
                func_name = visit_func(node.value)
                if func_name is None:
                    func_name = ""
                func_name += "." + node.attr
                return func_name

but that might just be masking the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions