Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[inventory][chore] Bump libs #2270

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fixcore/fixcore/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def parse_time_or_delta(time_or_delta: str) -> datetime:

def js_value_get(element: JsonElement, path_or_name: Union[List[str], str], if_none: AnyT) -> AnyT:
result = js_value_at(element, path_or_name)
return result if result and isinstance(result, type(if_none)) else if_none # type: ignore
return result if result and isinstance(result, type(if_none)) else if_none


def js_value_at(element: JsonElement, path_or_name: Union[List[str], str]) -> Optional[Any]:
Expand Down
8 changes: 4 additions & 4 deletions fixcore/fixcore/cli/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def __init__(

async def source(self) -> Tuple[CLISourceContext, JsStream]:
res = self._fn()
context, gen = await res if iscoroutine(res) else res
context, gen = await res if iscoroutine(res) else res # type: ignore
return context, self.make_stream(await gen if iscoroutine(gen) else gen)

@staticmethod
Expand All @@ -273,7 +273,7 @@ def only_count(
) -> CLISource:
async def combine() -> Tuple[CLISourceContext, JsGen]:
res = fn()
count, gen = await res if iscoroutine(res) else res
count, gen = await res if iscoroutine(res) else res # type: ignore
return CLISourceContext(count=count, total_count=count), gen

return CLISource(combine, produces, requires, envelope, required_permissions)
Expand All @@ -299,7 +299,7 @@ def with_count(
) -> CLISource:
async def combine() -> Tuple[CLISourceContext, JsGen]:
res = fn()
gen = await res if iscoroutine(res) else res
gen: JsGen = await res if iscoroutine(res) else res # type: ignore
return CLISourceContext(count=count), gen

return CLISource(combine, produces, requires, envelope, required_permissions)
Expand Down Expand Up @@ -333,7 +333,7 @@ def __init__(

async def flow(self, in_stream: JsGen) -> JsStream:
gen = self._fn(self.make_stream(in_stream))
return self.make_stream(await gen if iscoroutine(gen) else gen)
return self.make_stream(await gen if iscoroutine(gen) else gen) # type: ignore


@define
Expand Down
2 changes: 1 addition & 1 deletion fixcore/fixcore/db/async_arangodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
self.visited_edge: Set[str] = set()
self.deferred_edges: List[Json] = []
self.cursor_exhausted = False
self.trafo: Callable[[Json], Optional[Any]] = trafo if trafo else identity # type: ignore
self.trafo: Callable[[Json], Optional[Any]] = trafo if trafo else identity
self.vt_len: Optional[int] = None
self.on_hold: Optional[Json] = None
self.get_next: Callable[[], Awaitable[Optional[Json]]] = (
Expand Down
2 changes: 1 addition & 1 deletion fixcore/fixcore/db/graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ async def execute_many_async(
) -> None:
if array:
async_fn_with_args = partial(async_fn, **kwargs) if kwargs else async_fn
result = await async_fn_with_args(name, array) # type: ignore
result = await async_fn_with_args(name, array)
ex: Optional[Exception] = first(lambda x: isinstance(x, Exception), result)
if ex:
raise ex # pylint: disable=raising-bad-type
Expand Down
2 changes: 1 addition & 1 deletion fixcore/fixcore/model/adjust_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def first_matching(paths: List[List[str]]) -> Optional[str]:
expires = DateTimeKind.from_datetime(expires_tag)
else:
expiration_tag = first_matching(self.expiration_values)
if expiration_tag and expires_tag != "never" and DurationRe.fullmatch(expiration_tag):
if expiration_tag and DurationRe.fullmatch(expiration_tag):
ctime_str = value_in_path(json, NodePath.reported_ctime)
if ctime_str:
ctime = from_utc(ctime_str)
Expand Down
2 changes: 1 addition & 1 deletion fixcore/fixcore/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def if_set(x: Optional[AnyT], func: Callable[[AnyT], Any], if_not: Any = None) -

def value_in_path_get(element: JsonElement, path_or_name: Union[List[str], str], if_none: AnyT) -> AnyT:
result = value_in_path(element, path_or_name)
return result if result is not None and isinstance(result, type(if_none)) else if_none # type: ignore
return result if result is not None and isinstance(result, type(if_none)) else if_none


def path_exists(element: JsonElement, path_or_name: Union[List[str], str]) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion fixcore/tests/fixcore/db/graphdb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ async def test_update_node(filled_graph_db: ArangoGraphDB, foo_model: Model) ->
async def elements(history: bool) -> List[Json]:
fn = filled_graph_db.search_history if history else filled_graph_db.search_list
model = QueryModel(parse_query("ancestors.account.reported.name==bat"), foo_model)
async with await fn(query=model) as crs: # type: ignore
async with await fn(query=model) as crs:
return [e async for e in crs]

assert len(await elements(False)) == 111
Expand Down
2 changes: 1 addition & 1 deletion fixlib/fixlib/asynchronous/web/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def _run_app(
sites: List[BaseSite] = []

def with_port(port: int, ssl: Optional[SSLContext] = None) -> None:
if isinstance(host, (str, bytes, bytearray, memoryview)):
if isinstance(host, (str, bytes, bytearray)):
sites.append(
TCPSite(
runner,
Expand Down
4 changes: 2 additions & 2 deletions fixlib/fixlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def add_config(config: object) -> None:
Config.running_config.classes[config.kind] = config # type: ignore
Config.running_config.types[config.kind] = {}
for field in fields(config): # type: ignore
if hasattr(field, "type"):
Config.running_config.types[config.kind][field.name] = optional_origin(field.type)
if hasattr(field, "type") and isinstance(origin := optional_origin(field.type), type):
Config.running_config.types[config.kind][field.name] = origin
else:
raise RuntimeError("Config must have a 'kind' attribute")

Expand Down
28 changes: 14 additions & 14 deletions fixlib/fixlib/core/model_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,43 @@


# List[X] -> list, list -> list
def optional_origin(clazz: Type[Any]) -> Type[Any]:
def optional_origin(clazz: Union[type, Tuple[Any], None]) -> Union[type, Tuple[Any], None]:
maybe_optional = get_args(clazz)[0] if is_optional(clazz) else clazz
origin = get_origin(maybe_optional)
return origin if origin else maybe_optional # type: ignore
return origin if origin else maybe_optional


# Optional[x] -> true
def is_optional(clazz: Union[type, Tuple[Any]]) -> bool:
def is_optional(clazz: Union[type, Tuple[Any], None]) -> bool:
args = get_args(clazz)
return get_origin(clazz) is Union and type(None) in args and len(args) == 2


# List[x] -> true, list -> true
def is_collection(clazz: type) -> bool:
def is_collection(clazz: Union[type, Tuple[Any], None]) -> bool:
return optional_origin(clazz) in [list, set, tuple]


# Dict[x,y] -> true, dict -> true
def is_dict(clazz: type) -> bool:
def is_dict(clazz: Union[type, Tuple[Any], None]) -> bool:
return optional_origin(clazz) in [dict]


# either enum or optional enum
def is_enum(clazz: type) -> bool:
def is_enum(clazz: Union[type, Tuple[Any], None]) -> bool:
origin = optional_origin(clazz)
return isinstance(origin, type) and issubclass(origin, Enum)


# List[X] -> X, list -> object
def type_arg(clazz: type) -> type:
def type_arg(clazz: Union[type, Tuple[Any], None]) -> type:
maybe_optional = get_args(clazz)[0] if is_optional(clazz) else clazz
args = get_args(maybe_optional)
return args[0] if args and len(args) == 1 else object # type: ignore
return args[0] if args and len(args) == 1 else object


# Dict[X,Y] -> (X,Y), dict -> (object, object)
def dict_types(clazz: type) -> Tuple[type, type]:
def dict_types(clazz: Union[type, Tuple[Any], None]) -> Tuple[type, type]:
maybe_optional = get_args(clazz)[0] if is_optional(clazz) else clazz
args = get_args(maybe_optional)
return (args[0], args[1]) if args and len(args) == 2 else (object, object)
Expand All @@ -76,7 +76,7 @@ def check(to_check: type) -> None:
check(value_type)
elif is_collection(clazz):
check(type_arg(to_check))
elif attrs.has(clazz):
elif isinstance(clazz, type) and attrs.has(clazz):
if getattr(clazz, "_model_export", True) is False:
return
resolve_types(clazz)
Expand All @@ -91,7 +91,7 @@ def check(to_check: type) -> None:
continue
check(field.type)
elif is_enum(clazz):
all_classes.add(clazz)
all_classes.add(clazz) # type: ignore

for c in classes:
check(c)
Expand Down Expand Up @@ -123,7 +123,7 @@ def model_name(clazz: Union[type, Tuple[Any], None]) -> str:
return f"dictionary[{model_name(key_type)}, {model_name(value_type)}]"
elif is_enum(to_check):
# camel case to snake case
return re.sub(r"(?<!^)(?=[A-Z])", "_", to_check.__name__).lower()
return re.sub(r"(?<!^)(?=[A-Z])", "_", to_check.__name__).lower() # type: ignore
elif get_origin(to_check) == Union:
# this is a union of different types other than none.
# since union types are not supported, we fallback to any here
Expand All @@ -132,7 +132,7 @@ def model_name(clazz: Union[type, Tuple[Any], None]) -> str:
return model_name(get_args(to_check))
elif isinstance(to_check, type) and issubclass(to_check, simple_type):
return lookup[to_check]
elif attrs.has(to_check):
elif isinstance(to_check, type) and attrs.has(to_check):
name = getattr(to_check, "kind", None)
if not name:
raise AttributeError(f"dataclass {to_check} need to define a ClassVar kind!")
Expand Down Expand Up @@ -191,7 +191,7 @@ def prop(field: Attribute) -> List[Json]: # type: ignore
kind = meta.pop("type_hint", model_name(field.type))
desc = meta.pop("description", None)
desc = desc if with_prop_description else None
required = meta.pop("required", use_optional_as_required and not is_optional(field.type)) # type: ignore
required = meta.pop("required", use_optional_as_required and not is_optional(field.type))
synthetic = meta.pop("synthetic", None)
synthetic = synthetic if synthetic else {}
for ps in property_metadata_to_strip:
Expand Down
1 change: 1 addition & 0 deletions fixlib/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies = [
"prometheus-client",
"psutil",
"python-dateutil",
"pytz==2024.1", # https://github.com/stub42/pytz/issues/130
"requests",
"typeguard",
"tzdata",
Expand Down
2 changes: 1 addition & 1 deletion plugins/gcp/fix_plugin_gcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def collect(self) -> None:
len(credentials) if len(credentials) < Config.gcp.project_pool_size else Config.gcp.project_pool_size
)
collect_args = {}
pool_args = {"max_workers": max_workers}
pool_args: Dict[str, Any] = {"max_workers": max_workers}
pool_executor = futures.ThreadPoolExecutor
if Config.gcp.fork_process:
collect_args = {
Expand Down
Loading
Loading