1. ã¯ããã«
Pythonã¯ããã®æè»æ§ãšäœ¿ãããããããåå¿è ãããããã§ãã·ã§ãã«ãŸã§å¹ åºãå±€ã«æ¯æãããŠããããã°ã©ãã³ã°èšèªã§ããããããPythonã®ãåçåä»ãããšããç¹æ§ããæã«ããã°ã©ã ã®å¯èªæ§ãä¿å®æ§ã«åœ±é¿ãäžããããšããããŸããããã«å¯Ÿå¿ãããããPython 3.5以éã§ã¯ãåãã³ãïŒType HintsïŒããå°å ¥ãããŸããã
ãã®åãã³ãã䜿çšããããšã§ãã³ãŒãã®å¯èªæ§ãå質ãåäžãããéçºã®å¹çãé«ããããšãå¯èœã§ãããã®èšäºã§ã¯ãPythonã®ãåãã³ããã掻çšãããåŒæ°ã®åæå®ãã«ã€ããŠãåºç€ããå®è·µçãªæŽ»çšæ³ãŸã§ã解説ããŠãããŸãã
Pythonã®åçåä»ãã®ç¹åŸŽ
Pythonã®ç¹åŸŽã®äžã€ã«ãå€æ°ãé¢æ°ã®åãæ瀺çã«æå®ããªããŠãåäœãããåçåä»ããããããŸããäŸãã°ã以äžã®ãããªã³ãŒãã¯Pythonã§ã¯åé¡ãªãåäœããŸãã
def add(a, b):
return a + b
result = add(1, 2) # æ£åžžã«åäœ
ãã®æè»æ§ã«ãããçŽ æ©ããããã¿ã€ãã³ã°ãéçºãè¡ããå©ç¹ããããŸãããäžæ¹ã§ä»¥äžã®ãããªåé¡ãçºçããããšããããŸãã
- é¢æ°ã®åŒæ°ãæ»ãå€ã®åãäžæ確ã§ã誀ã£ã䜿ãæ¹ãããŠããšã©ãŒã«ãªããªã
- ãããžã§ã¯ãã倧èŠæš¡åãããšãåã®æšæž¬ãå°é£ã«ãªãããã°ãå¢å ããå¯èœæ§ããã
åãã³ãå°å ¥ã®èæ¯
ããããåé¡ã解決ããããã«å°å ¥ãããåãã³ãã¯ãã³ãŒãã«åæ å ±ãè¿œå ããä»çµã¿ã§ããããã«ããã次ã®ãããªã¡ãªãããåŸãããŸãã
- å¯èªæ§ã®åäž: åæ å ±ãæ瀺ãããããšã§ãé¢æ°ãå€æ°ã®åœ¹å²ãåããããããªã
- éç解æããŒã«ã®æŽ»çš: mypyãªã©ã®ããŒã«ã䜿ãããšã§ãå®è¡åã«åãšã©ãŒãæ€åºå¯èœ
- éçºå¹çã®åäž: IDEã«ããè£å®æ©èœã匷åãããããå¹ççã«ã³ãŒããæžãããšãã§ãã
ãã®èšäºã§ã¯ãPythonã®åãã³ãã䜿ã£ãåŒæ°ã®åæå®æ¹æ³ãäžå¿ã«ãå ·äœäŸã亀ããŠè§£èª¬ããŠãããŸãã次ã®ã»ã¯ã·ã§ã³ã§ã¯ãåãã³ããšã¯äœããã«ã€ããŠãããã«è©³ããèŠãŠãããŸãããã
2. åãã³ããšã¯ïŒ
Pythonã®ãåãã³ãïŒType HintsïŒãã¯ãé¢æ°ãå€æ°ã®åæ å ±ãã³ãŒãäžã«èšè¿°ããä»çµã¿ã§ããããã«ãããã³ãŒãã®æå³ãæ確ã«ããéç解æããŒã«ãIDEãããã°ã©ã ã®åãã§ãã¯ãå®è¡ã§ããããã«ãªããŸããPython 3.5ã§PEP 484ã«ãã£ãŠå°å ¥ããã以éã®ããŒãžã§ã³ã§æ©èœãæ¡åŒµãããŠããŸããã
åãã³ãã®åœ¹å²
åãã³ãã®ç®çã¯ãããã°ã©ã ã®å®è¡äžã«ãšã©ãŒãæ€ç¥ããã®ã§ã¯ãªããã³ãŒãã®èšè¿°æç¹ã§ãšã©ãŒãé²ãããšã§ããç¹ã«ã以äžã®ãããªå Žé¢ã§åãã³ãã¯åœ¹ç«ã¡ãŸãã
- ã³ãŒãã®å¯èªæ§åäž: åãæ瀺ãããããšã§ãé¢æ°ãå€æ°ã®åœ¹å²ãäžç®ã§ãããã
- ããŒã éçºã®å¹çå: éçºè éã§ã®èª€è§£ãæžãããã³ãŒãã¬ãã¥ãŒãã¹ã ãŒãºã«ãªãã
- éç解æã®æŽ»çš: mypyãPyCharmãªã©ã®ããŒã«ã§åãšã©ãŒãäºåã«æ€åºã§ããã
åãã³ãã®èšè¿°äŸ
åãã³ãã䜿ããšã以äžã®ããã«åŒæ°ãæ»ãå€ã®åãæ瀺çã«æå®ã§ããŸãã
é¢æ°ã®åãã³ã
def greet(name: str) -> str:
return f"Hello, {name}!"
ãã®ã³ãŒãã§ã¯ãname
ã¯æååïŒstr
ïŒåã§ããããšãé¢æ°ã®æ»ãå€ãæåååã§ããããšãæ瀺ãããŠããŸããåãã³ãããªãå Žåãšæ¯ã¹ãŠãé¢æ°ã®æå³ãã¯ã£ããããŸãã
å€æ°ã®åãã³ã
Python 3.6以éã§ã¯ãå€æ°ã«ãåãã³ããèšè¿°ã§ããŸãã
age: int = 25
names: list = ["Alice", "Bob", "Charlie"]
åãã³ãã®ç¹åŸŽ
åãã³ãã¯ãããŸã§ããã³ããã§ãããPythonã®åçåä»ãã®æ§è³ªãå€ãããã®ã§ã¯ãããŸãããããšãã°ãåãäžèŽããªããŠããšã©ãŒã«ã¯ãªããŸããã
åãäžèŽããªãäŸ
def add_numbers(a: int, b: int) -> int:
return a + b
result = add_numbers(10, "20") # å®è¡æã«ã¯ãšã©ãŒã«ãªããªã
äžèšã®ã³ãŒãã¯å®è¡æã«ãšã©ãŒã«ãªããŸãããéç解æããŒã«ïŒäŸãã°mypyïŒã䜿çšããã°ãäºåã«ãšã©ãŒãæ€åºã§ããŸãã
éç解æããŒã«ã§ã®æ€åºäŸ
mypyã䜿ããšã次ã®ããã«åã®äžäžèŽãææããŠãããŸãã
error: Argument 2 to "add_numbers" has incompatible type "str"; expected "int"
åãã³ãã®å©ç¹ãšéç
å©ç¹
- ã³ãŒãã®å¯èªæ§ãåäžããã
- IDEã§ã®è£å®æ©èœã匷åãããã
- éç解æããŒã«ã䜿ã£ãŠäºåã«ãã°ãé²ãããšãã§ããã
éç
- å®è¡æã«ã¯åã匷å¶ãããªãïŒéç解æããŒã«ãå¿ èŠïŒã
- è€éãªåæå®ãå¿ èŠãªå Žåãèªã¿ã¥ãããå¢ãå¯èœæ§ãããã
åãã³ãã®å°å ¥ã«ããã泚æç¹
- åãã³ãã¯æ®µéçã«å°å
¥ãã
æ¢åã®å€§èŠæš¡ãããžã§ã¯ãã§ã¯ãäžéšã®é¢æ°ãã¢ãžã¥ãŒã«ããåãã³ããå°å ¥ããã®ãããããã§ãã - ç
©éãªåæå®ãé¿ãã
å¿ èŠä»¥äžã«è€éãªåæå®ã¯å¯èªæ§ãæãªããããç°¡æœããä¿ã€ããšãéèŠã§ãã - éç解æããŒã«ã掻çšãã
åãã³ããå°å ¥ããå Žåã¯ãmypy
ãpylint
ãªã©ã®ããŒã«ã䜵çšããããšã§å¹æãæ倧åã§ããŸãã
3. åºæ¬çãªåæå®ã®æ¹æ³
Pythonã®åãã³ãã䜿çšããããšã§ãé¢æ°ã®åŒæ°ãæ»ãå€ãå€æ°ã«åãæ瀺çã«æå®ã§ããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãåºæ¬çãªåæå®ã®æ¹æ³ã詳ãã解説ããŸãã
é¢æ°ã®åŒæ°ãšæ»ãå€ã®åæå®
é¢æ°ã®åŒæ°ãæ»ãå€ã«åãã³ããè¿œå ããããšã§ãé¢æ°ãã©ã®ãããªåãåãåããã©ã®ãããªåãè¿ãããæ瀺ã§ããŸãã
åçŽãªåæå®
以äžã¯ãåŒæ°ãšæ»ãå€ã«åãæå®ããã·ã³ãã«ãªäŸã§ãã
def add(a: int, b: int) -> int:
return a + b
a
ãšb
: æŽæ°åïŒint
ïŒãåãåãã- æ»ãå€: æŽæ°åïŒ
int
ïŒãè¿ãã
è€æ°ã®åŒæ°ãæã€å Žå
åãã³ãã¯åŒæ°ãè€æ°ã®å Žåã§ãç°¡åã«äœ¿çšã§ããŸãã
def greet(name: str, age: int) -> str:
return f"Hello, {name}! You are {age} years old."
- ãã®é¢æ°ã§ã¯ãæåååã®
name
ãšæŽæ°åã®age
ãåãåããæåååãè¿ããŸãã
å€æ°ãžã®åæå®
Python 3.6以éã§ã¯ãå€æ°ã«ãåãã³ããèšè¿°ã§ããŸãã
åºæ¬çãªå€æ°ã®åæå®
name: str = "Alice"
age: int = 30
is_student: bool = True
name
: æåååage
: æŽæ°åis_student
: çåœå€åïŒbool
ïŒ
åãæå®ãã€ã€åæå€ãæããªãå€æ°
å€æ°ã®åãæå®ããã ãã§åæå€ãäžããªãå Žåã次ã®ããã«èšè¿°ããŸãã
height: float # åã¯æå®ããŠãããåæå€ã¯ãªã
ãã®å ŽåãåŸã«height
ã«é©åãªåã®å€ã代å
¥ããå¿
èŠããããŸãã
åãã³ãã®çç¥ãšæšè«
Pythonã§ã¯ãåãã³ããèšè¿°ããªããŠãã³ãŒãã¯åäœããŸãããåãã³ãããªããšæå³ãäŒããã«ãããªããŸãã
åãã³ãããªãå Žå
def multiply(a, b):
return a * b
ãã®é¢æ°ã§ã¯ãa
ãb
ã®åãäžæã§ãããã®ãããã³ãŒããèªãéçºè
ãIDEã¯åãæ£ç¢ºã«æšæž¬ã§ããŸããã
åãã³ããè¿œå ããå Žå
def multiply(a: int, b: int) -> int:
return a * b
åãã³ããè¿œå ããããšã§ããã®é¢æ°ãæŽæ°åã®åŒæ°ãåãåããæŽæ°åã®æ»ãå€ãè¿ãããšãæ確ã«ãªããŸãã
ã³ã¬ã¯ã·ã§ã³åãžã®åæå®
Pythonã§ã¯ããªã¹ããèŸæžãªã©ã®ã³ã¬ã¯ã·ã§ã³åã«ãåãã³ããæå®ã§ããŸãããtypingãã¢ãžã¥ãŒã«ã䜿çšããŠèšè¿°ããã®ãäžè¬çã§ãã
ãªã¹ãã®åæå®
ãªã¹ãã®åãã³ãã¯typing
ã¢ãžã¥ãŒã«ã®List
ã䜿çšããŸãã
from typing import List
numbers: List[int] = [1, 2, 3]
èŸæžã®åæå®
èŸæžã®ããŒãšå€ã®åãæå®ããŸãã
from typing import Dict
student_ages: Dict[str, int] = {"Alice": 20, "Bob": 25}
åæå®ã䜿ã£ãé¢æ°ã®äŸ
以äžã¯ãè€æ°ã®åã䜿çšããé¢æ°ã®äŸã§ãã
from typing import List
def calculate_average(grades: List[float]) -> float:
return sum(grades) / len(grades)
grades = [85.5, 90.0, 78.5]
average = calculate_average(grades)
print(f"Average grade: {average}")
ãŸãšã
åãã³ãã䜿çšããããšã§ãã³ãŒãã®æå³ãæ確ã«ãªãããã°ãé²ãããããªããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãåºæ¬çãªåæå®æ¹æ³ã解説ããŸããã次ã¯ãã4. è€éãªããŒã¿æ§é ãžã®åæå®ãã®ã»ã¯ã·ã§ã³ã§ãããé«åºŠãªåæå®æ¹æ³ã«ã€ããŠèª¬æããŸãã
4. è€éãªããŒã¿æ§é ãžã®åæå®
Pythonã§ã¯ããªã¹ããèŸæžãšãã£ãåºæ¬çãªã³ã¬ã¯ã·ã§ã³åã ãã§ãªããã¿ãã«ããã¹ãããæ§é ããªãã·ã§ãã«åãªã©ãè€éãªããŒã¿æ§é ã«ãåãæå®ããããšãã§ããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ããããã®ããŒã¿æ§é ã«å¯Ÿããåãã³ãã®æå®æ¹æ³ã解説ããŸãã
ãªã¹ããšã¿ãã«ã®åæå®
ãªã¹ãã®åæå®
ãªã¹ãã®åãã³ãã¯typing
ã¢ãžã¥ãŒã«ã®List
ã䜿çšããŸããèŠçŽ ã®åãæ瀺ããããšã§ããªã¹ãã®å
容ãããå³å¯ã«æå®ã§ããŸãã
from typing import List
numbers: List[int] = [1, 2, 3, 4]
names: List[str] = ["Alice", "Bob", "Charlie"]
numbers
: æŽæ°åïŒint
ïŒã®ãªã¹ãnames
: æåååïŒstr
ïŒã®ãªã¹ã
ã¿ãã«ã®åæå®
ã¿ãã«ã¯Tuple
ã䜿ã£ãŠåãæå®ããŸããåèŠçŽ ã®åãé çªã«èšè¿°ããããšã§ãç°ãªãåã®èŠçŽ ãæã€ã¿ãã«ãè¡šçŸã§ããŸãã
from typing import Tuple
person: Tuple[str, int] = ("Alice", 25)
- ãã®äŸã§ã¯ã
person
ã¯æåååïŒååïŒãšæŽæ°åïŒå¹Žéœ¢ïŒã®ãã¢ãè¡šããŸãã
èŸæžã®åæå®
èŸæžã®ããŒãšå€ã®åãæ瀺ããå Žåã¯ãDict
ã䜿çšããŸãã
åºæ¬çãªèŸæžã®åæå®
from typing import Dict
student_scores: Dict[str, float] = {"Alice": 95.5, "Bob": 87.0}
- ãã®äŸã§ã¯ãããŒãæåååïŒ
str
ïŒãå€ãæµ®åå°æ°ç¹åïŒfloat
ïŒã§ããããšãæå®ããŠããŸãã
ãã¹ãããèŸæž
èŸæžã®å€ãšããŠå¥ã®èŸæžãå ¥ãå Žåãåãæ瀺ã§ããŸãã
from typing import Dict
class_data: Dict[str, Dict[str, int]] = {
"Class A": {"Alice": 85, "Bob": 90},
"Class B": {"Charlie": 88, "Dave": 92},
}
- ãã®äŸã§ã¯ãå€åŽã®èŸæžã®ããŒã¯ã¯ã©ã¹åïŒ
str
ïŒãå€ã¯çåŸåïŒstr
ïŒãšç¹æ°ïŒint
ïŒã®èŸæžã§ãã
OptionalåãšUnionå
Optionalå
Optional
ã¯ãåŒæ°ãæ»ãå€ããæå®ãããåãŸãã¯None
ããåãåãå Žåã«äœ¿çšããŸãã
from typing import Optional
def find_student(name: str) -> Optional[str]:
students = ["Alice", "Bob", "Charlie"]
return name if name in students else None
- ãã®äŸã§ã¯ã
find_student
é¢æ°ãstr
åãŸãã¯None
ãè¿ãããšãè¡šããŠããŸãã
Unionå
Union
ã䜿ããšãè€æ°ã®åãæå®ããããšãã§ããŸãã
from typing import Union
def calculate(value: Union[int, float]) -> float:
return value * 2.0
- ãã®äŸã§ã¯ã
value
ã¯æŽæ°åïŒint
ïŒãŸãã¯æµ®åå°æ°ç¹åïŒfloat
ïŒãåãåããŸãã
ã«ã¹ã¿ã åãšåãšã€ãªã¢ã¹
åãšã€ãªã¢ã¹
åãšã€ãªã¢ã¹ã䜿ããšãè€éãªåæå®ãç°¡æœã«è¡šçŸã§ããŸãã
from typing import List
Vector = List[float]
def add_vectors(v1: Vector, v2: Vector) -> Vector:
return [x + y for x, y in zip(v1, v2)]
Vector
ã¯æµ®åå°æ°ç¹åã®ãªã¹ãïŒList[float]
ïŒãšããŠå®çŸ©ããŠããŸãã
ã«ã¹ã¿ã ã¯ã©ã¹ãåæå®ãã
ç¬èªã®ã¯ã©ã¹ãåãã³ãã«äœ¿çšã§ããŸãã
class Student:
def __init__(self, name: str, age: int):
self.name = name
self.age = age
def enroll_student(student: Student) -> str:
return f"{student.name} has been enrolled."
- ãã®äŸã§ã¯ã
Student
ã¯ã©ã¹ãåãã³ããšããŠäœ¿çšããŠããŸãã
ãžã§ããªã¯ã¹ã䜿ã£ãåæå®
Generic
ã䜿çšãããšãåå©çšå¯èœãªåãå®çŸ©ã§ããŸãã
from typing import TypeVar, Generic, List
T = TypeVar('T')
class Stack(Generic[T]):
def __init__(self):
self.items: List[T] = []
def push(self, item: T) -> None:
self.items.append(item)
def pop(self) -> T:
return self.items.pop()
- ãã®äŸã§ã¯ãã¹ã¿ãã¯ãä»»æã®åïŒ
T
ïŒãæ±ããããšã瀺ããŠããŸãã
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ããªã¹ããã¿ãã«ãèŸæžãšãã£ãåºæ¬çãªã³ã¬ã¯ã·ã§ã³åãããOptionalåãUnionåãã«ã¹ã¿ã åãšã€ãªã¢ã¹ãŸã§ãè€éãªããŒã¿æ§é ãžã®åæå®æ¹æ³ã解説ããŸãããåãã³ãã䜿ãããšã§ãã³ãŒãã®å¯èªæ§ãšå®å šæ§ãå€§å¹ ã«åäžããŸãã
次ã®ã»ã¯ã·ã§ã³ã5. åãã³ãã®å©ç¹ãšå¶éãã§ã¯ãåãã³ãã®å°å ¥ã«ããã¡ãªãããšèª²é¡ã«ã€ããŠè©³ãã解説ããŸããåŒãç¶ããããããé¡ãããŸãïŒ
5. åãã³ãã®å©ç¹ãšå¶é
Pythonã®åãã³ãã¯ãã³ãŒãã®å質åäžã«å€ãã®ã¡ãªããããããããŸãããããããã®äžæ¹ã§æ³šæãã¹ãå¶éã課é¡ãååšããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãåãã³ãã®å©ç¹ãšå¶éã«ã€ããŠè©³ãã解説ããŸãã
åãã³ãã®å©ç¹
1. ã³ãŒãã®å¯èªæ§ãåäžãã
åãã³ããçšããããšã§ãé¢æ°ãå€æ°ã®ç®çãæ確ã«ãªããã³ãŒãã®å¯èªæ§ã倧å¹
ã«åäžããŸããç¹ã«ããŒã éçºã§ã¯ãä»ã®éçºè
ãã³ãŒããç解ãããããªããŸãã
äŸ:
def calculate_area(length: float, width: float) -> float:
return length * width
- åãã³ãããªãå Žåã
length
ãwidth
ãã©ã®åãæåŸ ããŠãããäžæ確ã§ãããåãã³ãã䜿ãããšã§æ確ã«ãªããŸãã
2. éç解æããŒã«ã§ãã°ãäºåã«çºèŠã§ãã
åãã³ãã掻çšãããšãmypy
ãªã©ã®éç解æããŒã«ãã³ãŒãããã§ãã¯ããåã®äžäžèŽã誀ããäºåã«æ€åºã§ããŸãã
äŸ: åã®äžäžèŽãæ€åºãã
def add(a: int, b: int) -> int:
return a + b
# mypyã«ãããã§ãã¯çµæ:
# error: Argument 2 to "add" has incompatible type "str"; expected "int"
result = add(10, "20") # åãšã©ãŒ
3. IDEã§ã®è£å®æ©èœã匷åããã
åãã³ããèšè¿°ããããšã§ãIDEïŒäŸ: PyCharmãVSCodeïŒãé©åãªè£å®æ©èœãæäŸããŸããããã«ãããéçºå¹çãåäžããééãã®çºçãæžãããŸãã
äŸ:
def greet(name: str) -> str:
return f"Hello, {name}!"
greet("Alice") # IDEãåŒæ°ãæ»ãå€ã®åãèªåè£å®
4. ããã¥ã¡ã³ããšããŠã®åœ¹å²ãæãã
åãã³ãã¯ãã³ãŒãå ã«èšè¿°ãããç°¡æçãªããã¥ã¡ã³ããšããŠæ©èœããŸããéçºè ã¯å€éšããã¥ã¡ã³ããåç §ããªããŠããåæ å ±ãå ã«é¢æ°ã®åäœãç解ã§ããŸãã
åãã³ãã®å¶é
1. å®è¡æã«ã¯åã匷å¶ãããªã
åãã³ãã¯Pythonã®å®è¡æã«åœ±é¿ãäžããªããããåã®äžèŽã¯ãããŸã§éç解æã§ã®ã¿ãã§ãã¯ãããŸããå®è¡æã«ã¯ç¡èŠããããããåã®äžäžèŽã«ãããšã©ãŒã¯é²ããŸããã
äŸ:
def divide(a: int, b: int) -> float:
return a / b
result = divide("10", 2) # å®è¡æã«ã¯ãšã©ãŒ
2. åæå®ãç ©éã«ãªãå Žåããã
è€éãªããŒã¿æ§é ããžã§ããªã¯ã¹ãæ±ãå Žåãåãã³ãã®èšè¿°ãç
©éã«ãªããã³ãŒãã®èªã¿ããããæãªãããããšããããŸãã
äŸ: è€éãªåãã³ã
from typing import Dict, List
data: Dict[str, List[Dict[str, int]]] = {
"group1": [{"name": 5}, {"name": 10}],
"group2": [{"name": 15}],
}
- åã詳现ããããšãå¯èªæ§ãäœäžããæãããããŸãã
3. åŠç¿ã³ã¹ããçºçãã
åãã³ãã«æ
£ããŠããªãåå¿è
ã«ãšã£ãŠã¯ãæ°ããªèšæ³ãšããŠåŠç¿ã³ã¹ããçºçããŸãããŸããtyping
ã¢ãžã¥ãŒã«ã®å€æ§ãªåã®äœ¿ãæ¹ãç解ããå¿
èŠããããŸãã
4. å®è¡é床ã«ã¯åœ±é¿ããªã
åãã³ãã¯å®è¡æã«ã¯ç¡èŠããããããåãå³å¯ã«æå®ããŠãå®è¡é床ãåäžããããã§ã¯ãããŸãããåãã§ãã¯ãå¿ èŠãšããå Žåã¯ãå¥ééç解æããŒã«ã䜿çšããå¿ èŠããããŸãã
åãã³ãã®å°å ¥ã«ããã泚æç¹
- åãã³ãã¯æ®µéçã«å°å
¥ãã
æ¢åã®å€§èŠæš¡ãããžã§ã¯ãã§ã¯ãäžéšã®é¢æ°ãã¢ãžã¥ãŒã«ããåãã³ããå°å ¥ããã®ãããããã§ãã - ç
©éãªåæå®ãé¿ãã
å¿ èŠä»¥äžã«è€éãªåæå®ã¯å¯èªæ§ãæãªããããç°¡æœããä¿ã€ããšãéèŠã§ãã - éç解æããŒã«ã掻çšãã
åãã³ããå°å ¥ããå Žåã¯ãmypy
ãpylint
ãªã©ã®ããŒã«ã䜵çšããããšã§å¹æãæ倧åã§ããŸãã
6. éç解æããŒã«ã䜿ã£ãåãã§ãã¯
Pythonã®åãã³ãã¯å®è¡æã«ã¯åäœã«åœ±é¿ãäžããŸããããéç解æããŒã«ãå©çšããããšã§åã®äžäžèŽãæœåšçãªãã°ãæ€åºããããšãã§ããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãåãã³ããšçžæ§ã®è¯ãéç解æããŒã«ã®ä»£è¡šäŸã§ãããmypyããäžå¿ã«ã掻çšæ¹æ³ã解説ããŸãã
éç解æããŒã«ãšã¯ïŒ
éç解æããŒã«ã¯ãã³ãŒããå®è¡ããããšãªãåãæ§æã®ãã§ãã¯ãè¡ãããŒã«ã§ããåãã³ãã䜿ã£ãéç解æãè¡ãããšã§ã以äžã®ãããªãšã©ãŒãåé¡ãäºåã«çºèŠããããšãã§ããŸãã
- åŒæ°ãæ»ãå€ã®åã®äžäžèŽ
- æªå®çŸ©ã®å€æ°ãé¢æ°ã®åŒã³åºã
- åã®ææ§ãªéšåã®ææ
mypyã®å°å ¥ãšåºæ¬çãªäœ¿ãæ¹
1. mypyã®ã€ã³ã¹ããŒã«
ãŸããpip
ã䜿çšããŠmypyãã€ã³ã¹ããŒã«ããŸãã
pip install mypy
2. mypyã§ã®åãã§ãã¯
åãã³ããå«ãPythonã¹ã¯ãªãããéç解æããŸãã以äžã®ããã«ã³ãã³ããå®è¡ããŸãã
mypy your_script.py
äŸ: 以äžã®ã³ãŒããå«ãã¹ã¯ãªããexample.py
ã解æããå Žå
def add(a: int, b: int) -> int:
return a + b
result = add(10, "20") # åãšã©ãŒ
ã³ãã³ããå®è¡ãããšã次ã®ãããªãšã©ãŒã衚瀺ãããŸãã
error: Argument 2 to "add" has incompatible type "str"; expected "int"
3. mypyã®åºæ¬ãªãã·ã§ã³
mypyã«ã¯ããŸããŸãªãªãã·ã§ã³ãçšæãããŠãããåãã§ãã¯ãæè»ã«ã«ã¹ã¿ãã€ãºã§ããŸãã
--strict
: å³å¯ãªåãã§ãã¯ãæå¹ã«ããã--ignore-missing-imports
: ã€ã³ããŒããšã©ãŒãç¡èŠããã--disallow-untyped-defs
: åãã³ãããªãé¢æ°ãèš±å¯ããªãã
äŸ: å³å¯ãªãã§ãã¯ãæå¹ã«ãã
mypy --strict example.py
IDEã§ã®åãã§ãã¯ã®æŽ»çš
1. PyCharmã§ã®åãã§ãã¯
PyCharmã¯ãåãã³ããšmypyãçµ±åçã«å©çšã§ããIDEã§ããPyCharmã䜿çšãããšã次ã®ãããªã¡ãªããããããŸãã
- ã³ãŒããæžããŠãã段éã§åãšã©ãŒããªã¢ã«ã¿ã€ã ã§æ€åºã
- åãã³ãã«åºã¥ãã³ãŒãè£å®æ©èœã®æäŸã
èšå®æé :
- PyCharmã®ãSettingsãâãLanguages & FrameworksãâãPythonãâãType Hintingãã§åãã³ããæå¹ã«ããã
- å¿ èŠã«å¿ããŠmypyãèšå®ããã
The Python IDE for data science and web development withâŠ
2. Visual Studio Code (VSCode) ã§ã®åãã§ãã¯
VSCodeã§ãåãã³ãããµããŒãããŠããŸãããPythonãæ¡åŒµæ©èœãã€ã³ã¹ããŒã«ããããšã§ãåãã§ãã¯ãè£å®ãå¯èœã«ãªããŸãã
- ãpylanceããšã¯ã¹ãã³ã·ã§ã³ãã€ã³ã¹ããŒã«ãããšãåãã³ãã«åºã¥ããªã¢ã«ã¿ã€ã ã®ãã§ãã¯ãå¯èœã§ãã
åãã§ãã¯ããŒã«ã䜿ã£ãå®è·µäŸ
äŸ1: å¿ é åŒæ°ã®åãã§ãã¯
def greet(name: str) -> str:
return f"Hello, {name}!"
print(greet(123)) # åãšã©ãŒ
mypyã䜿ããšãåŒæ°ã®åãäžèŽããªãããšãææããŠãããŸãã
äŸ2: Optionalåã®ãã§ãã¯
from typing import Optional
def find_student(student_id: int) -> Optional[str]:
students = {1: "Alice", 2: "Bob"}
return students.get(student_id)
student_name = find_student(3)
print(student_name.upper()) # åãšã©ãŒïŒNoneTypeã«upperã¯ååšããªãïŒ
mypyã¯ãOptional
åã®å¯èœæ§ãèæ
®ããNone
ããã§ãã¯ããªãå Žåã®ãšã©ãŒãææããŸãã
Visual Studio Code redefines AI-powered coding with GitHub CâŠ
åãã§ãã¯ã®éçšæ¹æ³
1. åãã§ãã¯ãèªååãã
CI/CDãã€ãã©ã€ã³ã«mypyãçµã¿èŸŒãããšã§ãã³ãŒãã®åãã§ãã¯ãèªååã§ããŸããããã«ããããã«ãªã¯ãšã¹ãæã«åãšã©ãŒãæ€åºããåé¡ã®ããã³ãŒãããããã€ãããã®ãé²ããŸãã
2. éçºãããŒã«çµ±åãã
以äžã®ãããªã«ãŒã«ãèšããããšã§ãåãã³ããå¹æçã«éçšã§ããŸãã
- æ°èŠã³ãŒãã«ã¯å¿ ãåãã³ããè¿œå ã
- å®æçã«mypyã§ãããžã§ã¯ãå šäœã解æã
- åãã³ããææ§ãªå Žåãã³ã¡ã³ããããã¥ã¡ã³ãã§è£è¶³èª¬æãèšèŒã
ãŸãšã
éç解æããŒã«ã掻çšããããšã§ãåãã³ããå¹æçã«éçšããã³ãŒãã®å質åäžããã°ã®æ©æçºèŠãå¯èœã«ãªããŸããç¹ã«mypyãå°å ¥ããããšã§ãåãã³ããæ倧éã«æŽ»ãããéçºç°å¢ãæ§ç¯ã§ããŸãã次ã®ã»ã¯ã·ã§ã³ã7. å®è·µçãªåãã³ã掻çšäŸãã§ã¯ãåãã³ãã䜿çšããé¢æ°ãã¯ã©ã¹ã®èšèšäŸãå ·äœçã«è§£èª¬ããŸãã
7. å®è·µçãªåãã³ã掻çšäŸ
ããã§ã¯ãPythonã®åãã³ããå®åã§ã©ã®ããã«æŽ»çšã§ããããå ·äœäŸãéããŠè§£èª¬ããŸããåãã³ãã¯åãªãããã¥ã¡ã³ããšããŠã®åœ¹å²ãè¶ ããã³ãŒãã®å¯èªæ§ãå®å šæ§ãåäžããã匷åãªããŒã«ã§ãããã®ã»ã¯ã·ã§ã³ã§ã¯ãé¢æ°ãã¯ã©ã¹ãå¯å€é·åŒæ°ãªã©ãããŸããŸãªã±ãŒã¹ã§ã®åãã³ãã®äœ¿ãæ¹ã瀺ããŸãã
é¢æ°ã«ãããåãã³ãã®æŽ»çš
1. åºæ¬çãªé¢æ°ã§ã®åæå®
åãã³ãã䜿çšããããšã§ãé¢æ°ã®å
¥åãšåºåãæ確ã«èšè¿°ã§ããŸãã
äŸ:
def calculate_area(length: float, width: float) -> float:
return length * width
area = calculate_area(5.0, 3.0)
print(f"Area: {area}")
- åŒæ°
length
ãšwidth
ã¯æµ®åå°æ°ç¹åïŒfloat
ïŒã - æ»ãå€ãæµ®åå°æ°ç¹åïŒ
float
ïŒã
2. ããã©ã«ãåŒæ°ã®åæå®
ããã©ã«ãåŒæ°ãããå Žåãåãã³ããæå®ã§ããŸãã
äŸ:
def greet(name: str = "Guest") -> str:
return f"Hello, {name}!"
print(greet()) # "Hello, Guest!"
print(greet("Alice")) # "Hello, Alice!"
name
ã¯æåååã§ãããã©ã«ãå€ãšããŠ"Guest"
ãèšå®ã
å¯å€é·åŒæ°ãžã®åãã³ã
1. å¯å€é·åŒæ°ïŒ*argsïŒã®åæå®
è€æ°ã®åŒæ°ãåãåãå Žåã*args
ã䜿ãããã®åãæ瀺ã§ããŸãã
äŸ:
from typing import List
def sum_numbers(*numbers: int) -> int:
return sum(numbers)
print(sum_numbers(1, 2, 3)) # 6
*numbers
ã¯æŽæ°åïŒint
ïŒã®ã¿ãã«ãåãåããŸãã
2. ããŒã¯ãŒãåŒæ°ïŒ**kwargsïŒã®åæå®
ããŒã¯ãŒãåŒæ°ã䜿çšããå Žåãåãã³ããæå®å¯èœã§ãã
äŸ:
from typing import Dict
def display_info(**info: str) -> None:
for key, value in info.items():
print(f"{key}: {value}")
display_info(name="Alice", age="25", city="New York")
**info
ã¯ããŒãæåååãå€ãæåååã®èŸæžïŒDict[str, str]
ïŒã
ã¯ã©ã¹èšèšã«ãããåãã³ã
1. ã¯ã©ã¹å ã®åãã³ã
ã¯ã©ã¹ã®å±æ§ãã¡ãœããã«åãã³ããè¿œå ããããšã§ãèšèšãæ確ã«ãªããŸãã
äŸ:
class Student:
def __init__(self, name: str, age: int):
self.name = name
self.age = age
def introduce(self) -> str:
return f"My name is {self.name}, and I am {self.age} years old."
student = Student("Alice", 20)
print(student.introduce())
name
ãšage
ã¯ãããããæåååïŒstr
ïŒãšæŽæ°åïŒint
ïŒãintroduce
ã¡ãœããã¯æåååïŒstr
ïŒãè¿ããŸãã
2. ã¯ã©ã¹å±æ§ã«åãã³ããæå®
ã¯ã©ã¹ã¬ãã«ã®å±æ§ã«ãåãã³ããèšè¿°ã§ããŸãã
äŸ:
class School:
name: str = "Default School"
students: int = 0
name
ã¯æåååïŒstr
ïŒãstudents
ã¯æŽæ°åïŒint
ïŒã
å®åçãªåãšã€ãªã¢ã¹ã®æŽ»çš
åãšã€ãªã¢ã¹ã䜿ããšãè€éãªåãç°¡æœã«åå©çšã§ããŸãã
1. åãšã€ãªã¢ã¹ã®å®çŸ©
from typing import List
Vector = List[float]
def calculate_magnitude(vector: Vector) -> float:
return sum(x**2 for x in vector) ** 0.5
vector = [1.0, 2.0, 3.0]
print(calculate_magnitude(vector)) # 3.7416573867739413
Vector
ã¯æµ®åå°æ°ç¹åã®ãªã¹ãïŒList[float]
ïŒãšããŠå®çŸ©ã
2. ã«ã¹ã¿ã åã®æŽ»çš
è€éãªããŒã¿æ§é ã«å¯ŸããŠåãšã€ãªã¢ã¹ãå©çšã§ããŸãã
äŸ:
from typing import Dict, List
StudentScores = Dict[str, List[int]]
scores: StudentScores = {
"Alice": [90, 85, 88],
"Bob": [72, 75, 78]
}
StudentScores
ã¯ããŒãæåååãå€ãæŽæ°åãªã¹ãã®èŸæžã
åãã§ãã¯ã掻çšããå®å šãªã³ãŒãèšèš
åãã§ãã¯ããŒã«ïŒmypyãªã©ïŒãšçµã¿åãããããšã§ãå®åçãªã³ãŒãã®å®å šæ§ãé«ããããŸãã
1. Noneãå«ãåã®ãã§ãã¯
Optional
ã䜿çšããŠãåŒæ°ãNone
ã蚱容ããããšãæ瀺ããŸãã
äŸ:
from typing import Optional
def find_student(name: str) -> Optional[str]:
students = ["Alice", "Bob", "Charlie"]
return name if name in students else None
find_student
ã®æ»ãå€ã¯æåååïŒstr
ïŒãŸãã¯None
ã
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãé¢æ°ãã¯ã©ã¹ãå¯å€é·åŒæ°ãªã©ã®å®åçãªåãã³ã掻çšäŸã瀺ããŸãããåãã³ããæ£ãã䜿çšããããšã§ãã³ãŒãã®å¯èªæ§ãšä¿å®æ§ãåäžãããã°ãäºåã«é²ãããšãã§ããŸãã
次ã®ã»ã¯ã·ã§ã³ã8. ãããã質åïŒFAQïŒãã§ã¯ãåãã³ãã«é¢ããçåã誀解ã解æ¶ããå
容ããå±ãããŸãã
8. ãããã質åïŒFAQïŒ
Pythonã®åãã³ãã¯äŸ¿å©ãªããŒã«ã§ãããåããŠäœ¿ãå Žåã«ã¯çåã誀解ãçããããšããããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãåãã³ãã«é¢ãããããã質åãåãäžããæ確ãªåçãæäŸããŸãã
åãã³ãã䜿ããªããšäœãåé¡ã§ããïŒ
åãã³ãããªããŠãPythonã®ã³ãŒãã¯åäœããŸããã以äžã®ãããªåé¡ãçºçãããããªããŸãã
- å¯èªæ§ã®äœäž
é¢æ°ãå€æ°ã®åãæ瀺ãããŠããªããšãä»ã®éçºè ãã³ãŒããç解ããã®ã«æéãããããŸãã
def add(a, b):
return a + b
ãã®é¢æ°ã§ã¯ãa
ãšb
ã®åãäžæãªãããæ°å€åãæ³å®ããŠããã®ããæåååãªã®ããåãããŸããã
- ãã°ã®å¢å
åãæ確ã§ãªããããäžæ£ãªåãæž¡ããŠããšã©ãŒãæ€åºããããå®è¡æã«ãã°ãçºçããå¯èœæ§ãé«ãŸããŸãã
åãã³ãã䜿ããšå®è¡é床ãåäžããŸããïŒ
ããããåãã³ãã¯å®è¡é床ã«åœ±é¿ããŸããã
åãã³ãã¯ãããŸã§ããã³ããã§ãããPythonã®åäœãã®ãã®ã«ã¯åœ±é¿ãäžããŸãããåãã§ãã¯ã¯å®è¡æã§ã¯ãªããéç解æããŒã«ïŒäŸ: mypyïŒã䜿ã£ãŠè¡ãããŸãã
åãã³ããå®å šã«å¿ é ã«ããæ¹æ³ã¯ãããŸããïŒ
Pythonã§ã¯åãã³ãã匷å¶ããä»çµã¿ã¯ãããŸãããã以äžã®æ¹æ³ã§ãåãã³ãããªãã³ãŒãã蚱容ããªããã«ãŒã«ãéçšã§ããŸãã
- éç解æããŒã«ã®å©çš
mypyã§--strict
ãªãã·ã§ã³ã䜿çšããããšã§ãåãã³ãããªãé¢æ°ããšã©ãŒãšããŠæ€åºã§ããŸãã
mypy --strict your_script.py
- ã³ãŒãã¬ãã¥ãŒãCI/CDã®ã«ãŒã«å
ãã«ãªã¯ãšã¹ããCI/CDãã€ãã©ã€ã³ã§åãã³ãã®æç¡ããã§ãã¯ããã«ãŒã«ãèšå®ããããšã§ãåãã³ãã培åºã§ããŸãã
mypyã䜿ã£ãåãã§ãã¯ãé ãå Žåã®å¯ŸåŠæ³ã¯ïŒ
倧èŠæš¡ãããžã§ã¯ãã§ã¯ãmypyã®åãã§ãã¯ãé ããªãããšããããŸãã以äžã®æ¹æ³ã§ããã©ãŒãã³ã¹ãæ¹åã§ããŸãã
- ã€ã³ã¯ãªã¡ã³ã¿ã«ã¢ãŒãã®äœ¿çš
--incremental
ãªãã·ã§ã³ã䜿ããšãå€æŽãããéšåã®ã¿ããã§ãã¯ããŸãã
mypy --incremental your_script.py
- äžéšã¢ãžã¥ãŒã«ãç¡èŠ
åãã§ãã¯ãäžèŠãªå€éšã¢ãžã¥ãŒã«ã--ignore-missing-imports
ã§ç¡èŠããŸãã
mypy --ignore-missing-imports your_script.py
åãã³ããåŠã¶ã¹ãåå¿è ã«ããããã®ãªãœãŒã¹ã¯ãããŸããïŒ
以äžã®ãªãœãŒã¹ã掻çšãããšãåãã³ãã®åºæ¬ããå¿çšãŸã§ãå¹ççã«åŠã¹ãŸãã
- Pythonå
¬åŒããã¥ã¡ã³ãïŒPEP 484ïŒ
åãã³ãã®åºæ¬çãªä»æ§ã解説ãããŠããŸãã
PEP 484 – Type Hints - Pythonå
¬åŒåãã³ãã®ãã¥ãŒããªã¢ã«
å®éã®äœ¿çšäŸã詳ãã説æãããŠããŸãã
Typing Module - ãªã³ã©ã€ã³åŠç¿ãã©ãããã©ãŒã
UdemyãCourseraã§ãPythonåãã³ããé¢é£ã®ã³ãŒã¹ãæ¢ããšãäœç³»çã«åŠã¹ãŸãã
åãã³ãã䜿ãã¹ãå Žé¢ãšäœ¿ããªããŠãããå Žé¢ã¯ïŒ
åãã³ãã䜿ãã¹ãå Žé¢:
- ããŒã éçº
åãã³ãã䜿ãããšã§ãä»ã®éçºè ãã³ãŒããããç°¡åã«ç解ã§ããŸãã - 倧èŠæš¡ãããžã§ã¯ã
ãããžã§ã¯ãã倧ãããªãã»ã©ãåãã³ãããã°é²æ¢ã«è²¢ç®ããŸãã - å€éšAPIãã©ã€ãã©ãªã®å
Ž
åãã³ãããããšãå©çšè ãé¢æ°ãã¯ã©ã¹ã®äœ¿ãæ¹ãç解ãããããªããŸãã
åãã³ãã䜿ããªããŠãããå Žé¢:
- å°èŠæš¡ã§çæéã®ã¹ã¯ãªãã
äŸ: ç°¡åãªããŒã¿è§£æãèªååã¹ã¯ãªãã - è©Šäœæ®µéã®ã³ãŒã
ãããã¿ã€ãäœææã¯åãã³ããçç¥ããŠè¿ éã«éçºãé²ããå ŽåããããŸãã
åãã³ãã掻çšããããšã§ã©ã®ãããªå®åçã¡ãªããããããŸããïŒ
åãã³ãã掻çšããããšã§ã以äžã®ãããªå®åçãªã¡ãªããããããŸãã
- ãã°ã®æ©æçºèŠ
åãã³ãã«åºã¥ãéç解æã«ããããã°ãå®è¡åã«é²ããŸãã - éçºå¹çã®åäž
IDEã®è£å®æ©èœã匷åããããããã³ãŒãèšè¿°ãéããªããŸãã - ä¿å®æ§ã®åäž
åãæ確ã«ãªãããšã§ãåŸããã³ãŒããèªã人ãç解ãããããªããŸãã
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãåãã³ãã«é¢ãããããã質åã«åçããŸãããåãã³ãã¯åŠã³ããããéçºè ã®äœæ¥å¹çãã³ãŒãã®å質ã倧ããåäžãããããŒã«ã§ããç¹ã«éç解æããŒã«ãšçµã¿åãããããšã§ããã®å¹æãæ倧éã«åŒãåºããŸãã
9. ãŸãšã
ãã®èšäºã§ã¯ãPythonã®ãåãã³ããã掻çšããåŒæ°ã®åæå®ã«ã€ããŠãåºæ¬ããå¿çšãããã«ã¯åãã§ãã¯ããŒã«ã®äœ¿çšæ¹æ³ãå®åã§ã®æŽ»çšäŸãŸã§ã詳ãã解説ããŸãããæåŸã«ããããŸã§ã®å 容ãç·æ¬ããåãã³ããå¹æçã«äœ¿ãããã®ãã€ã³ãããäŒãããŸãã
åãã³ãã®éèŠæ§
åãã³ãã¯ãPythonã®åçåä»ãã®æè»æ§ãä¿ã¡ãªããã以äžã®ãããªå€ãã®å©ç¹ããããããŸãã
- å¯èªæ§ã®åäž
åæ å ±ãã³ãŒãã«æèšããããšã§ãé¢æ°ãå€æ°ã®åœ¹å²ãäžç®ã§åããããã«ãªããŸãã - éç解æã«ãããã°é²æ¢
å®è¡åã«åã®äžäžèŽãæ€åºããæœåšçãªãã°ãæžãããŸãã - éçºå¹çã®åäž
IDEã®è£å®æ©èœã掻çšããããšã§ãã³ãŒãèšè¿°ãã¹ã ãŒãºã«ãªãããã¹ãæžå°ããŸãã - ä¿å®æ§ã®åäž
åãæ確ã§ããã°ãåŸããã³ãŒããèªã人ãç解ãããããªããŸãã
åãã³ãå°å ¥ã®ã¹ããã
åãã³ããå¹æçã«å°å ¥ããããã®æé ã以äžã«ãŸãšããŸãã
1. 段éçã«å°å ¥ãã
æ¢åãããžã§ã¯ãã«åãã³ããè¿œå ããå Žåã¯ã以äžã®æé ã§æ®µéçã«å°å ¥ãããšå¹æçã§ãã
- äž»èŠãªé¢æ°ãã¯ã©ã¹ã«å¯ŸããŠåãã³ããè¿œå ããã
- éç解æããŒã«ïŒäŸ: mypyïŒã䜿çšããŠåãã§ãã¯ãèªååããã
- åãã³ãã®éçšã«ãŒã«ãããŒã å ã§å ±æããã
2. å¿ èŠä»¥äžã«è€éãªåæå®ãé¿ãã
åãè€éã«ãªãããããšãå¯èªæ§ãäœäžããå ŽåããããŸããé©åãªæœè±¡åãåãšã€ãªã¢ã¹ã掻çšããŠãç°¡æœã«èšè¿°ããŸãããã
3. éç解æããŒã«ã掻çšãã
mypyãPyCharmãªã©ã®éç解æããŒã«ãå°å ¥ããŠãåãã³ãã掻çšããå質管çãè¡ããŸãã
åãã³ã掻çšã®ãã€ã³ã
以äžã®ãã€ã³ããæèããããšã§ãåãã³ããããå¹æçã«æŽ»çšã§ããŸãã
- å
šãŠã«åãã³ããè¿œå ããå¿
èŠã¯ãªã
å°èŠæš¡ãªã¹ã¯ãªãããè©Šäœæ®µéã®ã³ãŒãã§ã¯ãåãã³ããçç¥ããŠãæ§ããŸãããéèŠãªã®ã¯ãã©ã³ã¹ã§ãã - Pythonã®å
¬åŒãªãœãŒã¹ã掻çšãã
Pythonå ¬åŒããã¥ã¡ã³ãïŒPEP 484ãtyping
ã¢ãžã¥ãŒã«ïŒãåç §ããããšã§ãåãã³ãã®ææ°ä»æ§ãåŠã¹ãŸãã - éçºç°å¢ã«é©ããåãã§ãã¯ããŒã«ãéžã¶
ããŒã ã®èŠæš¡ããããžã§ã¯ãã®æ§è³ªã«å¿ããŠãé©åãªããŒã«ïŒäŸ: mypyãpylanceïŒãéžæããŸãã
åãã³ãã®æªæ¥
Pythonã®åãã³ãã¯ä»åŸããã«é²åããå¯èœæ§ããããŸããæ°ããPEPïŒPython Enhancement ProposalïŒã®ææ¡ã«ãããããæè»ã§è¡šçŸåè±ããªåæå®ãå¯èœã«ãªããšæåŸ ãããŠããŸããåãã³ããæ©æã«åŠã³ã掻çšæ¹æ³ãç解ããŠããããšã§ãå°æ¥çãªPythonãããžã§ã¯ãã«ãããŠãåªäœã«ç«ã€ããšãã§ããã§ãããã
次ã®ã¹ããã
åãã³ãã®åºç€ãšå¿çšãåŠãã 次ã¯ã以äžã®ã¹ããããå®è·µããŠã¿ãŸãããã
- èªåã®ãããžã§ã¯ãã«åãã³ããè¿œå ããã
- éç解æããŒã«ãå°å ¥ããåãã§ãã¯ãè¡ãã
- åãã³ãã«é¢é£ããå ¬åŒããã¥ã¡ã³ãããªãœãŒã¹ãåç §ãããããªãç¥èãæ·±ããã
æåŸã«
Pythonã®åãã³ãã¯ãéçºè ã«ãšã£ãŠéåžžã«åŒ·åãªããŒã«ã§ãããã®èšäºã§åŠãã å 容ã掻çšããå®åã§ã®ã³ãŒãã£ã³ã°å¹çãå質ãåäžãããŸããããåãã³ãã®æ£ãã䜿ãæ¹ãç¿åŸããã°ãPythonã®æè»æ§ã掻ãããªãããå ç¢ã§ä¿å®æ§ã®é«ãã³ãŒããäœæã§ããããã«ãªããŸãã