from Annotated import Annotated, Union, Optional
def greet(name: Annotated[str, "The name of the person"]) -> str:
return "Hello, " + name
def add(a: int, b: int) -> int:
return a + b
def divide(a: int, b: Annotated[int, "The divisor"], *, remainder: Optional[bool] = False) -> Union[int, float]:
if remainder:
return a % b
else:
return a / b
from typing import Annotated, Union, Optional
def greet(name: Annotated[str, "The name of the person"]) -> str:
return "Hello, " + name
def divide(a: int, b: Annotated[int, "The divisor"], *, remainder: Optional[bool] = False) -> Union[int, float]:
if remainder:
return a % b
else:
return a / b
result = greet("Alice")
print(result) # 输出:Hello, Alice
result = divide(10, 3)
print(result) # 输出:3.3333333333333335
result = divide(10, 3, remainder=True)
print(result) # 输出:1
from typing import TypedDict,TypedDict, Annotated, Sequence from langgraph.graph import StateGraph, END from langgraph.graph import add_messages from langchain_core.messages import BaseMessage from langchain_openai import ChatOpenAI from langgraph.prebuilt import ToolNode from langchain_community.tools.tavily_search import TavilySearchResults class AgentState(TypedDict):` `messages: Annotated[Sequence[BaseMessage], add_messages]
class Person:
def __init__(self, name):
self._name = name
@property
def name(self):
return self._name
# 创建 Person 对象
person = Person("John")
print(person.name) # 输出: John
from abc import ABC, abstractmethod
class Graphic(ABC):
@abstractmethod
def draw(self):
pass
def add(self, graphic):
raise NotImplementedError("This method is not supported")
def remove(self, graphic):
raise NotImplementedError("This method is not supported")
def get_child(self, index):
raise NotImplementedError("This method is not supported")
定义叶子
class Circle(Graphic):
def draw(self):
print("Drawing a circle")
class Square(Graphic):
def draw(self):
print("Drawing a square")
定义组合
class CompositeGraphic(Graphic):
def __init__(self):
self.children = []
def draw(self):
for child in self.children:
child.draw()
def add(self, graphic):
self.children.append(graphic)
def remove(self, graphic):
self.children.remove(graphic)
def get_child(self, index):
return self.children[index]
使用组合模式
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service import time import undetected_chromedriver as uc
首先,Client Hello在扩展字段里标明了支持的TLS版本(Supported Version:TLS1.3)。值得注意的是Version字段必须要是TLS1.2,这是因为TLS1.2已经在互联网上存在了10年。网络中大量的网络中间设备都十分老旧,这些网络设备会识别中间的TLS握手头部,所以TLS1.3的出现如果引入了未知的TLS Version 必然会存在大量的握手失败。