question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support collection_class in relationship()

See original GitHub issue

I do not know if #82 will fix the issue but I have the following problem with mypy. I use typing in order to simplify coding.

repositories: Set['Repository'] = relationship('Repository', back_populates="installation", uselist=True, collection_class=set)

This is the error I get when running mypy with sqlalchemy-stubs

error: Incompatible types in assignment (expression has type "RelationshipProperty[Iterable[Repository]]", variable has type "Set['Repository']")

I also tried with InstrumentedSet which is the instance returned by relationship in my case. but no success. The code works btw, so it’s really mypy that is not able to understand.

Do you think it’s the scope of sqlalchemy-stubs ?

Information

python 3.6
sqlalchemy 1.3.8 Database Abstraction Library
sqlalchemy-stubs 0.2 SQLAlchemy stubs and mypy plugin
├── mypy >=0.660
│   ├── mypy-extensions >=0.4.0,<0.5.0 
│   ├── typed-ast >=1.4.0,<1.5.0 
│   └── typing-extensions >=3.7.4 
│       └── typing >=3.7.4 
└── typing-extensions >=3.6.5
    └── typing >=3.7.4

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ilevkivskyicommented, Sep 24, 2019

OK, the latter error can be fixed by adding support for collection_class. On one hand this doesn’t look like high priority (there is a simple workaround like adding correct annotation plus a # type: ignore), but on other hand this should not be hard to fix.

1reaction
ilevkivskyicommented, Sep 26, 2019
repositories: RelationshipProperty[Set['Repository']] = relationship('Repository', back_populates="installation", uselist=True, collection_class=set)  # type: ignore
Read more comments on GitHub >

github_iconTop Results From Across the Web

Collection Configuration and Techniques
The relationship() function defines a linkage between two classes. ... AppenderQuery. A dynamic query that supports basic collection storage operations.
Read more >
Defining and Using Relationships - InterSystems Documentation
Describes how to define and use relationships, a special kind of property used to ... In this case, we use the RemoveAt() method...
Read more >
Does a class with has-a relationship with a Collection object ...
I would say yes. The collection is almost immaterial here, more just an implementation detail of the "has-a" relationship between the class and ......
Read more >
Return eloquent collection from relationship method - Laracasts
This works fine and returns an eloquent collection of all consultations of a user. I have a Practice model that has a members()...
Read more >
Relationship Class (Microsoft.AnalysisServices.Tabular)
Represents a logical relationship between two Table objects. It is a child of a Model object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found