/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
dis__bytecode__is_empty_function.py
30 строк
648 B
gil9red
Refactoring. Using black code style
24 июн 2023, 17:46
24 июн 2023, 17:46
e8b40a2
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" import dis # https://ru.stackoverflow.com/a/767523/201445 def check_is_empty_function(function): instructions = dis.get_instructions(function) instr = next(instructions, None) if instr is None or instr.opname != "LOAD_CONST" or instr.argrepr != "None": return False instr = next(instructions, None) return instr and (instr.opname == "RETURN_VALUE") if __name__ == "__main__": def foo(): pass def foo2(): return 1 print("Empty:", check_is_empty_function(foo)) print("Empty:", check_is_empty_function(foo2))