Skip to content

Commit 3c8e545

Browse files
committed
Keep Optional and union in valid_static_types
I'm keeping them here so as to avoid a potential bug, it's used in type checking and it makes sense to keep it, I've added a second type for Union using UnionType. Consistency with the placement of None for optional arguments has also been improved. Signed-off-by: Chihurumnaya Ibiam <ibiamchihurumnaya@gmail.com>
1 parent 5caa0c3 commit 3c8e545

File tree

3 files changed

+6
-228
lines changed

3 files changed

+6
-228
lines changed

osprey_worker/src/osprey/engine/ast/grammar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class Assign(Statement, IsConstant, IsExtractable):
350350

351351
target: Name
352352
value: Expression
353-
annotation: None | 'Annotation' | 'AnnotationWithVariants' = None
353+
annotation: 'Annotation' | 'AnnotationWithVariants' | None = None
354354

355355
@cached_property
356356
def should_extract(self) -> bool:
@@ -411,7 +411,7 @@ class Call(Expression, Statement):
411411
func: Name | 'Attribute'
412412
arguments: Sequence['Keyword']
413413

414-
def find_argument(self, name: str) -> None | 'Keyword':
414+
def find_argument(self, name: str) -> 'Keyword' | None:
415415
for argument in self.arguments:
416416
if argument.name == name:
417417
return argument

osprey_worker/src/osprey/engine/ast_validator/validators/validate_static_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import dataclass, replace
33
from functools import lru_cache
44
from types import UnionType
5-
from typing import TYPE_CHECKING, Any, Type, cast
5+
from typing import TYPE_CHECKING, Any, Optional, Type, Union, cast
66

77
from osprey.engine.ast import grammar
88
from osprey.engine.ast.error_utils import SpanWithHint
@@ -452,9 +452,9 @@ def _is_optional_type(self, t: type) -> bool:
452452

453453
# We allow Entities to typecheck as optional in order to avoid having to update the type system
454454
# to support Optional[Entity[str]]
455-
if origin is None or origin is EntityT:
455+
if origin is Optional or origin is EntityT:
456456
return True
457-
elif origin is UnionType:
457+
elif origin is Union or origin is UnionType:
458458
return type(None) in t.__args__ # type: ignore[attr-defined]
459459

460460
return False
@@ -613,7 +613,7 @@ def _validate_format_string(self, format_string: grammar.FormatString) -> type:
613613
accepted_types_str = ', '.join(to_display_str(arg) for arg in accepted_types)
614614
self._check_compatible_type(
615615
type_t=name_type,
616-
accepted_by_t=cast(type, accepted_types),
616+
accepted_by_t=cast(type, Union[accepted_types]),
617617
message='unsupported type for f-string substitution',
618618
node=name,
619619
hint=f'has type {name_type_str}, expected one of {accepted_types_str}',

osprey_worker/src/osprey/worker/ui_api/osprey/views/tests/test_saved_queries.py

Lines changed: 0 additions & 222 deletions
This file was deleted.

0 commit comments

Comments
 (0)