{ "info": { "author": "Allen Barker", "author_email": "Allen.L.Barker@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Utilities" ], "description": "\nstrip-hints\n===========\n\nThis package provides a command-line command and a corresponding importable\nfunction that strips type hints from Python code files. The stripping process\nleaves runnable code, assuming the rest of the code is runnable in the\ninterpreter version. The program tries to make as few changes as possible to\nthe processed code so that line and column numbers in error messages for the\nprocessed code file also correspond to those for the original code file. In\nmost cases, with the default options, both the line and column numbers are\npreserved.\n\nThe stripping operation can be used as a preprocessor to allow the new type\nhint syntax to be used in Python 2. The main intended application is for code\nwhich is being developed in Python 3 but which needs backward compatibility to\nPython 2.\n\nThis project also contains a general-purpose class named ``TokenList`` which\nallows lists of Python tokens to be operated on using an interface similar to\nthat of Python strings. In particular, a ``split`` method is used for much of\nthe processing in stripping hints. This module could be useful for people\ndoing other things with Python at the token level.\n\nInstalling the code\n-------------------\n\nTo install from PyPI using pip use::\n\n pip install strip-hints\n\nTo install the most-recent development version first clone or download the\nproject from `this GitHub repository\n`_.\n\nRunning the code\n----------------\n\nAfter installing with pip you can run the console script ``strip-hints``::\n\n strip-hints your_file_with_hints.py\n\nThe code runs with Python 2 and Python 3. The processed code is written to\nstdout. The AST checker that is run on the processed code checks the code\nagainst whatever version of Python the script is run with.\n\nThe command-line options are as follows:\n\n``--to-empty``\n Map removed code to empty strings rather than spaces. This is easier to read,\n but does not preserve columns. Default is false.\n\n``--no-ast``\n Do not parse the resulting code with the Python ``ast`` module to check it.\n Default is false.\n\n``--no-colon-move``\n Do not move colons to fix line breaks that occur in the hints for the\n function return type. Default is false.\n\n``--only-assigns-and-defs``\n Only strip annotated assignments and standalone type definitions, keeping\n function signature annotations. Python 3.5 and earlier do not implement\n these; they first appeared in Python 3.6. The default is false.\n\n``--only-test-for-changes``\n Only test if any changes would be made. If any stripping would be done then\n it prints ``True`` and exits with code 0. Otherwise it prints ``False`` and\n exits with code 1.\n\nIf you are using the development repo you can just run the file\n``strip_hints.py`` in the ``bin`` directory of the repo::\n\n python strip_hints.py your_file_with_hints.py\n\nAlternately, you can install the development repo with pip::\n\n cd \n pip install . # use -e for development mode\n\nAutomatically running on import\n-------------------------------\n\nA function can be called to automatically strip the type hints from all future\nimports that are in the same directory as the calling module. For a package\nthe function call can be placed in ``__init__.py``, for example.\n\nThe function can be called as follows, with options set as desired (these\nare the default settings)::\n\n from strip_hints import strip_on_import\n strip_on_import(__file__, to_empty=False, no_ast=False, no_colon_move=False,\n only_assigns_and_defs=False, py3_also=False)\n\nBy default Python 3 code is ignored unless ``py3_also`` is set. The first\nargument is the file path of the calling module.\n\nCalling from a Python program\n-----------------------------\n\nTo strip the comments from a source file from within a Python program,\nreturning a string containing the code, the functional interface is as follows.\nThe option settings here are the default values::\n\n from strip_hints import strip_file_to_string\n code_string = strip_file_to_string(filename, to_empty=False, no_ast=False,\n no_colon_move=False, only_assigns_and_defs=False,\n only_test_for_changes=False)\n\nIf ``only_test_for_changes`` is true then a boolean is returned which is true iff\nsome changes would be made.\n\nLimitations\n-----------\n\nThe program currently does not handle line breaks in annotated assignments when\nthe code that is removed (the type specification) contains a line break that\nwas formerly nested inside parens, brackets, or braces. The program detects\nthe situation and raises an exception. As a workaround if necessary, using an\nexplicit backslash line continuation seems to work.\n\nThe same situation in the return type specification is handled by moving the\ncolon token up to the line with the closing paren. The situation does not\noccur inside parameter lists because they are always nested inside parentheses.\n\nThe program currently only handles simple annotated expressions (e.g.,\nit handles ``my_class.x: int`` and ``my_list[2]: int`` but not ``(x): int``).\n\nHow it works\n------------\n\nRather than doing a full, roundtrip parse, this module works on the tokens\nproduced by the Python tokenizer. Locating the relevant parts to remove is a\nmuch simpler task than parsing a program in full generality. This allows an ad\nhoc approach based on splitting groups of tokens, taking into account the\nnesting level of the tokens to potentially split on. Nesting level is based on\nthe level count inside parentheses, brackets, and curly braces.\n\n* The tokenizer for Python 2 also works on code with type hints, as introduced in\n Python 3.\n\n* Type hints can be removed, in most cases, simply by turning some tokens into\n whitespace. This preserves line and column numbers in the files. Whiting-out a\n section of code with a non-nested line break either raises an exception or\n performs a slightly more-complicated transformation.\n\nIn the most basic usage the sequence of tokens originally read from the file is\nnever changed; some tokens just have their string values set to whitespace or\nto a pound sign before the untokenize operation.\n\nThe gory details of the algorithm are discussed in the docstring for\n``strip_hints_main.py``. The method should be fairly robust.\n\nBugs\n----\n\nThe code has been run on the Mypy source code and on some other examples, with\nthe results parsed into ASTs and also visually inspected via diff. Some edge\ncases may well remain to cause problems. There is a Bash script in the ``test``\ndirectory which runs the program on files and shows the diffs.\n\nPossible enhancements\n---------------------\n\n* Formal tests.\n \n* Better argument-handling, help, etc. with argparse.\n\n* Generate stubs for Python 2. (Unless the annotated files themselves will work as\n stubs; I haven't checked.)\n\n* Better error warnings (raising exceptions with messages rather than just failing\n assertions in some places).\n\n* More command options.\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/abarker/strip-hints", "keywords": "type", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "strip-hints", "package_url": "https://pypi.org/project/strip-hints/", "platform": "", "project_url": "https://pypi.org/project/strip-hints/", "project_urls": { "Homepage": "https://github.com/abarker/strip-hints" }, "release_url": "https://pypi.org/project/strip-hints/0.1.7/", "requires_dist": null, "requires_python": "", "summary": "Function and command-line program to strip Python type hints.", "version": "0.1.7" }, "last_serial": 5591700, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "e2e58ab3d9a79a4bef4cdae289ce9a2b", "sha256": "9678eea4e084204e88833cab0389979c05b56ce2e8d5e886605f901606c05521" }, "downloads": -1, "filename": "strip-hints-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e2e58ab3d9a79a4bef4cdae289ce9a2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14752, "upload_time": "2017-09-29T04:24:16", "url": "https://files.pythonhosted.org/packages/31/1b/4eaee3e8b2e3dca78fd85b021ee92ec87a890e5a26c9899e018e87730a7d/strip-hints-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "464abc15a8aa280cc946f7926f21af70", "sha256": "05026a8282c4649b67a74f41f9ad1fcb492e8912568b36a0f366309cf757e170" }, "downloads": -1, "filename": "strip-hints-0.1.1.tar.gz", "has_sig": false, "md5_digest": "464abc15a8aa280cc946f7926f21af70", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18320, "upload_time": "2017-10-04T01:36:43", "url": "https://files.pythonhosted.org/packages/2d/cd/c3775cd4171d24137b8c2faa34accea0e81734997f2ab47b43122716bf52/strip-hints-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "1cf1c44fb9b6c976093dec2555780851", "sha256": "4ce406f3ec242012589a5bfdd802bd5b0685f4436f431fcef02b138abebe7da2" }, "downloads": -1, "filename": "strip-hints-0.1.2.tar.gz", "has_sig": false, "md5_digest": "1cf1c44fb9b6c976093dec2555780851", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18596, "upload_time": "2019-01-16T22:52:52", "url": "https://files.pythonhosted.org/packages/88/34/85dc7a7fb0322a1d9427fb97b31b6ceb19503914f301c6d733791e16ff75/strip-hints-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "90270fc19b2c52262903d23008d5b017", "sha256": "2c5bea52cbf5d8a66c59b9a98bdbc5012cf40f9945389f72a3617f80b20c8512" }, "downloads": -1, "filename": "strip-hints-0.1.3.tar.gz", "has_sig": false, "md5_digest": "90270fc19b2c52262903d23008d5b017", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18992, "upload_time": "2019-01-18T04:24:00", "url": "https://files.pythonhosted.org/packages/36/42/c4c2bf55f3fc1c99df456f107f5bb8e2ae5a9e006055c030d94da49fa2a8/strip-hints-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "c9c77236bfe1127a12e1411c22fd0757", "sha256": "25a9cd0e88d0945e5b26f7ba808218d730b00392a89c6198acaedeae316db1cb" }, "downloads": -1, "filename": "strip-hints-0.1.4.tar.gz", "has_sig": false, "md5_digest": "c9c77236bfe1127a12e1411c22fd0757", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19154, "upload_time": "2019-01-18T20:25:47", "url": "https://files.pythonhosted.org/packages/fc/7c/1d057b73f3fb66c446169bf65e8dcae3cf3583e7e4b107d4271e11e30a68/strip-hints-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "1596568652dbd825f4ab3388e0b49e1e", "sha256": "067d1bf938d6744c4237954ad950fb6d535b554d49f69d23ff242172079b4f10" }, "downloads": -1, "filename": "strip-hints-0.1.5.tar.gz", "has_sig": false, "md5_digest": "1596568652dbd825f4ab3388e0b49e1e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19388, "upload_time": "2019-06-16T17:35:58", "url": "https://files.pythonhosted.org/packages/d4/03/08985efda9dba2802f0566079b022c15bbb72d7f9f8ac7dd178f4057321c/strip-hints-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "9d10a5381aeb18ba9afcb9094ba93dca", "sha256": "7e7ac54bf8f599dba8a418d22c9ed03adf97f1bce674daf619533cb413e4767d" }, "downloads": -1, "filename": "strip-hints-0.1.6.tar.gz", "has_sig": false, "md5_digest": "9d10a5381aeb18ba9afcb9094ba93dca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19717, "upload_time": "2019-07-24T22:31:56", "url": "https://files.pythonhosted.org/packages/06/71/29bdb101d45200d565550e33cb66714a7da92c28f3bfd66291ae36395622/strip-hints-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "84de7de7e794147d282766642460f504", "sha256": "d0bebb52053eb2def2ba6e346e3d19684e88819d706a1d961a09bc83957dfc4d" }, "downloads": -1, "filename": "strip-hints-0.1.7.tar.gz", "has_sig": false, "md5_digest": "84de7de7e794147d282766642460f504", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20351, "upload_time": "2019-07-27T04:00:59", "url": "https://files.pythonhosted.org/packages/d7/5f/fb324e83fe43c1a0a8d29cc32935941823a42024c3120295920f1bf84ac3/strip-hints-0.1.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "84de7de7e794147d282766642460f504", "sha256": "d0bebb52053eb2def2ba6e346e3d19684e88819d706a1d961a09bc83957dfc4d" }, "downloads": -1, "filename": "strip-hints-0.1.7.tar.gz", "has_sig": false, "md5_digest": "84de7de7e794147d282766642460f504", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20351, "upload_time": "2019-07-27T04:00:59", "url": "https://files.pythonhosted.org/packages/d7/5f/fb324e83fe43c1a0a8d29cc32935941823a42024c3120295920f1bf84ac3/strip-hints-0.1.7.tar.gz" } ] }