Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "from importlib.util import module_from_spec, spec_from_loader, LazyLoader\n",
- "from importlib.machinery import SourceFileLoader, FileFinder\n",
- "from IPython import display\n",
- "from os import curdir\n",
- "from os.path import exists, extsep, sep\n",
- "import nbformat, random, sys"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "class TypeFinder(object):\n",
- " def find_spec(self, name, paths, target=None):\n",
- " \"\"\"Search paths for files matching `<name>.pyi`.\n",
- " \"\"\"\n",
- " for path in ['/Users/tonyfast/typeshed/third_party/2and3/']:\n",
- " print(path)\n",
- " path = sep.join([path, *name.split('.')])\n",
- " path = (\n",
- " sep.join([path, '__init__.pyi']) \n",
- " if exists(sep.join([path, '__init__.pyi'])) \n",
- " else extsep.join([path, 'pyi']))\n",
- " print(name, path)\n",
- " spec = spec_from_loader(name, SourceFileLoader(name, path))\n",
- " return spec\n",
- " return None"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "finder = TypeFinder()\n",
- "hook = FileFinder.path_hook((TypeFinder, ['.pyi']))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "sys.meta_path.insert(0, finder)\n",
- "sys.path_hooks.insert(0, hook)\n",
- "sys.path_importer_cache.clear()\n",
- "for k in list(sys.modules.keys()): \n",
- " if k.startswith('requests'): del sys.modules[k]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests /Users/tonyfast/typeshed/third_party/2and3//requests/__init__.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.models /Users/tonyfast/typeshed/third_party/2and3//requests/models.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.hooks /Users/tonyfast/typeshed/third_party/2and3//requests/hooks.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.structures /Users/tonyfast/typeshed/third_party/2and3//requests/structures.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.auth /Users/tonyfast/typeshed/third_party/2and3//requests/auth.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.compat /Users/tonyfast/typeshed/third_party/2and3//requests/compat.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.cookies /Users/tonyfast/typeshed/third_party/2and3//requests/cookies.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.utils /Users/tonyfast/typeshed/third_party/2and3//requests/utils.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.exceptions /Users/tonyfast/typeshed/third_party/2and3//requests/exceptions.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages /Users/tonyfast/typeshed/third_party/2and3//requests/packages/__init__.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3 /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/__init__.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.connectionpool /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/connectionpool.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.exceptions /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/exceptions.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.packages /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/packages/__init__.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.packages.ssl_match_hostname /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.connection /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/connection.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/__init__.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util.connection /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/connection.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util.request /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/request.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util.response /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/response.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util.ssl_ /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/ssl_.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util.timeout /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/timeout.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util.retry /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/retry.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.util.url /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/url.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.request /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/request.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.response /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/response.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3._collections /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/_collections.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.filepost /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/filepost.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.fields /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/fields.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.packages.urllib3.poolmanager /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/poolmanager.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.status_codes /Users/tonyfast/typeshed/third_party/2and3//requests/status_codes.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.api /Users/tonyfast/typeshed/third_party/2and3//requests/api.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.sessions /Users/tonyfast/typeshed/third_party/2and3//requests/sessions.pyi\n",
- "/Users/tonyfast/typeshed/third_party/2and3/\n",
- "requests.adapters /Users/tonyfast/typeshed/third_party/2and3//requests/adapters.pyi\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "'/Users/tonyfast/typeshed/third_party/2and3//requests/__init__.pyi'"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "import requests\n",
- "requests.__file__"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'params': typing.Union[typing.Mapping[typing.Union[str, bytes, int, float], typing.Union[str, bytes, int, float, typing.Iterable[typing.Union[str, bytes, int, float]]]], str, bytes, typing.Tuple[typing.Union[str, bytes, int, float], typing.Union[str, bytes, int, float, typing.Iterable[typing.Union[str, bytes, int, float]]]], typing.Mapping[str, typing.Union[str, bytes, int, float, typing.Iterable[typing.Union[str, bytes, int, float]]]], typing.Mapping[bytes, typing.Union[str, bytes, int, float, typing.Iterable[typing.Union[str, bytes, int, float]]]], typing.Mapping[int, typing.Union[str, bytes, int, float, typing.Iterable[typing.Union[str, bytes, int, float]]]], typing.Mapping[float, typing.Union[str, bytes, int, float, typing.Iterable[typing.Union[str, bytes, int, float]]]], NoneType],\n",
- " 'return': requests.models.Response,\n",
- " 'url': typing.Union[str, bytes]}"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "requests.get.__annotations__"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'data': typing.Union[NoneType, bytes, typing.MutableMapping[str, str], typing.IO],\n",
- " 'json': typing.Union[typing.MutableMapping, NoneType],\n",
- " 'return': requests.models.Response,\n",
- " 'url': str}"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "requests.post.__annotations__"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "artifacts": [
- ".py"
- ],
- "kernelspec": {
- "display_name": "Python 3",
- "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.5.3"
- },
- "nbconvert": {
- "script": {}
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement