Skip to content

Instantly share code, notes, and snippets.

from typing import Any, Callable, Optional, TypeVar, Tuple, Dict, Protocol
R = TypeVar('R', covariant=True) # Return type of the function
T = TypeVar('T') # Type of instance (for methods)
class FuncProtocol(Protocol[R]):
def __call__(self, *args: Any, **kwargs: Any) -> R: ...
def decorator(
wrapper: Callable[
--- juju/client/schemas-juju-3.1.0.txt 2024-09-25 14:45:35
+++ juju/client/schemas-juju-3.3.0.txt 2024-09-25 14:45:35
@@ -309,6 +309,7 @@
.macaroons[0][0]: Macaroon
.macaroons[0][0]: dict[Any, Any]
.nonce: str
+.token: str
.user-data: str
out: LoginResult
.bakery-discharge-required: Macaroon
This file has been truncated, but you can view the full file.
--- 310.gr.txt 2024-09-25 14:51:09
+++ 330.gr.txt 2024-09-25 14:51:14
@@ -562,6 +562,8 @@
json[2].Schema.definitions.LoginRequest.properties.macaroons.type = "array";
json[2].Schema.definitions.LoginRequest.properties.nonce = {};
json[2].Schema.definitions.LoginRequest.properties.nonce.type = "string";
+json[2].Schema.definitions.LoginRequest.properties.token = {};
+json[2].Schema.definitions.LoginRequest.properties.token.type = "string";
json[2].Schema.definitions.LoginRequest.properties["auth-tag"] = {};
json[2].Schema.definitions.LoginRequest.properties["auth-tag"].type = "string";
@dimaqq
dimaqq / test_main_type_hint.py
Last active August 30, 2024 06:30
Type tests using pyright
from dataclasses import dataclass
from typing import Optional, Protocol, Type
import ops
class CallableWithCharmClassOnly(Protocol):
"""Encapsulate main function type for simple charms.
@dimaqq
dimaqq / test_main_invocations.py
Last active August 30, 2024 06:31
Type tests via custom type guard
import ... # exinsting code
@pytest_fixture
def charm_env(monkeypatch, ...): # existing code
...
from typing import Type, TypeVar, Any, Optional, Callable, Mapping
from typing_extensions import TypeGuard
import inspect
@dimaqq
dimaqq / ops __init__.py
Last active August 28, 2024 01:17
Fixing ops.main() type hints, the protocol version
from typing import Protocol, cast
import ._main
import .main as _legacy_main
class Main(Protocol):
def __call__(self, arg1: Arg1, ...): ...
def main(self, arg1: Arg1, ...): ...
main = cast(Main, _main.main)
main.main = _legacy_main.main
@dimaqq
dimaqq / ops __init__.py
Last active August 28, 2024 01:09
Fixing ops.main() type hints, the callable class version
import ._main
import .main as _legacy_main
class Main:
__call__ = staticmethod(_main.main)
main = staticmethod(_legacy_main.main)
main = Main()
@dimaqq
dimaqq / ops __init__.py
Last active August 28, 2024 01:07
Fixing ops.main() type hints, the callable module version
import .main as _main
main = _main._CallableMainModule('ops.main', _main.__doc__)

Totally OT: if you wanna test nogil out:

  • macos 3.13b2 installer includes the nogil build, needs to be exp[licitly selected
    • at "Installation type" click "Customise" instead of "Install"
  • ubuntu (and similar), the deadsnakes project apparently ships nogil versions too
    • apt/nala install python3.13-nogil
  • GitHub actions, via deadsnakes/[email protected] with nogil:true
{
"Profiles": [
{
"Ansi 7 Color (Light)" : {
"Red Component" : 0.93333333333333335,
"Color Space" : "sRGB",
"Blue Component" : 0.83529411764705885,
"Green Component" : 0.90980392156862744
},
"Ansi 15 Color (Light)" : {