Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
youknowone-2018-pycon-ring
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Hyesoo Yoo
August 18, 2018
Programming
66
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
youknowone-2018-pycon-ring
test :)
Hyesoo Yoo
August 18, 2018
Other Decks in Programming
See All in Programming
すこし踏み込む CancellationToken
htkym
2
1.7k
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
ChromeでローカルLLM
ryu1013
0
140
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
390
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
150
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
370
sbt 2.0: takeoff
eed3si9n
0
160
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2k
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
530
Ethics towards AI in product and experience design
skipperchong
2
430
Thoughts on Productivity
jonyablonski
76
5.4k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
600
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Documentation Writing (for coders)
carmenintech
77
5.6k
Site-Speed That Sticks
csswizardry
13
1.6k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
Paper Plane
katiecoart
PRO
5
54k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Transcript
Ring ۽Ӓې߁ য৬ оө நद ۄ࠳۞ܻ ਮਗ
OOP ঠӝ • userী itemਸ ୶о೧ঠ ೠҊ ࢤп೧ ࠇद. ېझо
হח যۄݶ ই݃ب user_add_item(user, item) э ٘ܳ ॶ Ѫੑפ. • ই݃ user_delete_itemب Ҋ user_clear_itemsب ѷਃ. • ೞ݅ ܻח ॆ ۽Ӓېݠפө ࠁా user.add_item(item) э ٘ܳ ॺפ .
நद ঠӝ • userী ࣘೠ itemٜਸ оઉয়ח ೣࣻо Ҋ
ೣࣻח Ѿҗܳ நदೞҊ Ҋ ࢤп೧ ࠇद. user.get_items() э ٘ܳ ॶ ࣻب Ҋ user.get_cached_items(storage) э ٘ܳ ॶ ࣻب ѷਃ. • item ݾ۾ সؘ غणפ. ઁ நदܳ ޖബച೧ঠ פ. ই݃ب user.invalidate_items()ա user.delete_cached_items(storage) э ٘ܳ ٜ݅যঠ ೞѷਃ. • Ringীࢲח user.get_items.delete() ܳ ഐפ.
• Ring ই٣যীࢲࠗఠ ߊפ. • ಕөח ߊীח ನೣغ
ঋ ղਊੑפ. ಕࠗఠ ߊ ղਊ दؾפ.
நद
நद ৵ ೞաਃ?
நद ৵ ೞաਃ?
நद Ring যڌѱ ೞաਃ? ৵ ೞաਃ? =
৵? • झషܻח যߡܻ • ٘ী ೞ • ੋрചੋ ੋఠಕझ۽
۽Ӓې߁ ೞ • ؒ: ী Ѧ ழझఠ݃ૉ оמ
நद ܲ ਗਸ ডೞӝ ਤ೧ द۽ чਸ ӝ۾೧ فח
ҕр
ೠٲ ೠٲ ࣚਵ۽
ೠٲ ೠٲ ࣚਵ۽ प೯ بо ӟ ٘
ೠٲ ೠٲ ࣚਵ۽ प೯ بо ӟ ٘ Ӓր ߈ࠂغח ֢ز
ೠٲ ೠٲ ࣚਵ۽ • ۠ ױࣽೠ IOܳ ੋр ߈ࠂ೧ࢲ ೞݶ...
ೠٲ ೠٲ ࣚਵ۽ • ۠ ױࣽೠ IOܳ ੋр ߈ࠂ೧ࢲ ೞݶ...
Ҁ ૐդ ইޖ ࢤп হ ࣚоۅب ൨ٜ
ೠٲ ೠٲ ࣚਵ۽ • ۠ ױࣽೠ IOܳ ੋр ߈ࠂ೧ࢲ ೞݶ...
Ҁ ૐդ ইޖ ࢤп হ ࣚоۅب ൨ٜ पࣻೠ
ൔೠ ޙઁূ
decorator
decorator प೯ بо ӟ ٘
decorator प೯ بо ӟ ٘ ࢎਊ оמೞҊ प೯ܴਸ ೧ ঋח
٘ ࠶۾
decorator ೣࣻী ॶ ࣻ ח ৮߷ೠ ೧ߨ
decorator ೣࣻী ॶ ࣻ ח ৮߷ೠ ೧ߨ ࣽࣻ pure function
࠺Ѿ ೣࣻ • ۽Ӓې߁ ࣁ҅ח ࠗਊਵ۽ оٙ ର “ஹೊఠ
җীࢲ ೣࣻо Ѿҗч ৻ী ܲ ࢚కܳ ߸҃दఆ ٸ ࠗਊ Ҋ ݈ೠ. (... ۚ ...) ࠗਊ ۽Ӓ۔ زਸ ೧ೞӝ য۵ѱ ೠ.” ࠗਊ(ஹೊఠ җ) - ਤఃߔҗ ೠҴয౸
࠺Ѿ ೣࣻ • ۽Ӓې߁ ࣁ҅ח ࠗਊਵ۽ оٙ ର “ஹೊఠ
җীࢲ ೣࣻо Ѿҗч ৻ী ܲ ࢚కܳ ߸҃दఆ ٸ ࠗਊ Ҋ ݈ೠ. (... ۚ ...) ࠗਊ ۽Ӓ۔ زਸ ೧ೞӝ য۵ѱ ೠ.” ࠗਊ(ஹೊఠ җ) - ਤఃߔҗ ೠҴয౸
࠺Ѿ ೣࣻ
࠺Ѿ ೣࣻ # 60 * 15 ୡ زউ ਬബೠ நद
ࢤࢿ # cache_page: Djangoীࢲ ౠ HTTP ਃ ਸ ੌӝр நद೧ ח decorator
࠺Ѿ ೣࣻ # 60 * 15 ୡ زউ ਬബೠ நद
ࢤࢿ PyConী য়न Django ࢎਊ ৈ۞࠙, Ѣ ॳࣁਃ? # cache_page: Djangoীࢲ ౠ HTTP ਃ ਸ ੌӝр நद೧ ח decorator
࠺Ѿ ೣࣻ # 60 * 15 ୡ زউ ਬബೠ நद
ࢤࢿ PyConী য়न Django ࢎਊ ৈ۞࠙, Ѣ ॳࣁਃ? நद ޖബച दఃҊ ࢤࢿ ೞ۰ݶ..? # cache_page: Djangoীࢲ ౠ HTTP ਃ ਸ ੌӝр நद೧ ח decorator
࠺Ѿ ೣࣻ
࠺Ѿ ೣࣻ
Ring ܻࠁӝ
Ring • Sub-function control • Methods & descriptor support •
Key Consistency • Backend: memcache, redis, diskcache, shelve, dict • asyncio support • Fully customizable • Django integration
Sub-functions • ӝࠄ ೣࣻ import ring @ring.dict({}) def function(v): return
... import functools @functools.lru_cache() def function(v) return ... Ring lru_cache
Sub-functions • ݅ܐо ח ҃ from django… \ import cache_page
@cache_page(60) def view(request): return ... import ring @ring.dict( {}, expire=60) def function(v): return ... Ring Django per-view cache
Sub-functions • ӝࠄ ೣࣻ • ӝࠄ प೯ & நद value
= function(10) value = function(10) import ring @ring.dict({}) def function(v): return ... import functools @functools.lru_cache() def function(v) return ... Ring lru_cache
Sub-functions • ઁ • ೞח python-memcached function.delete(10) key = create_key(10)
client.delete(key)
Sub-functions • द সؘ • ೞח python-memcached key = create_key(10)
value = function(10) client.set(key) value = \ function.update(10)
Sub-functions • ӝࠄ प೯ & நद • ೞח python-memcached value
= function(10) value = function\ .get_or_update(10) key = create_key(10) value = client.get(key) if value is None: value = function(10) client.set(key)
झషܻ ஶ܀ਸ ೣࣻ बਵ۽
Sub-functions • ӝࠄ प೯ & நद • ࣻز ઁ •
நद݅ оઉয়ӝ • द সؘ • प೯݅ • ١١... value = function(10) function.delete(10) value = function.update(10) value = function.execute(10) value = function.get(10)
Sub-functions • Django ҙੋ ੋఠಕझ۽ ݃ ಣചܳ
Sub-functions • Django
Sub-functions • get_many • set_many, update_many, get_or_update_many … @ring.memcache(...) def
f(a, b): ... # getting data for f(1, 2), f(1, 3), f(a=2, b=2) data = f.get_many((1, 2), (1, 3), {'a': 2, 'b': 2}) # dataח ч sequence(list)
Sub-functions • get_many • set_many, update_many, get_or_update_many … @ring.memcache(...) def
f(a, b): return a * 100 + b # getting data for f(1, 2), f(1, 3), f(a=2, b=2) data = f.get_many((1, 2), (1, 3), {'a': 2, 'b': 2}) assert data == [102, 103, 202]
Sub-functions • get_many • execute_many, set_many, update_many, get_or_update_many …, @ring.memcache(...)
def f(a, b): return a * 100 + b # getting data for f(1, 2), f(1, 3), f(a=2, b=2) data = f.get_many((1, 2), (1, 3), {'a': 2, 'b': 2}) assert data == [102, 103, 202]
Sub-functions • झషܻܳ ٘(ೣࣻ) बਵ۽ ઑ • ࢎਊীѱ ҙੋ ੋఠಕझ
• ࢎਊ ӝמ(ݫࢲ٘) ୶оܳ ਤೠ ೠ namespace
Ring • Sub-function control • Methods & descriptor support •
Key Consistency • Backend: memcache, redis, diskcache, shelve, dict • asyncio support • Fully customizable • Django integration
Methods & Descriptors class UserAPI(object): url_prefix = 'https://...' secret_key =
'...' def __init__(self, user_id): self.user_id = user_id # cache? @classmethod def api_status(cls): return request( f'{cls.url_prefix}/status') # cache? def get_user(self, n): return request( f'{cls.url_prefix}/users/{n}')
Methods & Descriptors • ݫࢲ٘ܳ ܖ۰ݶ? • (ࠁా) • ৻ࠗী
ೣࣻ۽ ࡐѢա • In-house۽ ઁಿী ݏѱ ٜ݅য ॳѢա class UserAPI(object): url_prefix = 'https://...' secret_key = '...' def __init__(self, user_id): self.user_id = user_id # cache? @classmethod def api_status(cls): return request( f'{cls.url_prefix}/status') # cache? def get_user(self, n): return request( f'{cls.url_prefix}/users/{n}')
Methods & Descriptors • Ring: ੌҙࢿ ח ੋఠಕझ class UserAPI(object):
url_prefix = 'https://...' secret_key = '...' def __init__(self, user_id): self.user_id = user_id @ring.dict({}, expire=5) @classmethod def api_status(cls): return request( f'{cls.url_prefix}/status') @ring.dict({}, expire=60) def get_user(self, n): return request( f'{cls.url_prefix}/users/{n}')
Methods & Descriptors • Ring: ੌҙࢿ ח ੋఠಕझ • (free)
function • method • classmethod • staticmethod • property • custom descriptors • hybridmethod? hybridproperty? • descriptorী class UserAPI(object): url_prefix = 'https://...' secret_key = '...' def __init__(self, user_id): self.user_id = user_id @ring.dict({}, expire=5) @classmethod def api_status(cls): return request( f'{cls.url_prefix}/status') @ring.dict({}, expire=60) def get_user(self, n): return request( f'{cls.url_prefix}/users/{n}')
Methods & Descriptors • Q: Ringҗ ࠺तೠ method/descriptor ਗਸ ٜ݅۰ݶ
যڌѱ ೞաਃ?
Methods & Descriptors • Q: Ringҗ ࠺तೠ method/descriptor ਗਸ ٜ݅۰ݶ
যڌѱ ೞաਃ? • A: https://github.com/youknowone/wirerope
Ring • Sub-function control • Methods & descriptor support •
Key Consistency • Backend: memcache, redis, diskcache, shelve, dict • sync/asyncio support • Fully customizable • Django integration
Key consistency • э ೣࣻ ੋী ೧ э ఃܳ
ࢤࢿೞח ޙઁ • ݅ܐ(expire, invalidate) ٸޙী ਃೠ ޙઁ
Key consistency • э ೣࣻ ੋী ೧ э ఃܳ
ࢤࢿೞח ޙઁ • ݅ܐ(expire, invalidate) ٸޙী ਃೠ ޙઁ function(1) function(v=1) э ੋؘ ׳ػ ੋ ഋधী ٮۄ ܲ ఃܳ ݅ٚݶ? @functools.lru_cache( maxsize=64) def function(v): return ...
Key consistency • э ೣࣻ ੋী ೧ э ఃܳ
ࢤࢿೞח ޙઁ • ݅ܐ(expire, invalidate) ٸޙী ਃೠ ޙઁ function(1) function(v=1) @functools.lru_cache( maxsize=64) def function(v): return ... э ੋؘ ׳ػ ੋ ഋधী ٮۄ ܲ ఃܳ ݅ٚݶ? ҃ח ࢿמ ખ ڄযઉب ޙઁח হ݅...
Key consistency • э ೣࣻ ੋী ೧ э ఃܳ
ࢤࢿೞח ޙઁ • ݅ܐ(expire, invalidate) ٸޙী ਃೠ ޙઁ function.delete(1) function(v=1) @ring.dict({}) def function(v): return ... э ੋؘ ׳ػ ੋ ഋधী ٮۄ ܲ ఃܳ ݅ٚݶ?
Key consistency • э ೣࣻ ੋী ೧ э ఃܳ
ࢤࢿೞח ޙઁ • ݅ܐ(expire, invalidate) ٸޙী ਃೠ ޙઁ function.delete(1) function(v=1) @ring.dict({}) def function(v): return ... э ੋؘ ׳ػ ੋ ഋधী ٮۄ ܲ ఃܳ ݅ٚݶ? ҃ח ࢎਊ ੑীࢲ ঌӝ ൨ٚ ߡӒ ߊࢤ
Key consistency • э ೣࣻ ੋী ೧ э ఃܳ
ࢤࢿೞח ޙઁ • ݅ܐ(expire, invalidate) ٸޙী ਃೠ ޙઁ >>> import sample sample.f:1:2 sample.f:1:2 sample.f:1:2 import ring @ring.dict({}) def f(a, *, b): return ... print(f.key(1, b=2)) print(f.key(a=1, b=2)) print(f.key(**{'a': 1, 'b': 2}))
Key consistency • э ೣࣻ ੋী ೧ э ఃܳ
ࢤࢿೞח ޙઁ • ݅ܐ(expire, invalidate) ٸޙী ਃೠ ޙઁ >>> import sample sample.A.f:A():1 sample.A.g:A:2 sample.A.g:A:3 import ring class A(object): def __ring_key__(self): return 'A()' @ring.dict({}) def f(self, a): pass @ring.dict({}) @classmethod def g(cls, a): pass a = A() print(a.f.key(a=1)) print(a.g.key(a=2)) print(A.g.key(a=3))
Key policy • э ഐ ೧ ೦࢚ 1ѐ நद(ః)݅
ઓೞח Ѫਸ ࠁ • ఃܳ ݅٘ח ೣࣻ݅ ٮ۽ ഐ оמ (ॆ ۽ંр ഐജ) • ೧दо ইצ ח ޙৌ (࠺ ॆ ۽ંр ഐജ)
Ring • Sub-function control • Methods & descriptor support •
Key Consistency • Backend: memcache, redis, diskcache, shelve, dict • asyncio support • Fully customizable • Django integration
Backends @ring.dict(s) @ring.shelve(s) @ring.memcache(s) @ring.redis(s) @ring.diskcache(s) @ring.django.cache()
Backends @ring.dict(s) @ring.shelve(s) @ring.memcache(s) @ring.redis(s) @ring.diskcache(s) @ring.django.cache() dict shelve.Shelf memcache.Client
(python-memcached) pylibmc.Client pymemcache.client.Client aiomcache.Client redis.Client aioredis.Client diskcache.Cache django.core.cache.caches
Ring • Sub-function control • Methods & descriptor support •
Key Consistency • Backend: memcache, redis, diskcache, shelve, dict • asyncio support • Fully customizable • Django integration
Backends @ring.dict(s) @ring.shelve(s) @ring.memcache(s) @ring.redis(s) @ring.diskcache(s) dict shelve.Shelf memcache.Client (python-memcached)
pylibmc.Client pymemcache.client.Client aiomcache.Client redis.Client aioredis.Client diskcache.Cache
Backends • Q: ࢜۽ ߔূ٘ܳ ୶оೞ۰ݶ? • A: ٘ܳ 30
ૠ
Backends • Q: ࢜۽ ߔূ٘ܳ ୶оೞ۰ݶ? • A: ٘ܳ 30
ૠ class MemcacheStorage( fbase.CommonMixinStorage, fbase.StorageMixin, BulkStorageMixin): def get_value(self, key): value = self.backend.get(key) if value is None: raise fbase.NotFound return value def set_value(self, key, value, expire): self.backend.set(key, value, expire) def delete_value(self, key): self.backend.delete(key) def touch_value(self, key, expire): self.backend.touch(key, expire) def get_many_values(self, keys): values = self.backend.get_multi(keys) return [values.get(k, fbase.NotFound) for k in keys] def set_many_values(self, keys, values, expire): self.backend.set_multi({k: v for k, v in zip(keys, values)}, expire) def delete_many_values(self, keys): return self.backend.delete_multi(keys)
Ring • Sub-function control • Methods & descriptor support •
Key Consistency • Backend: memcache, redis, diskcache, shelve, dict • asyncio support • Fully customizable • Django integration
Storage Key • Q: Ring ࢤࢿೞח ఃܳ ॳҊ र ঋইਃ
Storage Key sample.article:42 @ring.memcache(client) def article(id): return ... print(article.key(42))
Storage Key sample.article:42 new_prefix:42 @ring.memcache(client) def article(id): return ... print(article.key(42))
@ring.memcache(client, key_prefix='new_prefix') def article(id): return ... print(article.key(42)) case1: prefix config
Storage Key sample.article:42 a42e @ring.memcache(client) def article(id): return ... print(article.key(42))
@article.ring.key def article_key(id): return f'a{id}e' print(article.key(42)) case2: key function override
Data Encoder • Q: ղ ؘఠח ࠂೠؘ, झషܻী যڌѱ غաਃ?
•
Data Encoder dict(id=42, name='Name') dict(id=42, name='Name') @ring.dict({}) def user1(id): return
{ 'id': id, 'name': 'Name'} print(user1(42)) @ring.dict( {}, coder='json') def user2(id): return { 'id': id, 'name': 'Name'} print(user2(42))
Data Encoder dict(id=42, name='Name') # = json.dumps(user1(42)) b'{"id": id, "name":
"Name"}' d1 = {} @ring.dict(d1) def user1(id): return { 'id': id, 'name': 'Name'} print(d1[42]) d2 = {} @ring.dict(d2, coder='json') def user2(id): return { 'id': id, 'name': 'Name'} print(d2[42])
Data Encoder • Q: ܲ ߑधਵ۽ ೞҊ रؘ •
Data Encoder • json, pickle ղ • ए ੋ؊ ١۾
Data Encoder # = json.dumps(user1(42)) '{"id": id, "name": "Name"}' d1
= {} @ring.dict(d1) def user1(id): return { 'id': id, 'name': 'Name'} @user1.ring.encode def user_encode(v): return json.dumps(v) @user1.ring.decode def user_decode(v): return json.loads(v) print(d1[42]) case1: single function coder
Data Encoder import json import ring ring.coder.register( 'json', (json.dumps, json.loads))
import pickle import ring ring.coder.register( 'pickle', (pickle.dumps, pickle.loads)) case2: reusable coder
Strategy • __call__, get, update, delete ١ਸ ೞ۰ݶ? • ࢜۽
ݫࢲ٘ܳ ୶оೞ۰ݶ? • ex: োҙػ ݽٚ ؘఠܳ ೠߣী ח ݫࢲ٘о ਃೞ • நद ଼ਸ ߄Բ۰ݶ? • ex: ࢸ࢚ expire غযب நदܳ թѹف hitೞѱ ೧ࢲ ࢿמ хࣗܳ ݄ѷ •
Strategy • __call__, get, update, delete ١ਸ ೞ۰ݶ? • ࢜۽
ݫࢲ٘ܳ ୶оೞ۰ݶ? • ex: োҙػ ݽٚ ؘఠܳ ೠߣী ח ݫࢲ٘о ਃೞ • நद ଼ਸ ߄Բ۰ݶ? • ex: ࢸ࢚ expire غযب நदܳ թѹف hitೞѱ ೧ࢲ ࢿמ хࣗܳ ݄ѷ • UserInterface
Low-level Interface • Q: ਃೠؘ হח ӝמ ਵݶ UserInterface ഛਸ
೧ঠ ೞաਃ?
Ringਵ۽ ޤٚ ٜ݅ࣻ ?
Ringਵ۽ ޤٚ ٜ݅ࣻ ? ਃೡ ٸ݅ ॶ ࣻ
Low-level Interface @ring.memcache(client, key_prefix='article') def article(id): return ...
Low-level Interface @ring.memcache(client, key_prefix='article') def article(id): return ... key =
article.key(42) # key݅ ٜ݅ӝ encoded = client.get(key) # memcacheীࢲ get data = article.decode(encoded) # ਗࠄؘఠ۽
Low-level Interface @ring.memcache(client, key_prefix='article') def article(id): return ... key =
article.key(42) # key݅ ٜ݅ӝ encoded = client.get(key) # memcacheীࢲ get data = article.decode(encoded) # ਗࠄؘఠ۽ data = article.get(42) # ਤ 3җ э ٘
Low-level Interface • ए ഐജ: ਬ۽ ఎ • оמೠ ֢ػ
ੋఠಕझ
Ring ইې ॆ
inspect.signature • parameters & return annotation • Python 3.3+ •
Backport: https://pypi.org/project/inspect2/
inspect.signature In [1]: def f(a, b, *args, x, y=10, **kw):
...: pass ...: In [2]: import inspect In [3]: s = inspect.signature(f) Out[4]: <Signature (a, b, *args, x, y=10, **kw)> In [6]: for name, parameter in s.parameters.items(): ...: print(name, parameter.kind, parameter.default) ...: a POSITIONAL_OR_KEYWORD <class 'inspect._empty'> b POSITIONAL_OR_KEYWORD <class 'inspect._empty'> args VAR_POSITIONAL <class 'inspect._empty'> x KEYWORD_ONLY <class 'inspect._empty'> y KEYWORD_ONLY 10 kw VAR_KEYWORD <class 'inspect._empty'>
qualname • ݽٕ উীࢲ ೞա ېझ/ೣࣻܳ оܻఃח Ѣ ਬੌೠ ܴ
• ࢤࢿ दী ഋࢿ (py2 im_classࠁ ࡅܰѱ!) • Python 3.3+ >>> class C: ... def f(): pass ... class D: ... def g(): pass ... >>> C.__qualname__ 'C' >>> C.f.__qualname__ 'C.f' >>> C.D.__qualname__ 'C.D' >>> C.D.g.__qualname__ 'C.D.g'
annotation • def f(a: int, b: int) -> int: return
a + b print(f.__annotations__) {'a': <class 'int'>, 'b': <class 'int'>, 'return': <class 'int'>} • inspect.signature(f).return_annotation int • inspect.signature(f.get).return_annotation Optional[int] • inspect.signature(f.key).return_annotation str
pickle, shelve • pickle: ॆ ёܳ ؘఠ۽ serialize ೞח ߑߨ
• shelve: pickleਸ ਊೠ dict ੋఠಕझܳ оח ੌDB • ل ݽف য়ے ॆ ળ ۄ࠳۞ܻ
Methods & Descriptors • Q: Ringҗ ࠺तೠ method/descriptor ਗਸ ٜ݅۰ݶ
যڌѱ ೞաਃ? • A: https://github.com/youknowone/wirerope • Rope: ೣࣻ दӒפী ೧ ೣࣻ ܴী (unbound ೣࣻ ܳ Rope ё۽ ജ) • Wire: ੋझఢझ ҳ ೣࣻী ೧ пӝ ܲ ੋझఢझ(method), ېझ(classmethod) ೣࣻ ഐী (ёী bind ػ ೣࣻܳ Wire ё۽ ജ) • hybridmethod, hybridproperty ١ ੌ߈ੋ ழझథ ҳഅীب ੜ
Descriptor analysis • ҙबࢎ೦: • ೣࣻੋо ݫࢲ٘ੋо? • descriptorੋо? •
methodੋо propertyੋо? • descriptorীࢲ ߄ੋ٘ غח ёח ޖੋо? (= methodੋо classmethodੋо - যݶ hybridੋо) • descriptorо хऱҊ ח पઁ ೣࣻח ޖੋо? • ৈ۞ ॆ ҳഅ৬ ߡীࢲ ഐജغחо?
Descriptor analysis • ҙबࢎ೦: • ೣࣻੋо ݫࢲ٘ੋо? • descriptorੋо? •
methodੋо propertyੋо? • descriptorীࢲ ߄ੋ٘ غח ёח ޖੋо? (= methodੋо classmethodੋо - যݶ hybridੋо) • descriptorо хऱҊ ח पઁ ೣࣻח ޖੋо? • ৈ۞ ॆ ҳഅ৬ ߡীࢲ ഐജغחо? ߡ߹ ߸ ࣽഥ 2.7, 3.4-3.7 / PyPy2 PyPy3 def _f(owner): return owner
Django app in single file • Django ഛਸ ٜ݅חؘ పझܳ
೧ঠغחؘ... • ழۆ জਸ పझ ٘ী ׳Ҋ ק ࣻח হਗ਼ই? • 30ܻ Django appਸ ٜ݅যࢲ పझ٘ী ղפ • https://github.com/youknowone/django-app-in-single-file