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
Hyesoo Yoo
August 18, 2018
Programming
67
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
sbt 2.0: takeoff
eed3si9n
0
190
SODA - FACT BOOK(EN)
sodainc
1
200
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
1.8k
ChromeでローカルLLM
ryu1013
0
190
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.2k
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
2k
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
180
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
510
Spec-driven Development with AI
simas
PRO
0
2.2k
Crash Auto Pipelines
veronikapj
1
350
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
260
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
220
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
610
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
540
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
2
1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
WCS-LA-2024
lcolladotor
0
970
Ethics towards AI in product and experience design
skipperchong
2
460
Ruling the World: When Life Gets Gamed
codingconduct
0
430
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
670
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
650
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
60k
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