{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "30ae0a6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
    "# Introspection:\n",
    "#\n",
    "#      is the ability of an object to know about its own attributes at runtime.\n",
    "#\n",
    "# https://realpython.com/primer-on-python-decorators/\n",
    "# (In chapter \"Who are you really?\")\n",
    "# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8c22033e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function sum(iterable, /, start=0)>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A Python function knows it's own name and documentation:\n",
    "\n",
    "sum                   # Function header"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "76c6d141",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'sum'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum.__name__          # Function name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2e7e996a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sum in module builtins:\n",
      "\n",
      "sum(iterable, /, start=0)\n",
      "    Return the sum of a 'start' value (default: 0) plus an iterable of numbers\n",
      "    \n",
      "    When the iterable is empty, return the start value.\n",
      "    This function is intended specifically for use with numeric values and may\n",
      "    reject non-numeric types.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(sum)             # Documentation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "6c5c21cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Whee!\n"
     ]
    }
   ],
   "source": [
    "# Introspection on user defined functions\n",
    "\n",
    "def say_whee():\n",
    "    print(\"Whee!\")\n",
    "    \n",
    "say_whee()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "652d50aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function __main__.say_whee()>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "say_whee"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1182cd20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'say_whee'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "say_whee.__name__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5ab0d9f6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function say_whee in module __main__:\n",
      "\n",
      "say_whee()\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(say_whee)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f9b70735",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Whee!\n",
      "Whee!\n"
     ]
    }
   ],
   "source": [
    "import functools\n",
    "    \n",
    "def do_twice(func):\n",
    "    # Add this to help Python\n",
    "    @functools.wraps(func)\n",
    "    \n",
    "    def wrapper_do_twice(*args, **kwargs):\n",
    "        func(*args, **kwargs)\n",
    "        func(*args, **kwargs)\n",
    "    return wrapper_do_twice\n",
    "\n",
    "@do_twice\n",
    "def say_whee():\n",
    "    print(\"Whee!\")\n",
    "\n",
    "say_whee()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "18a06cbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function __main__.say_whee()>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "say_whee"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "5a1af180",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'say_whee'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "say_whee.__name__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e454f571",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function say_whee in module __main__:\n",
      "\n",
      "say_whee()\n",
      "    # Add this to help Python\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(say_whee)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1de38444",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "362a24a7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
