Advertisement
Guest User

Untitled

a guest
May 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.42 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 3,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": [
  11. "from importlib.util import module_from_spec, spec_from_loader, LazyLoader\n",
  12. "from importlib.machinery import SourceFileLoader, FileFinder\n",
  13. "from IPython import display\n",
  14. "from os import curdir\n",
  15. "from os.path import exists, extsep, sep\n",
  16. "import nbformat, random, sys"
  17. ]
  18. },
  19. {
  20. "cell_type": "code",
  21. "execution_count": 4,
  22. "metadata": {
  23. "collapsed": true
  24. },
  25. "outputs": [],
  26. "source": [
  27. "class TypeFinder(object):\n",
  28. " def find_spec(self, name, paths, target=None):\n",
  29. " \"\"\"Search paths for files matching `<name>.pyi`.\n",
  30. " \"\"\"\n",
  31. " for path in ['/Users/tonyfast/typeshed/third_party/2and3/']:\n",
  32. " print(path)\n",
  33. " path = sep.join([path, *name.split('.')])\n",
  34. " path = (\n",
  35. " sep.join([path, '__init__.pyi']) \n",
  36. " if exists(sep.join([path, '__init__.pyi'])) \n",
  37. " else extsep.join([path, 'pyi']))\n",
  38. " print(name, path)\n",
  39. " spec = spec_from_loader(name, SourceFileLoader(name, path))\n",
  40. " return spec\n",
  41. " return None"
  42. ]
  43. },
  44. {
  45. "cell_type": "code",
  46. "execution_count": 5,
  47. "metadata": {
  48. "collapsed": true
  49. },
  50. "outputs": [],
  51. "source": [
  52. "finder = TypeFinder()\n",
  53. "hook = FileFinder.path_hook((TypeFinder, ['.pyi']))"
  54. ]
  55. },
  56. {
  57. "cell_type": "code",
  58. "execution_count": 6,
  59. "metadata": {},
  60. "outputs": [],
  61. "source": [
  62. "sys.meta_path.insert(0, finder)\n",
  63. "sys.path_hooks.insert(0, hook)\n",
  64. "sys.path_importer_cache.clear()\n",
  65. "for k in list(sys.modules.keys()): \n",
  66. " if k.startswith('requests'): del sys.modules[k]"
  67. ]
  68. },
  69. {
  70. "cell_type": "code",
  71. "execution_count": 7,
  72. "metadata": {},
  73. "outputs": [
  74. {
  75. "name": "stdout",
  76. "output_type": "stream",
  77. "text": [
  78. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  79. "requests /Users/tonyfast/typeshed/third_party/2and3//requests/__init__.pyi\n",
  80. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  81. "requests.models /Users/tonyfast/typeshed/third_party/2and3//requests/models.pyi\n",
  82. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  83. "requests.hooks /Users/tonyfast/typeshed/third_party/2and3//requests/hooks.pyi\n",
  84. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  85. "requests.structures /Users/tonyfast/typeshed/third_party/2and3//requests/structures.pyi\n",
  86. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  87. "requests.auth /Users/tonyfast/typeshed/third_party/2and3//requests/auth.pyi\n",
  88. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  89. "requests.compat /Users/tonyfast/typeshed/third_party/2and3//requests/compat.pyi\n",
  90. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  91. "requests.cookies /Users/tonyfast/typeshed/third_party/2and3//requests/cookies.pyi\n",
  92. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  93. "requests.utils /Users/tonyfast/typeshed/third_party/2and3//requests/utils.pyi\n",
  94. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  95. "requests.exceptions /Users/tonyfast/typeshed/third_party/2and3//requests/exceptions.pyi\n",
  96. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  97. "requests.packages /Users/tonyfast/typeshed/third_party/2and3//requests/packages/__init__.pyi\n",
  98. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  99. "requests.packages.urllib3 /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/__init__.pyi\n",
  100. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  101. "requests.packages.urllib3.connectionpool /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/connectionpool.pyi\n",
  102. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  103. "requests.packages.urllib3.exceptions /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/exceptions.pyi\n",
  104. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  105. "requests.packages.urllib3.packages /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/packages/__init__.pyi\n",
  106. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  107. "requests.packages.urllib3.packages.ssl_match_hostname /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/packages/ssl_match_hostname/__init__.pyi\n",
  108. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  109. "requests.packages.urllib3.connection /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/connection.pyi\n",
  110. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  111. "requests.packages.urllib3.util /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/__init__.pyi\n",
  112. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  113. "requests.packages.urllib3.util.connection /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/connection.pyi\n",
  114. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  115. "requests.packages.urllib3.util.request /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/request.pyi\n",
  116. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  117. "requests.packages.urllib3.util.response /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/response.pyi\n",
  118. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  119. "requests.packages.urllib3.util.ssl_ /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/ssl_.pyi\n",
  120. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  121. "requests.packages.urllib3.util.timeout /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/timeout.pyi\n",
  122. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  123. "requests.packages.urllib3.util.retry /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/retry.pyi\n",
  124. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  125. "requests.packages.urllib3.util.url /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/util/url.pyi\n",
  126. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  127. "requests.packages.urllib3.request /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/request.pyi\n",
  128. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  129. "requests.packages.urllib3.response /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/response.pyi\n",
  130. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  131. "requests.packages.urllib3._collections /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/_collections.pyi\n",
  132. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  133. "requests.packages.urllib3.filepost /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/filepost.pyi\n",
  134. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  135. "requests.packages.urllib3.fields /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/fields.pyi\n",
  136. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  137. "requests.packages.urllib3.poolmanager /Users/tonyfast/typeshed/third_party/2and3//requests/packages/urllib3/poolmanager.pyi\n",
  138. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  139. "requests.status_codes /Users/tonyfast/typeshed/third_party/2and3//requests/status_codes.pyi\n",
  140. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  141. "requests.api /Users/tonyfast/typeshed/third_party/2and3//requests/api.pyi\n",
  142. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  143. "requests.sessions /Users/tonyfast/typeshed/third_party/2and3//requests/sessions.pyi\n",
  144. "/Users/tonyfast/typeshed/third_party/2and3/\n",
  145. "requests.adapters /Users/tonyfast/typeshed/third_party/2and3//requests/adapters.pyi\n"
  146. ]
  147. },
  148. {
  149. "data": {
  150. "text/plain": [
  151. "'/Users/tonyfast/typeshed/third_party/2and3//requests/__init__.pyi'"
  152. ]
  153. },
  154. "execution_count": 7,
  155. "metadata": {},
  156. "output_type": "execute_result"
  157. }
  158. ],
  159. "source": [
  160. "import requests\n",
  161. "requests.__file__"
  162. ]
  163. },
  164. {
  165. "cell_type": "code",
  166. "execution_count": 8,
  167. "metadata": {},
  168. "outputs": [
  169. {
  170. "data": {
  171. "text/plain": [
  172. "{'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",
  173. " 'return': requests.models.Response,\n",
  174. " 'url': typing.Union[str, bytes]}"
  175. ]
  176. },
  177. "execution_count": 8,
  178. "metadata": {},
  179. "output_type": "execute_result"
  180. }
  181. ],
  182. "source": [
  183. "requests.get.__annotations__"
  184. ]
  185. },
  186. {
  187. "cell_type": "code",
  188. "execution_count": 10,
  189. "metadata": {},
  190. "outputs": [
  191. {
  192. "data": {
  193. "text/plain": [
  194. "{'data': typing.Union[NoneType, bytes, typing.MutableMapping[str, str], typing.IO],\n",
  195. " 'json': typing.Union[typing.MutableMapping, NoneType],\n",
  196. " 'return': requests.models.Response,\n",
  197. " 'url': str}"
  198. ]
  199. },
  200. "execution_count": 10,
  201. "metadata": {},
  202. "output_type": "execute_result"
  203. }
  204. ],
  205. "source": [
  206. "requests.post.__annotations__"
  207. ]
  208. },
  209. {
  210. "cell_type": "code",
  211. "execution_count": null,
  212. "metadata": {
  213. "collapsed": true
  214. },
  215. "outputs": [],
  216. "source": []
  217. }
  218. ],
  219. "metadata": {
  220. "artifacts": [
  221. ".py"
  222. ],
  223. "kernelspec": {
  224. "display_name": "Python 3",
  225. "language": "python",
  226. "name": "python3"
  227. },
  228. "language_info": {
  229. "codemirror_mode": {
  230. "name": "ipython",
  231. "version": 3
  232. },
  233. "file_extension": ".py",
  234. "mimetype": "text/x-python",
  235. "name": "python",
  236. "nbconvert_exporter": "python",
  237. "pygments_lexer": "ipython3",
  238. "version": "3.5.3"
  239. },
  240. "nbconvert": {
  241. "script": {}
  242. }
  243. },
  244. "nbformat": 4,
  245. "nbformat_minor": 2
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement