williame / obiwan Goto Github PK
View Code? Open in Web Editor NEWa function parameter type checker; a json validator
License: Other
a function parameter type checker; a json validator
License: Other
How to specify that an item should be iterable, with the contents being a specific type? In the case I'm looking at, all the following should pass:
list
of str
stuple
of str
sodict_values
of str
setc.
Expected the following to be valid:
template = {
'person': [{
'id': int,
obiwan.noneable('name'): str
}]
}
test = {'person': [{'id': 1, 'name': None}]}
obiwan.duckable(test, template)
But seems like it isn't.
The documentation says
noneable is just a way of saying
{...,None}
I would prefer to use the {...,None}
syntax, as it's more concise and more convenient. However, obiwan doesn't seem to actually let None match None, objecting that None is not the same as NoneType. (And NoneType is hard to use as a literal.)
I have a minimal working example of this bug in python 3.4
import abc
from obiwan import *; install_obiwan_runtime_check()
class Foo(metaclass=abc.ABCMeta):
@abc.abstractmethod
def bar(self):
pass
class FooImpl(Foo):
def bar(self):
print('hi')
def do_stuff_with_a_foo_implementation(f: [Foo]):
f.bar()
do_stuff_with_a_foo_implementation([FooImpl()])
I'm not sure what it is about the list that causes the trouble but it is required. It works fine without the list
Console dump:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\obiwan\__init__.py", line 281, in duckable
if not isinstance(obj, collections.abc.Sequence):
AttributeError: 'module' object has no attribute 'abc'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "obiwan_abc_test.py", line 17, in <module>
do_stuff_with_a_foo_implementation([FooImpl()])
File "obiwan_abc_test.py", line 14, in do_stuff_with_a_foo_implementation
def do_stuff_with_a_foo_implementation(f: [Foo]):
File "C:\Python34\lib\site-packages\obiwan\__init__.py", line 401, in _runtime
_checker
duckable(arg, constraint, "%s(%s)" % (frame.f_code.co_name, key))
File "C:\Python34\lib\site-packages\obiwan\__init__.py", line 318, in duckable
raise ObiwanError("%s internal error: %s" % (ctx, e))
obiwan.ObiwanError: do_stuff_with_a_foo_implementation(f) internal error: 'modul
e' object has no attribute 'abc'
Like here:
def id2(x: int) -> int:
"""Identitée
>>> id2(2)
2
>>> id2(2.0)
Traceback (most recent call last):
...
obiwan.ObiwanError: id(x) is <class 'float'> but should be <class 'int'>
"""
return x
See here:
https://gist.github.com/Grahack/9333665
setup.py
is missing classifiers like
classifiers=(
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
),
This will help us know to try this library we need python 2 or python 3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.