circular-dependency

Remove python circular import

好久不见. 提交于 2019-12-06 22:19:02
问题 user.py: from story import Story class User: ... def get_stories(self): story_ids = [select from database] return [Story.get_by_id(id) for id in story_ids] story.py from user import User class Story: ... def __init__(self, id, user_id, content): self.id = id self.user = User.get_by_id(user_id) self.content = content as you can see, there is a circular import in this program, which causes an ImportError . I learned that I can move the import statement in method definition to prevent this error

Getting around circular reference in Google Spreadsheet

流过昼夜 提交于 2019-12-06 21:39:22
问题 I have a google docs spreadsheet with two columns: A and B. Values of B are just values from A in a different format, and I have a formula in the B column that does the conversion. Sometimes I do not have the values in A format but I have them in B format. I would like to automatically get the values in A format in the A column by adding the formula that does the reverse conversion in the A column. This, of course, generates a circular reference. Is there a way to get around it? 回答1: From

Fortran OOP circular dependency handling, interfaces

孤街浪徒 提交于 2019-12-06 15:50:43
Compiler: ifort version 12.1.5 I'm writing some Fortran code and I'd like to make use of some F2003 OOP features, but I'm hitting some stumbling blocks. Paring down the example, I wish to have two derived types A and B, each of which have a pointer to instances of the other. In Fortran, circular dependencies between modules are explicitly disallowed, so these two types would have to reside in the same module. This compiles: module testModule implicit none type A type(B),pointer :: b1 end type A type B type(A),pointer :: a1 end type B contains [some possibly type-bound procedures] end module

boost::shared_ptr cycle break with weak_ptr

◇◆丶佛笑我妖孽 提交于 2019-12-06 13:36:20
I am currently in a situation like: struct A { shared_ptr<B> b; }; struct B { shared_ptr<A> a; }; //... shared_ptr<A> a(new A()); shared_ptr<B> b(new B()); a->b(b); b->a(a); I know this won't work, because the references would continue to point to each other. I've also been told that weak_ptr solves this issue. However, weak_ptr has no get or -> overload. I've heard mentions of 'use lock() ', but can anyone give code examples of how to do this correctly? Come on now. http://boost.org/doc/libs/1_42_0/libs/smart_ptr/weak_ptr.htm ^^^^^ EXAMPLE IS RIGHT THERE ^^^^^^ DAMN! I think the bigger issue

How to handle circularly dependent observables in RxJS?

≯℡__Kan透↙ 提交于 2019-12-06 11:30:54
问题 Let's say e.g. that somewhere on a server there is a mapping between integers and names and a web page provides a simple input where a user can enter a number and is given the corresponding name. In its basic form, this problem is simple: const input$ = Rx.Observable.fromEvent(..., "input"); const request$ = input$.map( ... ); const serverResponse$ = request$.flatMap( askServer ); Now I would like to cache the results so that a request is only done when the number is not in the cache. const

Gson Serialize Circular References Using Stubs

这一生的挚爱 提交于 2019-12-06 09:26:42
I'm trying to implement some simple Json serialization functionality but I'm having a hard time coping with the massive complexity of Gson. So basically I have a bunch of Entity classes which reference each other with a lot of circular reference. To serialize this structure to JSON I want to keep track of the objects already serialized. The Entity classes all implement an interface called Identified which has one method String getId() giving a globally unique id. So during serializiation of one root element, I want to store all encountered ids in a Set and decide based on that set, whether to

ES6 Modules and Circular Dependency

不羁岁月 提交于 2019-12-06 07:53:36
I'm having this problem in ES6 in a Babel Environment: // A.js class A { } export default new A(); // B.js import C from './C'; class B { } export default new B(); // C.js import A from './A'; import B from './B'; class C { constructor(A, B){ this.A = A; this.B = B; // undefined } } export default new C(A, B) I import them like this: // stores/index.js import A from './A'; import B from './B'; import C from './C'; export { A, B, C } And from my app entry point I do: import * as stores from './stores'; I would (hoped) expected the order of execution to be A -> B ->C but in reality it is A-> C->

Best practice for structuring module exceptions in Python3

无人久伴 提交于 2019-12-06 07:01:48
问题 Suppose I have a project with a folder structure like so. /project __init__.py main.py /__helpers __init__.py helpers.py ... The module helpers.py defines some exception and contains some method that raises that exception. # /project/__helpers/helpers.py class HelperException(Exception): pass def some_function_that_raises(): raise HelperException On the other hand my main.py module defines its own exceptions and imports methods that may raise an exception from helpers.py . # /projects/main.py

Calling IMappingEngine.Map inside custom mapping

℡╲_俬逩灬. 提交于 2019-12-06 04:32:17
问题 With AutoMapper, when using ConvertUsing to define a custom mapping for a type that is a container, I often need to call IMappingEngine.Map inside the mapping function. This is necessary because it allows-me to reuse the definition of the child mapping. CreateMap<Order, OrderModel>() .ConvertUsing(o => new OrderModel( o.Id, o.ShippingAddress, mapper.Map<IList<OrderItemModel>>(o.Items) )); In order to do this, I need a reference to IMappingEngine. When the mapping engine is being configured, I

How to generate a dependency diagram from a set of XSD files?

感情迁移 提交于 2019-12-05 21:05:51
See the title: I have around 50 XSD files importing each other (with tags) and I need to analyze their dependencies. Do you know any software (preferably free) to generate a dependency diagram automatically from these files? I did not find any existing program to do that, so... I developed my own! It is called GraphVisu . There is a first program to generate the graph structure from seed XSD files, and another one to visualise graphs. I also included a detection of clusters of interrelated nodes (called " strongly connected components " in graph theory). Feel free to use it! I am not aware of