python.jp View RSS

No description
Hide details



DjangoCongress JP 2025の発表内容とYouTube Liveでの配信が決定 11 Feb 6:00 AM (2 months ago)

DjangoCongress JP 2023

DjangoCongress JP 2025の発表内容とYouTube Liveでの配信が決定

2025年2月22日(土曜日)開催予定のDjangoCongress JP 2025の配信が決定しました。

以下のYouTube Liveにて配信されます:

今年はDjangoだけでなくFastAPIなど非同期Webに関するトークも予定されています。またDjang

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.13の新機能(その5)PEP 742: TypeIs による型の絞り込み 30 Jan 6:00 AM (2 months ago)

Python 3.10では PEP 647: ユーザ定義の型ガード が導入され、型ガード を定義して型推論に利用できるようになりました。

from typing import TypeGuard

def is_int(x: object) -> TypeGuard[int]:
    return isinstance(x, int)

def func(x:object) -> None:
    if is_int(x):
        reveal_type(x) # x は int

型ガードについては、Python 3.10の新機能(その7) ユーザ定義型ガード の解説を参照してください。

型ガー

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.13の新機能(その4)PEP 705: TypeDict: 読み取り専用アイテム 27 Jan 6:00 AM (2 months ago)

PEP 705: TypedDict: Read-only items では、TypedDict に読み取り専用の項目を指定できるようになりました。

from typing import TypedDict, ReadOnly

class FooDict(TypedDict):
    x: int
    y: int
    z: ReadOnly[int]  # z は読み取り専用

foo: FooDict = {"x": 1, "y": 2, "z": 3}
foo["x"] = 4  # Ok
foo["z"] = 5  # エラー: "z" is a read-only key in "FooDict"

ただし、リストな

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.13の新機能(その3)PEP 702: 型システムを利用したDeprecate(廃止予定)の指定 27 Jan 6:00 AM (2 months ago)

PEP 702: 型システムを利用した非推奨の指定

従来のPythonでは、Deprecate(廃止予定)のAPIを警告するために、次のように DeprecationWarning を使っていました。

import warnings

def func():
    warnings.warn("deprecated", DeprecationWarning)
    return 0

しかし、この方法では実行するまで警告が表示されないため、警告を見逃されることがありました。

そこで、PEP 702では、@warnings.deprecated デコレータ

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.13の新機能(その2)PEP 696: 型パラメータのデフォルト型 26 Jan 6:00 AM (2 months ago)

従来のジェネリック型では、型を決定できない型パラメータは Any などにされていました。

class A[T]:
    foo: T | None
    def __init__(self, foo: T | None=None):
        self.foo = foo

a = A()
reveal_type(a) # Mypyでは a は A[Any] となる

PEP 696: Type Defaults for Type Parameters では、指定されていない型パラメータにデフォルトの型を指定できるようになりました。

class A[T=int]: # T のデフォルトを int に指定
    foo: T |

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.13の新機能(その1) PEP 703: フリースレッドモード 22 Jan 6:00 AM (2 months ago)

2024年10月7日にリリースされたPython 3.13の概要を紹介します。

Python 3.13ではPythonのプログラミング言語としての仕様に大きな変更はありませんでしたが、将来のPythonの実行環境に大きな影響を与える、大きな変更が導入されました。

PEP 703: フリースレッドモード

Python 3.13では、実験的な機能として、フリースレッドモードが導入されました。従来のPythonには、グローバルインタプリタロック(GIL)があり、マルチスレッドでのパフォーマンスが向上しないという問題がありました

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.12の新機能(その7) PEP 709: 内包式のインライン化 11 Apr 2024 7:00 AM (last year)

Python3.0以降では、リスト内包でエラーが発生すると、トレースバックに <listcomp> という不思議な関数名が表示されることがありました。

>>> def func():
...     [1/0 for i in range(10)]
...
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in func
  File "<stdin>", line 2, in <listcomp>
ZeroDivisionError: di

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.12の新機能(その5) PEP 684: インタープリター別GIL 9 Apr 2024 7:00 AM (last year)

Python3.11で開始された Faster CPython: CPython 高速化計画ですが、予定されていた Tracing optimizerが追加されなかったこともあり、残念ながらPython3.12では大きなパフォーマンスの改善は見られませんでした。

しかし、将来の高速化に向けて、大きな機能追加がありました。

サブインタープリター

Pythonのあまり知られていない機能に、サブインタープリター があります。これは一つのプロセス内で複数のPython実行環境を作成し、複数のアプリケーションを同時に動かすことができる

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.12の新機能(その6) PEP 683: 固定参照カウントによる永続オブジェクト 9 Apr 2024 7:00 AM (last year)

Pythonは、すべての変数などが参照しているオブジェクトを正確に把握し、それぞれのオブジェクトが参照されている数を厳密に記録しています。この、記録されている参照の数を、参照カウント と言います。参照カウントが 0 になると、そのオブジェクトはすでに利用されていないことが明らかなので、Pythonはそのオブジェクトを開放します。

オブジェクトの参照カウントは、sys.getrefcount() で調べられます。

次の例では、sys.getrefcount() を使って、True オブジェクトが参照されている数を調べています

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?

Python 3.12の新機能(その4) PEP 688: バッファープロトコルをPythonで利用可能に 9 Oct 2023 7:00 AM (last year)

Pythonで最も有名なライブラリの一つに、Numpy があります。Numpyは科学技術計算、機械学習、AI、画像処理など、多岐にわたる分野で利用され、今日のPythonの普及に大きく貢献しています。

Numpyは独立したライブラリですが、もともとはPythonの標準ライブラリに組み込む予定で開発が始まりました。しかし、プロジェクトが大規模化したため、最終的に独立したライブラリとして提供されることになりました。この経緯から、NumpyはPython言語と密接な関係を持ち、その設計や実装に大きな影響を与えてきまし

Add post to Blinklist Add post to Blogmarks Add post to del.icio.us Digg this! Add post to My Web 2.0 Add post to Newsvine Add post to Reddit Add post to Simpy Who's linking to this post?