Giter Club home page Giter Club logo

primitives's People

Contributors

proofit404 avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

primitives's Issues

Generator return value.

from primitives import Generator, Argument, Return, Callable

gen = Callable(Generator(1, 2, 3, Return(4)), a=Argument('a'), b=Argument('b'))

it = gen(a='a', b='b')

next(it)  # 1

next(it)  # 2

next(it)  # 3

next(it)  # StopIteration: 4

Awaitable throw arguments.

from primitives import Awaitable, Callable, Throw, Argument

coro = Callable(Awaitable(1, Throw(ValueError, Argument(TypeError))))

it = coro()

await it  # 1

it.throw(TypeError())  # ValueError()

AsyncContext exit method return value.

from primitives import AsyncContext, Exit

resource = AsyncContext(1, Exit(True))

async with resource as r:
    r  # 1
    raise ValueError()
# Execution continues here without exception

Awaitable send arguments.

from primitives import Awaitable, Send, Argument

a = Awaitable(1, Send(3, Argument(2)))

it = gen()

await it  # 1

it.send(2)  # 3

Empty Instance object.

from primitives import Callable, Instance

user = Instance(greet=Callable('Hello, John'))

user.greet()  # Hello, John

Add comparison with mock library to the index page. Writing mock for use case below would be a nightmare:

def greet_many(repo):
    for user in repo.users():
        print(user.greet('Hello'))

You could try to check that third user received congratulations in French. Mock version would a homework to exercise.

Fake objects within scopes should be used.

All fake objects instantiated within particular scope should be used before scope will be finalized.

from primitives import Scope

with Scope() as scope:

    func1 = scope.Callable(1, a=scope.Argument('x'))

    func2 = scope.Callable(2, a=scope.Argument('y'))

    func1(a='x') # 1

# Error (func2 was never called)

Inherited Instance object.

from primitives import Callable, Instance

user = Instance(User, greet=Callable())

isinstance(user, User)  # True

Callable return value.

from primitives import Callable

func = Callable('Hello, John')

func()  # 'Hello, John'

Class object produces Instance objects.

from primitives import Class, Instance, Callable

FkUser = Class(Instance(greet=Callable('Hello, John')))

user = FkUser()

user.greet()  # Hello, John
from primitives import Class, Instance, Callable

FkUser = Class(User, Instance(greet=Callable('Hello, John')))

user = FkUser()

user.greet()  # Hello, John

AsyncContext exit method arguments.

from primitives import AsyncContext, Exit, Argument

resource = AsyncContext(1, Exit(Argument(ValueError)))

async with resource as r:
    r  # 1
    raise ValueError()  # Ok

async with resource as r:
    r  # 1
    raise TypeError()  # Error

Context exit method return value.

from primitives import Context, Exit

resource = Context(1, Exit(True))

with resource as r:
    r  # 1
    raise ValueError()
# Execution continues here without exception

Inherited Class object.

from primitives import Class

FkUser = Class(User)

inspect.isclass(FkUser)  # True

issubclass(FkUser, User)  # True

fk_user = FkUser()

isinstance(fk_user, User)  # True

Callable keyword arguments.

from primitives import Callable, Argument

func = Callable(1, a=Argument('x'), b=Argument('y'))

func('x', 'y')  # 1

func(b='y', a='x')  # 1
from primitives import Callable, Argument

func = Callable(a=Argument('x'), b=Argument('y'))

func('x', 'y')  # None

func(b='y', a='x')  # None

Callable positional arguments.

from primitives import Argument, Callable

func = Callable('Hello, John', Argument('John'))

func('John')  # Hello, John

func('Kate')  # Exception
from primitives import Argument, Callable

func = Callable(Argument('John'))

func('John')  # None

func('Kate')  # Exception
from primitives import Argument, Callable

func = Callable(Argument('John'))

func(a='John')  # Exception

Generator throw arguments.

from primitives import Generator, Callable, Throw, Argument

gen = Callable(Generator(1, Throw(ValueError, Argument(TypeError))))

it = gen()

next(it)  # 1

it.throw(TypeError())  # ValueError()

Instance object attributes.

from primitives import Attribute, Instance

user = Instance(name=Attribute('John'))

user.name  # 'John'
from primitives import Attribute, Instance

user = Instance(User, name=Attribute('John'))

user.greet()  # Hello, John

Context exit method arguments.

It should be possible to expect exception occurred within the context manager.

from primitives import Context, Exit, Argument

resource = Context(1, Exit(Argument(ValueError)))

with resource as r:
    r  # 1
    raise ValueError()  # Ok

with resource as r:
    r  # 1
    raise TypeError()  # Error

Generator yield value.

from primitives import Generator, Callable, Argument

genfunc = Callable(Generator(1, 2, 3), Argument('a'), Argument('b'))

it = genfunc('a', 'b')

next(it)  # 1

next(it)  # 2

next(it)  # 3

next(it)  # StopIteration

Class object constructors.

from primitives import Class, Instance, Callable, Variant

FkUser = Class(
    User,
    Variant(
        Callable(
            Instance(greet=Callable('Hello, John')),
            Argument('John'),
        ),
        Callable(
            Instance(greet=Callable(Exception())),
            Argument('Kate'),
        ),
    ),
)

j_user = FkUser('John')

user.greet()  # Hello, John

k_user = FkUser('Kate')

user.greet()  # Exception

Generator send arguments.

from primitives import Generator, Send, Argument

gen = Generator(1, Send(3, Argument(2)))

it = gen()

next(it)  # 1

it.send(2)  # 3

Empty Awaitable object.

from primitives import Callable, Instance, Awaitable

user = Instance(greet=Callable(Awaitable('Hello, John')))

await user.greet()  # Hello, John

Empty Class object.

from primitives import Class

FkUser = Class()

inspect.isclass(FkUser)  # True

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.