From 1a9f046fe253369057328383ec13ea05c187cf51 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 6 Nov 2024 14:30:32 +0200 Subject: [PATCH] Try to fix cyclic import for typing. --- mesonbuild/arglist.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mesonbuild/arglist.py b/mesonbuild/arglist.py index 54d7157e2ccf..6f04fa7a16c8 100644 --- a/mesonbuild/arglist.py +++ b/mesonbuild/arglist.py @@ -11,10 +11,6 @@ import re import typing as T -if T.TYPE_CHECKING: - from .linkers.linkers import StaticLinker - from .compilers import Compiler - # execinfo is a compiler lib on BSD UNIXY_COMPILER_INTERNAL_LIBS = ['m', 'c', 'pthread', 'dl', 'rt', 'execinfo'] @@ -94,9 +90,12 @@ class CompilerArgs(T.MutableSequence[str]): # TODO: these should probably move too always_dedup_args = tuple('-l' + lib for lib in UNIXY_COMPILER_INTERNAL_LIBS) - def __init__(self, compiler: T.Union['Compiler', 'StaticLinker'], - iterable: T.Optional[T.Iterable[str]] = None): - self.compiler = compiler + def __init__(self, compiler: T.Any, iterable: T.Optional[T.Iterable[str]] = None): + # Must be here to avoid cyclic import. + from .linkers.linkers import StaticLinker + from .compilers import Compiler + assert isinstance(compiler, (StaticLinker, Compiler)) + self.compiler: T.Union['Compiler', 'StaticLinker'] = compiler self._container: T.List[str] = list(iterable) if iterable is not None else [] self.pre: T.Deque[str] = collections.deque() self.post: T.Deque[str] = collections.deque()