- Sort Score
- Num 10 results
- Language All
Results 1 - 10 of 56 for Union (0.02 seconds)
The search processing time has exceeded the limit. The displayed results may be partial.
-
docs/zh/docs/advanced/advanced-python-types.md
# 高级 Python 类型 { #advanced-python-types } 这里有一些在使用 Python 类型时可能有用的额外想法。 ## 使用 `Union` 或 `Optional` { #using-union-or-optional } 如果你的代码因为某些原因不能使用 `|`,例如它不是在类型注解里,而是在 `response_model=` 之类的参数中,那么你可以使用 `typing` 中的 `Union` 来代替竖线(`|`)。 例如,你可以声明某个值可以是 `str` 或 `None`: ```python from typing import Union def say_hi(name: Union[str, None]): print(f"Hi {name}!") ``` `typing` 也提供了一个声明“可能为 `None`”的快捷方式:`Optional`。Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Feb 13 13:37:57 GMT 2026 - 2K bytes - Click Count (0) -
docs/ja/docs/advanced/advanced-python-types.md
# 高度な Python の型 { #advanced-python-types } Python の型を扱うときに役立つ追加のアイデアをいくつか紹介します。 ## `Union` または `Optional` の利用 { #using-union-or-optional } 何らかの理由で `|` が使えない場合、たとえば型アノテーションではなく `response_model=` のような場所では、縦棒(`|`)の代わりに `typing` の `Union` を使えます。 例えば、`str` または `None` になり得ることを宣言できます: ```python from typing import Union def say_hi(name: Union[str, None]): print(f"Hi {name}!") ```Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Fri Feb 13 15:24:30 GMT 2026 - 2.4K bytes - Click Count (0) -
fastapi/_compat/shared.py
return True origin = get_origin(annotation) if origin is Union or origin is UnionType: for arg in get_args(annotation): if lenient_issubclass(arg, UploadFile): return True return False def is_bytes_sequence_annotation(annotation: Any) -> bool: origin = get_origin(annotation) if origin is Union or origin is UnionType: at_least_one = FalseCreated: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Wed Feb 11 18:32:12 GMT 2026 - 6.9K bytes - Click Count (0) -
docs/en/docs/tutorial/extra-models.md
## `Union` or `anyOf` { #union-or-anyof } You can declare a response to be the `Union` of two or more types, that means, that the response would be any of them. It will be defined in OpenAPI with `anyOf`. To do that, use the standard Python type hint [`typing.Union`](https://docs.python.org/3/library/typing.html#typing.Union): /// noteCreated: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 05 18:13:19 GMT 2026 - 6.7K bytes - Click Count (0) -
tests/test_response_model_as_return_annotation.py
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Tue Feb 17 09:59:14 GMT 2026 - 50.3K bytes - Click Count (0) -
docs/ko/docs/advanced/advanced-python-types.md
Python 타입을 다룰 때 유용할 수 있는 몇 가지 추가 아이디어를 소개합니다. ## `Union` 또는 `Optional` 사용 { #using-union-or-optional } 어떤 이유로 코드에서 `|`를 사용할 수 없다면, 예를 들어 타입 어노테이션이 아니라 `response_model=` 같은 곳이라면, 파이프 문자(`|`) 대신 `typing`의 `Union`을 사용할 수 있습니다. 예를 들어, 어떤 값이 `str` 또는 `None`이 될 수 있다고 선언할 수 있습니다: ```python from typing import Union def say_hi(name: Union[str, None]): print(f"Hi {name}!") ```Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sat Feb 14 08:57:01 GMT 2026 - 2.4K bytes - Click Count (0) -
tests/test_compat.py
def test_serialize_sequence_value_with_none_first_in_union(): """Test that serialize_sequence_value handles Union[None, List[...]] correctly.""" from typing import Union from fastapi._compat import v2 # Use Union[None, list[str]] to ensure None comes first in the union args field_info = FieldInfo(annotation=Union[None, list[str]]) # noqa: UP007 field = v2.ModelField(name="items", field_info=field_info)
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Tue Feb 17 09:59:14 GMT 2026 - 4.2K bytes - Click Count (0) -
docs/en/docs/python-types.md
#### Union { #union } You can declare that a variable can be any of **several types**, for example, an `int` or a `str`. To define it you use the <dfn title='also called "bitwise or operator", but that meaning is not relevant here'>vertical bar (`|`)</dfn> to separate both types. This is called a "union", because the variable can be anything in the union of those two sets of types.Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Thu Mar 05 18:13:19 GMT 2026 - 11K bytes - Click Count (0) -
fastapi/dependencies/utils.py
def is_union_of_base_models(field_type: Any) -> bool: """Check if field type is a Union where all members are BaseModel subclasses.""" from fastapi.types import UnionType origin = get_origin(field_type) # Check if it's a Union type (covers both typing.Union and types.UnionType in Python 3.10+) if origin is not Union and origin is not UnionType: return False union_args = get_args(field_type)
Created: Sun Apr 05 07:19:11 GMT 2026 - Last Modified: Sun Mar 15 11:44:39 GMT 2026 - 38.7K bytes - Click Count (3) -
android/guava/src/com/google/common/collect/ImmutableRangeSet.java
: result; } /** * Returns a new range set consisting of the union of this range set and {@code other}. * * <p>This is essentially the same as {@code TreeRangeSet.create(this).addAll(other)} except it * returns an {@code ImmutableRangeSet}. * * @since 21.0 */ public ImmutableRangeSet<C> union(RangeSet<C> other) { return unionOf(Iterables.concat(asRanges(), other.asRanges())); }Created: Fri Apr 03 12:43:13 GMT 2026 - Last Modified: Tue Mar 17 16:45:58 GMT 2026 - 27.5K bytes - Click Count (0)