Git Product home page Git Product logo

dynprops's People

Watchers

 avatar  avatar

dynprops's Issues

DynProps not recoginzed correctly if not declared in the class

The following code:

class I2B2Core(DynProps):
    sourcesystem_cd: Global[str] = "Unspecified"

class OntologyEntry(I2B2Core):
    c_hlevel: Local[int] = 0
    c_foo: Local[str]

class ConceptOntologyEntry(OntologyEntry):
    def c_hlevel(self) -> int:
        return 101

class OntologyRoot(OntologyEntry):
    c_hlevel = 2

print(OntologyRoot().c_hlevel)

Returns an error rather than '2'. The reason for this issue is two-fold:

  1. ConceptOntologyEntry doesn't recognize c_hlevel as a dyn property and
  2. c_hlevel function is set in the parent class

Normal properties with non '_' prefix fail

DynPropsMeta.__new__ assumes that all and only properties that don't begin with an underscore are dynamic entries. This is too fragile for normal use.

       def test_simple_props(self):
        class Base(DynProps):
            a_prop: Global[str] = 'on the'
            a_general_item = "penguin"

            def __init__(self, v: str) -> None:
                self.v = v

            def try_me(self) -> str:
                return f"There is a {self.a_general_item} {self.a_prop} {self.v}"

        x = Base("telly")
        self.assertEqual("There is a penguin on the telly", x.try_me())

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.