Giter Site home page Giter Site logo

pony-stubs's People

Contributors

github-actions[bot] avatar jonesus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pony-stubs's Issues

Package naming

Should the package be named pony-stubs, types-pony or something else?

@fluffy-critter suggested that

Also, just as a note, a more standard name for the types package would be types-pony.

at ponyorm/pony#479 (comment)

But as far as I could find, this PEP (https://peps.python.org/pep-0561/#type-checker-module-resolution-order) suggests that type-only modules should be named <package_name>-stubs. Personally I don't have an opinion other than that we go as standard as possible.

@fluffy-critter can you find another PEP that would propose the naming you suggested, or is it more based on what is commonly done?

Support "attribute lifting"

Pony ORM uses quite a bunch of dynamic behaviour, which makes it hard to statically type. One of the most glaring difficulties I've had so far is with "attribute lifting" of related models: https://docs.ponyorm.org/working_with_relationships.html#attribute-lifting

Currently the workaround is to type all additional attributes of a SetInstance[EntityType] as any (https://github.com/Jonesus/pony-stubs/blob/main/pony-stubs/orm/core.pyi#L464), but this is obviously suboptimal.

orm.json not supported

I have a model class like:

class User(orm.core.Entity):
    name = orm.PrimaryKey(str)
    profile = orm.Required(orm.json)

When I attempt to make use of this field, mypy fails to see orm.json as being equivalent to a dict, so I can neither call user.profile.copy() nor can I return user.profile as a dict directly.

orm.PrimaryKey and orm.Set need explicit annotations

When I have a model like:

class Foo(orm.core.Entity):
    name = orm.PrimaryKey(str)
    bar = orm.Set("Bar")

class Bar(orm.core.Entity):
    foo = orm.Set(Foo)

mypy generates errors such as need type annotation for "name" and need type annotation for "bar". I'm able to work around this by adding annotations such as:

class Foo(orm.core.Entity):
    name:orm.PrimaryKey[str] = orm.PrimaryKey(str)

and so on.

Type[Foo] has no attribute __iter__

It looks like one of the hairier type-inference things that Pony screws up mypy on is still happening even with this package installed. For example:

publ/path_alias.py:65: error: "Type[PathAlias]" has no attribute "__iter__" (not iterable)
publ/path_alias.py:74: error: "Type[PathAlias]" has no attribute "__iter__" (not iterable)
publ/path_alias.py:77: error: "Type[PathAlias]" has no attribute "__iter__" (not iterable)
publ/entry.py:746: error: "Type[Entry]" has no attribute "__iter__" (not iterable)
publ/entry.py:890: error: "Type[EntryAuth]" has no attribute "__iter__" (not iterable)
publ/entry.py:1008: error: "Type[PathAlias]" has no attribute "__iter__" (not iterable)
publ/entry.py:1011: error: "Type[Entry]" has no attribute "__iter__" (not iterable)
publ/category.py:72: error: "Type[Entry]" has no attribute "__iter__" (not iterable)

The respective lines of code are all simple generator-based queries, e.g.:

# path_alias.py:65
    orm.delete(p for p in model.PathAlias if p.path == path)

# entry.py:746
        limit = max(10, orm.get(orm.count(e) for e in model.Entry) * 5)

# caegory.py:72
        subcat_query = orm.select(e.category for e in model.Entry if e.visible)

Implicit id field not set

If I use the implicit int PrimaryKey field on an entity class, I get errors like "type[Entry]" has no attribute "id". I can work around this by providing an explicit id field but that seems like it shouldn't be necessary.

Testing the package

I need to figure out how to automate testing stubs. Maybe have a folder full of random implementation files, and run both mypy and pyright against them on a CI job?

Name "db.Entity" is not defined

from pony import orm

db = orm.Database()
db.bind(provider='sqlite', filename='db.sqlite')

class A(db.Entity):
	name = orm.Required(str, max_len=64, index=True)

mypy says: Name "db.Entity" is not defined

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.