# Making \`as\` an operator

**URL:** <https://discuss.python.org/t/making-as-an-operator/44863>\
**Category:** Ideas\
**Created:** [February 2, 2024, 3:08pm UTC](https://discuss.python.org/t/making-as-an-operator/44863 "2024-02-02T15:08:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bschubert](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bschubert/32/26920_2.png) [@bschubert](https://discuss.python.org/u/bschubert)\
**Post date:** [February 2, 2024, 3:22pm UTC](https://discuss.python.org/t/making-as-an-operator/44863/2 "2024-02-02T15:22:25Z")

</div>

Related previous discussions:

> [@Cast syntax for static typing](https://discuss.python.org/t/cast-syntax-for-static-typing/25174):
>
> Currently to cast from one type to another in typing you have to use the function typing.cast which requires a runtime cost and is not very pleasant to use. i propose a built-in syntax for this: a as Type this re-uses the as keyword from imports and with statements, this is better over the existing typing.cast because it can be a no-op at runtime removing the runtime cost and is a lot cleaner of a syntax, Typescript uses the same syntax for the same purpose as well[1](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions). I have a draft PEP for th…

> [@typing.Cast as an annotation alternative to typing.cast](https://discuss.python.org/t/typing-cast-as-an-annotation-alternative-to-typing-cast/20943):
>
> typing.cast is very helpful and I find myself using it quite a lot when trying to be type-safe (especially when converting old code). However, it always bothered me that the only way to cast types is during runtime by calling an empty function which hurts performance for the sake of type-checkers that do everything else statically using annotations. My suggestion is to add a way to cast types using annotations. Instead of: from typing import cast a = cast(str, b) We could do: from typing …

> [@Type conversions using as](https://discuss.python.org/t/type-conversions-using-as/22362):
>
> I think type conversions would be better with using ‘as’ or ‘to’ Rust example let my\_int = 69 as u8; It makes code more readable

---

_[View the full topic](https://discuss.python.org/t/making-as-an-operator/44863)._
