-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libs: Add mypy-abstracts plugin (#24)
Signed-off-by: Ryan Northey <ryan@synca.io>
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
mypy-abstracts | ||
============== | ||
|
||
mypy plugin to recognize classes decorated with ``abstracts.implementer``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from mypy.plugin import Plugin | ||
from mypy.nodes import SymbolTable, TypeInfo | ||
from mypy.types import Instance | ||
|
||
|
||
class AbstractionPlugin(Plugin): | ||
|
||
def get_class_decorator_hook(self, fullname: str): | ||
|
||
def _decorator_hook(*la): | ||
impl = la[0].cls.info | ||
iface = la[0].reason.args[0].node | ||
try: | ||
promote = Instance(iface, []) | ||
except TypeError: | ||
return | ||
if not any(ti._promote == promote for ti in impl.mro): | ||
faketi = TypeInfo(SymbolTable(), iface.defn, iface.module_name) | ||
faketi._promote = promote | ||
impl.mro.append(faketi) | ||
|
||
if fullname == "abstracts.decorators.implementer": | ||
return _decorator_hook | ||
|
||
|
||
def plugin(version: str): | ||
# ignore version argument if the plugin works with all mypy versions. | ||
return AbstractionPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import codecs | ||
from setuptools import setup # type:ignore | ||
|
||
|
||
DESCRIPTION = ( | ||
"A patches test fixture which provides a contextmanager for handling " | ||
"multiple mock patches") | ||
|
||
|
||
def read(fname): | ||
file_path = os.path.join(os.path.dirname(__file__), fname) | ||
return codecs.open(file_path, encoding='utf-8').read() | ||
|
||
|
||
setup( | ||
name='mypy-abstracts', | ||
version=read("VERSION"), | ||
author='Ryan Northey', | ||
author_email='ryan@synca.io', | ||
maintainer='Ryan Northey', | ||
maintainer_email='ryan@synca.io', | ||
license='Apache Software License 2.0', | ||
url='https://github.com/envoyproxy/pytooling/mypy-abstracts', | ||
description=DESCRIPTION, | ||
long_description=read('README.rst'), | ||
py_modules=['mypy_abstracts'], | ||
python_requires='>=3.5', | ||
install_requires=['mypy'], | ||
extras_require={ | ||
"test": [ | ||
"pytest", | ||
"pytest-coverage"], | ||
"lint": ['flake8'], | ||
"publish": ['wheel'], | ||
}, | ||
classifiers=[ | ||
'Development Status :: 4 - Beta', | ||
'Framework :: Pytest', | ||
'Intended Audience :: Developers', | ||
'Topic :: Software Development :: Testing', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.8', | ||
'Programming Language :: Python :: 3.9', | ||
'Programming Language :: Python :: 3 :: Only', | ||
'Programming Language :: Python :: Implementation :: CPython', | ||
'Operating System :: OS Independent', | ||
'License :: OSI Approved :: Apache Software License', | ||
], | ||
entry_points={ | ||
'pytest11': [ | ||
'patches = pytest_patches', | ||
], | ||
}, | ||
) |