<filename>tests/myproject.py
# stdlib
import builtins
import sys
from typing import Any, Dict

__all__ = ["baz", "fizbuzz"]

if sys.version_info >= (3, 7):
	# stdlib
	import dataclasses

	@dataclasses.dataclass()
	class A:
		"""
		My Dataclass
		"""

	__all__.append('A')


def foo():

	def bar():
		"""
		A locally defined function.
		"""

	return bar


baz = foo()
# fizbuzz = foo()


def create_fizbuzz():
	# Based on the dataclass module from CPython
	locals = {"BUILTINS": builtins}  # noqa: A001  # pylint: disable=redefined-builtin
	local_vars = ", ".join(locals.keys())

	txt = f" def fizbuzz(): pass"
	txt = f"def __create_fn__({local_vars}):\n{txt}\n return fizbuzz"

	ns: Dict[str, Any] = {}
	exec(txt, None, ns)
	return ns["__create_fn__"](**locals)


fizbuzz = create_fizbuzz()
fizbuzz.__qualname__ = "fizbuzz"
fizbuzz.__doc__ = "A locally defined function."

<filename>tests/myproject.py
# stdlib
import builtins
import sys
from typing import Any, Dict

__all__ = ["baz", "fizbuzz"]

if sys.version_info >= (3, 7):
	# stdlib
	import dataclasses

	@dataclasses.dataclass()
	class A:
		"""
		My Dataclass
		"""

	__all__.append('A')


def foo():

	def bar():
		"""
		A locally defined function.
		"""

	return bar


baz = foo()
# fizbuzz = foo()


def create_fizbuzz():
	# Based on the dataclass module from CPython
	locals = {"BUILTINS": builtins}  # noqa: A001  # pylint: disable=redefined-builtin
	local_vars = ", ".join(locals.keys())

	txt = f" def fizbuzz(): pass"
	txt = f"def __create_fn__({local_vars}):\n{txt}\n return fizbuzz"

	ns: Dict[str, Any] = {}
	exec(txt, None, ns)
	return ns["__create_fn__"](**locals)


fizbuzz = create_fizbuzz()
fizbuzz.__qualname__ = "fizbuzz"
fizbuzz.__doc__ = "A locally defined function."

# stdlib # stdlib My Dataclass A locally defined function. # fizbuzz = foo() # Based on the dataclass module from CPython # noqa: A001  # pylint: disable=redefined-builtin