Resolving circular imports for protocols #5
kangz12345
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
I also found out how to prevent circular imports, but there may be another neat way.. Furthermore, we need two functions; dumps and loads, then how about implementing them in |
Beta Was this translation helpful? Give feedback.
2 replies
-
Ah, I forgot it completly.. And your opinion looks better because they are also related to protocols! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
When apps communicate with each other, they need to know the message protocol of each app.
For convenience and robustness, many apps will provide
dataclass
protocols to dumps and loads messages.However, when an app A and B needs the protocol of each other, they must import each other, which leads to circular import.
Circular import is not good because:
Therefore, we need a way to break through this problem.
Suggestion
Recommend to define such protocols outside the main module, i.e., make an independent module for protocols.
iquip
appsFor the apps included in
iquip
, make such protocols in a "protocol" module.For example, if we have app modules
app1.py
andapp2.py
, their protocol definitions are defined inprotocol.py
.Then
protocol.py
will never import the other app modules, so it will not cause any circular imports.Third-party apps
For the external apps which are not included in
iquip
, they can implement it however they want, sinceiquip
does not import them.They can import
iquip.protocol
and use it without any problem.Beta Was this translation helpful? Give feedback.
All reactions