24 Commits
Author SHA1 Message Date
bendtherules 42d640c478 Version bump from dev as build fails + build egg 2015-10-07 15:22:23 +05:30
bendtherules 9376d05d52 Fix build step newlines 2015-10-07 15:13:28 +05:30
bendtherules 8c9fe9c141 Removed fmatch from folder 2015-06-23 12:59:35 +05:30
bendtherules bcbd78b8be Revert "Re-remove fmatch"
This reverts commit 711d51d4cf.
2015-06-23 12:55:58 +05:30
bendtherules 711d51d4cf Re-remove fmatch 2015-06-23 12:55:40 +05:30
bendtherules b931342984 Removed fmatch 2015-06-23 12:54:36 +05:30
bendtherules 9466035cc7 Moved idea out in gitignore 2015-06-23 12:53:13 +05:30
bendtherules fabbefa7af Fixed docs link used rtd 2015-06-22 19:45:28 +05:30
bendtherules 96e32846ec git link docs added 2015-06-22 17:38:44 +05:30
bendtherules 0dce7022aa git link formatting fixed 2015-06-22 17:37:19 +05:30
bendtherules 9c24838596 github link added 2015-06-22 17:33:24 +05:30
bendtherules 3451971f8e tutorial link fixed 2015-06-22 14:20:30 +05:30
bendtherules 931e7ed937 pip link added 2015-06-22 14:17:08 +05:30
bendtherules 5c70bc5b44 Fixed typo 2015-06-21 22:30:27 +05:30
bendtherules bcac8d5cfc Docs - fixed typo duck-typing 2015-06-21 22:12:09 +05:30
bendtherules 77f0e00fa1 Docs - about undocumented duck-typing 2015-06-21 22:06:50 +05:30
bendtherules d57304504e Adeed pip link + fixed version in setup.py 2015-06-21 22:02:28 +05:30
bendtherules 46edf10e9d Fixed logo link 1 2015-06-21 21:34:13 +05:30
bendtherules 354ce2e307 Fixed doc link 4 2015-06-21 21:28:31 +05:30
bendtherules 98ebd5b40e Fixed doc link 3 2015-06-21 21:23:53 +05:30
bendtherules c1924f3630 Fixed doc link 2 2015-06-21 21:22:35 +05:30
bendtherules b579683287 Fixed docs link 2015-06-21 21:19:33 +05:30
bendtherules ccdeea9ccf Moved tests + removed extra img 2015-06-21 20:59:55 +05:30
bendtherules 027665d9eb Moved docs + build working 2015-06-21 18:48:28 +05:30
20 changed files with 3201 additions and 157 deletions
+3
View File
@@ -274,3 +274,6 @@ docs/_build/
# PyBuilder # PyBuilder
target/ target/
*.pypirc *.pypirc
MANIFEST
fmatch_idea.txt
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.
-14
View File
@@ -1,14 +0,0 @@
# HumbleMatch
Will **Sanitize your type-checks and duck-checks** for you
Available at [HumbleMatch@pypi]()
## What the heck is it?
HumbleMatch is made to *add a zing* to your mundane type-checking and duck-checking code.
* Check your function arguments reliably, add *more flexible signatures* and most of all, have a lovely API.
* Or just *sprinkle some assert* checks to ensure the data is what you expect it to be at any point.
* Provide helpful debugging errors, *dont just fail with cryptic errors*
@@ -1,13 +1,7 @@
Title: HumbleMatch - Go sanitize your type-checking
Date: 2015-06-19 16:56
Authors: bendtherules
Category: Projects
Tags: HumbleMatch, Launch stuff, Projects
Slug: HumbleMatch_Launch
## Intro ## Intro
Hi, I am [Abhas](blog.codesp.in) and personally, I love Python mostly for its intuitive, flexible and beautiful API. But some things, I really hate doing. HumbleMatch is my attempt at solving that pain. Hi, I am [Abhas](http://blog.codesp.in) and personally, I love Python mostly for its intuitive, flexible and beautiful API. But some things, I really hate doing. HumbleMatch is my attempt at solving that pain.
## The Pain Point #1 ## The Pain Point #1
@@ -241,4 +235,6 @@ Infact now that we know this, in Test 2 we can remove the repetion of `w([float]
I purposedly missed one method which is already there, called `w(obj).save_as(arg_name)`. How it works is that whatever it matches with is stored as `"arg_name"` and returns a dict filled with all such values, when `==`d with `other`. For eg `w([2, w(int).save_as("a"), OR(str,dict)).save_as("b")]) == [2,5,{"q":1}]` returns `{"a":5,"b":{"q":1}}`. I didnt document it well beacuse I am not mentally ok with a `==` call returning anything other than a `boolean`. Maybe, I will change the API in some way to make it better and document it then. But feel free to also try this, I am proud of this feature :) I purposedly missed one method which is already there, called `w(obj).save_as(arg_name)`. How it works is that whatever it matches with is stored as `"arg_name"` and returns a dict filled with all such values, when `==`d with `other`. For eg `w([2, w(int).save_as("a"), OR(str,dict)).save_as("b")]) == [2,5,{"q":1}]` returns `{"a":5,"b":{"q":1}}`. I didnt document it well beacuse I am not mentally ok with a `==` call returning anything other than a `boolean`. Maybe, I will change the API in some way to make it better and document it then. But feel free to also try this, I am proud of this feature :)
I have not yet talked about how it helps duck-typing code, but I'll add it soon (there is no more API for it, just need to apply these to objects and use FunctionType as type).
And thats all for now, have fun and write more code. And thats all for now, have fun and write more code.

Before

Width:  |  Height:  |  Size: 521 KiB

After

Width:  |  Height:  |  Size: 521 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

+34
View File
@@ -0,0 +1,34 @@
# HumbleMatch
Will **Sanitize your type-checks and duck-checks** for you
![HumbleMatch logo](./img/logo_medium.png "Yeah, I took that pic :)")
**Install using**
`pip install humblematch`
Github Repo at [github.com/bendtherules/humblematch](http://github.com/bendtherules/humblematch)
Available at [HumbleMatch@pypi](https://pypi.python.org/pypi/humblematch)
## What the heck is it?
HumbleMatch is made to *add a zing* to your mundane type-checking and duck-checking code.
* Check your function arguments reliably, add *more flexible signatures* and most of all, have a lovely API.
* Or just *sprinkle some assert* checks to ensure the data is what you expect it to be at any point.
* Provide helpful debugging errors, *dont just fail with cryptic errors*
## Impress me
Lets say we want a Point class with two __init__ signatures - `Point(x,y)` and `Point([x,y])`.
Assume its `__init__` signature looks like `def __init__(self, x, y=None)`
This is the only typechecking code you'll need for valid arguments.
from humblematch import w
assert( w([int, int]) == [x, y] or w([[int, int], None]) == [x, y] )
If you like it, please move to the [Tutorials](./Tutorial). Its a bit long, but that all the documentation youll need to know.
-125
View File
@@ -1,125 +0,0 @@
fmatch
.matched
.wrap
.Any
.old_matched
list_ -> fmatch -> [2,+(wrap([Int])*Any), [Any]*4 and fmatch(matched.len < old_matched[-1].len) ] (1)
matches [2, 3,5,8,9,1, [1,2,3,4]]
*(wrap([Int])*Any) => *(wrap([Int]).times(Any))
list_ -> fmatch -> [2,Any, wrap(int)*4 and (matched[0]*2 > 5 or all([m >6 for m in matched]) ] -> _, a, b
list_ -> fmatch -> [2,Any*Any,5]
basically need a mock object of sorts which stores everything, tries to stop evaluation, so that invalid (wrt types,values) ones work. invalid syntax still wont work.
macros in python
pass in a string or function, have a great pattern matching like lisp and then do your own stuff ( like http://stackoverflow.com/questions/267862/what-makes-lisp-macros-so-special#4621882 )
look for reaasembler in python
(1) -> [2, multi_0, list(Any,Any,Any,Any)]
wrap([Int]) = wrap_obj(data =[Int])
creates wrap_obj with data = param and ops =[]
if ops are applied store them
apply right then correctly or later (???)
(wrap([Int, Float])*Any) = wrap_obj(data =[Int, Float], ops =[__mult__:Any])
if ops[__mult__] is Any and data is list:
this == wrap_obj(data =[ wrap_multi_obj(data = [Int, Float],multi = Any, ops =None) ], ops =None)
if (data not list):
# eg 2
try normal __mult__ anyway
if ops[__mult__] is not Any:
# eg [2,3]*5
try normal __mult__ anyway
## Done
WrapObj
WrapMultiObj
## Done
wrap(Float).times(Any) == wrap_multi_obj(data = [Float],multi = Any, ops =None)
wrap([2,3.0]).times(Any) == wrap_multi_obj(data = [[2,3.0]],multi = Any, ops =None)
.times means the whole thing will repeat n times
first doing all ops and, replace wrap_obj with wrap_multi_obj putting new data=[data]
to repeat multiple items sequentially -> (2,3) say n times as in 2,3,2,3,2,3,.. do +(wrap([2,3.0]).times(Any))
### Not needed ###
+(wrap([Int])*Any) == wrap(Int).times(Any)
== wrap_multi_obj(data = [Int],multi = Any, ops =None)
if prev is wrap_obj and data is list:
removes prev node, and replace with wrap_multi_obj with same data
+ is the unwrap op
XXXX
types of indirect matching
1. type-based (X This is what exact match does)
2. Checking subclass-tree (issubclass)
3. explicit conversion-based (converts 1st arg of fmatch to type of 2nd arg) -- usually quite good
4. ABC-based somewhat
try to use abc for multiple types
functional prog is like passing little chunks of data, however less you can. but you will lose sense of what data it is.
imperative prog is like having a structure of data and partially modifying it, yet sending the whole thing over.
if you know about every data, fp - like experts.
if you want to ask about everything, imp. safer in some sense
types like putting a label. one label attests to a number of similar properties, so if you got type use all those properties even with the assumptions that how they behave with each other
duck typing is like letting anyone with a known speciific skill work in your office. They dont need degrees or anything if they know that one thing very well which you'll need. And yes that is very flexible and democratic. But never assume that they will even have some related but different skill. Degrees attest to the fact that they know about a set of skills. All that cool.
Now if you have any more requirement, ask if they can do it and if they cant, fire them. Or force them to do it, if they fail fire them. But rest assured, you are more flexible so anyone with both those skills are welcome now, even the one you just fired if they end up learning that skill.
issue of flexibility vs reliability, you sometimes want both :)
Ceveats
This wont work
1. WrapObj({str:5}) == {"w":5} as dicts are not searched for key and yet they are ambiguous if searched. So, keys are taken for what they are, even if it is a class. So, here str is considered as the key
for mixed type:
allow this kind of things -> int or float("inf")
IDEAS TO DO
add more debug info
debug info or raise custom exception
better __repr__ print
allow matches to store in var (done)
add __mult__ alternative to .times (done)
what about dict ? (dicts ok, )
maybe dict to obj? (done)
save_as in multimatch with list behaviour(done)
Any and OR save_as (done)
test if data == Multi branch, raise error doesnt break anything
more docs
test integration save_as and times
do smart .times for single value
allow Any with a module.Class(Any), which allows only object - Any
more doctest for other methods and helpers
test helpers
name change to humblematch
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,4 @@
from wrap_obj import WrapObj, Any, OR, w from humblematch import WrapObj, Any, OR, w
import collections import collections
import pytest import pytest
+2
View File
@@ -1,3 +1,5 @@
site_name: HumbleMatch site_name: HumbleMatch
theme: cerulean theme: cerulean
docs_dir: humblematch/docs
-5
View File
@@ -1,5 +0,0 @@
Run doctest -
python -m doctest .\wrap_obj.py
Run py.test-
py.test
+56
View File
@@ -0,0 +1,56 @@
# HumbleMatch
--------------
Will **Sanitize your type-checks and duck-checks** for you
![HumbleMatch logo](http://humblematch.readthedocs.org/en/latest/img/logo_medium.png "Yeah, I took that pic :)")
**Install using**
`pip install humblematch`
Github Repo at [github.com/bendtherules/humblematch](http://github.com/bendtherules/humblematch)
Available at [HumbleMatch@pypi](https://pypi.python.org/pypi/humblematch)
More Docs at [humblematch.readthedocs.org](http://humblematch.readthedocs.org/en/latest/)
## What the heck is it?
HumbleMatch is made to *add a zing* to your mundane type-checking and duck-checking code.
* Check your function arguments reliably, add *more flexible signatures* and most of all, have a lovely API.
* Or just *sprinkle some assert* checks to ensure the data is what you expect it to be at any point.
* Provide helpful debugging errors, *dont just fail with cryptic errors*
## Get Running
--------------
### Run doctest -
python -m doctest .\humblematch\wrap_obj.py
### Run tests-
cd humblematch
py.test
### To build code -
python setup.py sdist bdist_wheel bdist_msi bdist_egg
python setup.py build --plat-name=win-amd64 bdist_wininst
python setup.py build --plat-name=win32 bdist_wininst
### To upload to PYPI-
twine upload dist/* -r pypi
### To build or serve docs
mkdocs build
or
mkdocs serve
-----
+4 -1
View File
@@ -1,2 +1,5 @@
[metadata] [metadata]
description-file = README description-file = readme.md
[bdist_wheel]
universal=1
+32 -3
View File
@@ -1,14 +1,43 @@
from distutils.core import setup import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
setup( setup(
name='humblematch', name='humblematch',
packages=['humblematch'], # this must be the same as the name above packages=['humblematch'], # this must be the same as the name above
version='0.1.dev1', version='0.1.1',
description='Will Sanitize your type-checks and duck-checks for you', description='Will Sanitize your type-checks and duck-checks for you',
author='bendtherules', author='bendtherules',
author_email='bendtherules@codesp.in', author_email='bendtherules@codesp.in',
url='https://github.com/bendtherules/humblematch', # use the URL to the github repo url='https://github.com/bendtherules/humblematch', # use the URL to the github repo
download_url='https://github.com/bendtherules/humblematch/tarball/0.1.dev1', # I'll explain this in a second download_url='https://github.com/bendtherules/humblematch/tarball/0.1.dev3', # I'll explain this in a second
license='WTFPL',
keywords=['type-checking', 'testing', 'assert'], # arbitrary keywords keywords=['type-checking', 'testing', 'assert'], # arbitrary keywords
classifiers=['Development Status :: 3 - Alpha', ], classifiers=['Development Status :: 3 - Alpha', ],
package_data={
# Include all files in all packages
# 'humblematch': ['docs/*.md', 'test/*'],
},
tests_require=['pytest'],
cmdclass={'test': PyTest},
) )