Skip to content

Commit

Permalink
libs: Add mypy-abstracts plugin (#24)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax authored Aug 24, 2021
1 parent 40cd200 commit 47a7c1e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mypy-abstracts/README.rst
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``.
1 change: 1 addition & 0 deletions mypy-abstracts/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
28 changes: 28 additions & 0 deletions mypy-abstracts/mypy_abstracts/plugin.py
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
58 changes: 58 additions & 0 deletions mypy-abstracts/setup.py
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',
],
},
)

0 comments on commit 47a7c1e

Please sign in to comment.