From a474895764c62b11b155e78c06585e4b54c926bb Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 25 Jul 2020 15:05:42 +0200 Subject: [PATCH] Start working with mypy --- parso/cache.py | 6 +--- parso/normalizer.py | 4 +-- parso/tree.py | 3 +- setup.cfg | 13 +++++++ setup.py | 83 ++++++++++++++++++++++++--------------------- 5 files changed, 61 insertions(+), 48 deletions(-) diff --git a/parso/cache.py b/parso/cache.py index 61ea8ca..fd3563a 100644 --- a/parso/cache.py +++ b/parso/cache.py @@ -7,11 +7,7 @@ import shutil import platform import logging import warnings - -try: - import cPickle as pickle -except: - import pickle +import pickle from parso.file_io import FileIO diff --git a/parso/normalizer.py b/parso/normalizer.py index 41b8258..4477147 100644 --- a/parso/normalizer.py +++ b/parso/normalizer.py @@ -149,8 +149,8 @@ class Issue(object): class Rule(object): - code = None - message = None + code: int + message: str def __init__(self, normalizer): self._normalizer = normalizer diff --git a/parso/tree.py b/parso/tree.py index 9105785..ec58ed9 100644 --- a/parso/tree.py +++ b/parso/tree.py @@ -23,7 +23,7 @@ class NodeOrLeaf(object): The base class for nodes and leaves. """ __slots__ = () - type = None + type: str ''' The type is a string that typically matches the types of the grammar file. ''' @@ -257,7 +257,6 @@ class BaseNode(NodeOrLeaf): A node has children, a type and possibly a parent node. """ __slots__ = ('children', 'parent') - type = None def __init__(self, children): self.children = children diff --git a/setup.cfg b/setup.cfg index 1295389..433824a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,3 +10,16 @@ ignore = E226, # line break before binary operator W503, + + +[mypy] +disallow_subclassing_any = True + +# Avoid creating future gotchas emerging from bad typing +warn_redundant_casts = True +warn_unused_ignores = True +warn_return_any = True +warn_unused_configs = True +warn_unreachable = True + +strict_equality = True diff --git a/setup.py b/setup.py index 9ae7650..0ead19c 100755 --- a/setup.py +++ b/setup.py @@ -12,42 +12,47 @@ __AUTHOR_EMAIL__ = 'davidhalter88@gmail.com' readme = open('README.rst').read() + '\n\n' + open('CHANGELOG.rst').read() -setup(name='parso', - version=parso.__version__, - description='A Python Parser', - author=__AUTHOR__, - author_email=__AUTHOR_EMAIL__, - include_package_data=True, - maintainer=__AUTHOR__, - maintainer_email=__AUTHOR_EMAIL__, - url='https://github.com/davidhalter/parso', - license='MIT', - keywords='python parser parsing', - long_description=readme, - packages=find_packages(exclude=['test']), - package_data={'parso': ['python/grammar*.txt', 'py.typed', '*.pyi', '**/*.pyi']}, - platforms=['any'], - python_requires='>=3.6', - classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Plugins', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Topic :: Software Development :: Libraries :: Python Modules', - 'Topic :: Text Editors :: Integrated Development Environments (IDE)', - 'Topic :: Utilities', - 'Typing :: Typed', - ], - extras_require={ - 'testing': [ - 'pytest<6.0.0', - 'docopt', - ], - }, - ) +setup( + name='parso', + version=parso.__version__, + description='A Python Parser', + author=__AUTHOR__, + author_email=__AUTHOR_EMAIL__, + include_package_data=True, + maintainer=__AUTHOR__, + maintainer_email=__AUTHOR_EMAIL__, + url='https://github.com/davidhalter/parso', + license='MIT', + keywords='python parser parsing', + long_description=readme, + packages=find_packages(exclude=['test']), + package_data={'parso': ['python/grammar*.txt', 'py.typed', '*.pyi', '**/*.pyi']}, + platforms=['any'], + python_requires='>=3.6', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Plugins', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Text Editors :: Integrated Development Environments (IDE)', + 'Topic :: Utilities', + 'Typing :: Typed', + ], + extras_require={ + 'testing': [ + 'pytest<6.0.0', + 'docopt', + ], + 'qa': [ + 'flake8==3.8.3', + 'mypy==0.782', + ], + }, +)