Categories
Database Development

Cannot use “ON CONFLICT” with postgres updatable view and partial index

I have an updatable view pointing to an underlying table that has a partial index. It looks something like this CREATE TABLE if not exists foo ( a INT, b INT, x INT, y INT, z BOOLEAN, CONSTRAINT x_or_y CHECK ( (z and x is not null and y is null) or (not z and […]

Categories
Mastering Development

A python function returning signature of it’s own run time arguments

I’d like a function: def sig(*args, **kwargs): “””User-friendly inspect.Signature construction””” # I’m guessing some introspection of frames or something… pass that does what its doc says: Make Signature instances easily. An example of it’s behavior would be: >>> sig(a, b: int, c=1, d: str=’bar’) <Signature (a, b: int, c=1, d: str = ‘bar’)> >>> sig(something_else) […]

Categories
Mastering Development

Typing: How to consider class arguments wrapped with partial?

I have a class MyClass that expects a class parent_cls as an argument which fullfills the interface ParentInterface. ChildA implements/extends from ParentInterface. Since inside of MyClass, parent_cls is instantiated with the argument a and b, the addtional argument c of ChildA is partially instantiated outside. In principle this does run in Python. However I get […]

Categories
Mastering Development

How to create instance of object using reflection for class that have parameter in constructor?

I’m trying to create object using reflection with class that have parameter in constructor. This is what I try for class without constructor. ABC::class.createInstance() ”’ But I have no idea how to do this for class with constructor like ”’ class ABC(a: Int, b: Int) {} ”’

Categories
Development Python

python testing using hypothesis : dictionaries with different types of values

I am trying to generate dictionaries containing different python types as values using the hypothesis module. For lists I can do this simply using the expression from hypothesis import given import hypothesis.strategies as st @given( st.lists( st.from_type(type) .flatmap(st.from_type) .filter(lambda x: not isinstance(x, (type(None)))), min_size=2, unique_by=lambda x: type(x), ) ) def test_something(dictionary): … which gives me […]