Over Complicating Hello World

I came accross this TikTok video recently, where the presenter shows how to make an “Object Oriented” Hello World program. It made me laugh so much, I thought I would try my own hello world program.

This is my solution, which uses the Python ast module to inspect the script looking for functions to use in the hello world message.

#!/usr/bin/env python3

import ast

def Hello():
    ...

def World():
    ...

class Visitor(ast.NodeVisitor):
    def __init__(self):
        self.functions: list[str] = []

    def visit_FunctionDef(self, node: ast.AST):
        if '_' not in node.name and node.name[0].isupper():
            self.functions.append(node.name)
        self.generic_visit(node)

def _say_hi():
    with open(__file__, 'r') as fd:
        code = fd.read()
    node = ast.parse(code)
    visitor = Visitor()
    visitor.visit(node)
    print(' '.join(visitor.functions))

if __name__ == '__main__':
    _say_hi()