Coder Social home page Coder Social logo

typet's People

Contributors

dangle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dangle

typet's Issues

Use default values in Object.

When a default value is supplied, Object knows not to require the value but does not seem to be setting the value in new instances.

Add Sphinx docs.

The project needs to be thoroughly documented with examples and tutorials.

Using the @singleton errors on default metaclass.

When using @singleton on a class that does not inherit from Object (no other metaclasses defined) throws an exception.

Traceback (most recent call last):
  File "<input>", line 1, in <module>
    @singleton
  File "/home/dangle/Projects/contains.io/containment/.tox/py36/lib/python3.6/site-packages/typet/meta.py", line 58, in _inner
    class _Meta(base, _Meta):  # pylint: disable=function-redefined
TypeError: Cannot create a consistent method resolution
order (MRO) for bases type, Singleton

Register validation types as the sliced type.

It should be possible to run this test:

from typingplus import is_instance
from typet import Bounded
assert is_instance(5, Bounded[int, 0:10])

I believe this causes an issue when using validation types with StrictObject.

This can be done by setting __instancecheck__ and __subclasscheck__ in BoundedMeta._BoundedSubclass.

The Singleton meta class unexpectedly raises a TypeError when we thought __instance__ existed

In [4]: _RcliConfig.call()

TypeError Traceback (most recent call last)
in ()
----> 1 _RcliConfig.call()

~/rcli/venv/lib/python3.6/site-packages/typet/meta.py in call(cls, args, **kwargs)
78 else:
79 try:
---> 80 cls.instance.singleton(args, **kwargs) # type: ignore
81 except AttributeError:
82 pass

TypeError: 'NoneType' object is not callable

The code in question is here:

https://github.com/contains-io/typet/blob/master/typet/meta.py#L64

Add support for Generics in Object and StrictObject

Currently, using Generics with Object is a pain. Initial support for casting and type validation exist, but creating the class itself is awkward as it requires creating a metaclass.

from typet import Object
from typing import Generic, GenericMeta, TypeVar

T = TypeVar('T')

class Meta(type(Object), GenericMeta): ...

class MyObject(Object, Generic[T], meta=Meta):
    value: T

Break package into multiple modules.

typet/__init__.py is becoming unwieldy. It should be broken into multiple packages and imported into the package with wildcards.

Initial proposed packages:

  • typet
  • typet.path
  • typet.validation
  • typet.object

Add base classes SingletonObject and StrictSingletonObject

Create a SingletonObject by creating a private metaclass that inherits from Singleton and _ObjectMeta and a metaclass for a StrictSingletonObject that inherits from Singleton and _StrictObjectMeta.

The proposed use case would be a global settings object:

from typet import SingletonObject, File

class _Configuration(SingletonObject):
    config: File = '~/.my_config'

settings = _Configuration()

Path validation objects should use pathlib.

The path validation objects, File, Dir, Path, and ExistingPath should instantiate pathlib objects instead of strings. They should also accept pathlib objects.

A check to import pathlib2 will need to be added to setup.py.

Ideas for built-in types.

typet needs to supply a rich collection of types by default. This issue will track ideas for the initial types.

Add support for type comments.

Because the annotations are read during the metaclass before the class is created, it may be necessary to add support for reading the type hint comments in the metaclass.

Non Object attributes violate the expectations of the __hash__ function.

If I make a proper typet Object, I can still assign to its attributes at run time, subsequent comparison or hash operations on the resulting instance will now return unexpected results. I believe the solution is to add logic to set_attr to prevent non-Object, or StrictObject assignment.

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.