
Assuming your circular imports are only because you are annotating types. You would likely want to use `typing.TYPE_CHECKING` and `from __future__ import annotations` (PEP 563). You can also use `"message.Object"` if you need to reference the objects outside of annotations, such as `TypeVar("T", bound="message.Object")`. https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING https://peps.python.org/pep-0563/ An example: ``` from __future__ import annotations from typing import TYPE_CHECKING, TypeVar if TYPE_CHECKING: from . import message T = TypeVar("T", bound="message.Object") def foo() -> message.Object: ... ``` On 07/11/2022 11:23, TobiasHT wrote:
The title of the issue might be cryptic, but here's what I was trying to mean.
I have two modules located in the same subpackage, something like this: ./objects /message.py /chat.py
message.py has functions that take in objects from chat.py as parameters and so does message.py. I tried to import objects from message.py import chat.py to use for type annotations and also from chat.py to message.py for the same reason but I get circular import errors.
Is there a way to create types for these objects that can still be used by the type checker to track the actual objects without importing the objects from either class? I'm thinking of creating a separate module called types and put the types there, but I can't figure out how to map the types I'll create to the objects in those two files so that they can be used without circular import errors. Perhaps if there's some runtime check that can be done, I'm not so sure. _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: peilonrayz@gmail.com