๐ŸŽŠ Pycon KR 2019

ํŒŒ์ด์ฝ˜ KR 2019์— ๊ฐ€๋ณด๋ฉด์„œ ๋“ค์—ˆ๋˜ ๊ฝค ์ข‹์•˜๋˜ ์„ธ์…˜๋“ค ๋ชฉ๋ก + ๋‚ด์šฉ์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ •๋ฆฌํ•˜๋ฉด์„œ ๊ทธ ๋‚ด์šฉ์„ ๋ธ”๋กœ๊ทธ์—๋„ ์˜ฎ๊ฒจ๋†“๋Š”๋‹ค. ํšŒ์‚ฌ๋ถ„๋“ค๊ป˜ ๊ณต์œ ํ•  ๋ชฉ์ ์œผ๋กœ ์ ์–ด๋†“์•„์„œ ๋งŽ์€ ๋ถ€๋ถ„์ด ๋น ์ ธ์žˆ๊ณ , ์—„์ฒญ ์ถ•์•ฝ๋˜์–ด ์žˆ๋Š” ๊ฒƒ๋„ ์žˆ๋‹ค.

ํ‹€๋ฆฐ ๋‚ด์šฉ์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ณ , ์ •ํ™•ํ•˜๊ฒŒ ์ •๋ฆฌํ•˜์ง€ ๋ชปํ•œ ๋‚ด์šฉ์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ์œผ๋‹ˆโ€ฆ ์•Œ์•„์„œ ๊ฐ์•ˆํ•˜๊ณ  ๋ด์ฃผ์„ธ์š”..

Code review tips for Pythonistas

SQUEEZE Inc์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํŒŒ์ด์ฝ˜ ์žฌํŒฌ

Style Guide, Formatter

์˜๊ฒฌ ๋‹คํˆผ์„ ์ค„์ด๊ธฐ ์œ„ํ•ด์„œ ์ž๋™ ํฌ๋งคํŒ… ๋„๊ตฌ๋ฅผ ์ ์šฉํ•˜๋ผ

How to write PR

PR Template์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. ๋ฐœํ‘œ์—์„œ ๋‚˜์˜จ ๋‚ด์šฉ ์ค‘์— ์šฐ๋ฆฌํ•œํ…Œ ํ•„์š”ํ• ๋งŒ ํ•œ ๊ฒƒ๋“ค์€ ์‚ฌํ•ญ๋“ค์€ ์•„๋ž˜ ์ •๋„์ด๋‹ค.

  • Description
  • checked list
  • related PR, Issues
  • screenshot of UI changes
  • dependency updates

๋„ˆ๋ฌด ํฐ PR์€ ๋ฆฌ๋ทฐํ•˜๊ธฐ ๋„ˆ๋ฌด ํž˜๋“ค๋‹ค.

  • Splitting PR into small PRs
  • makes reviews easy and reponsibility is clear
  • Checking diff size by โ€œdangerโ€

Sharing Working In Progress

Draft PR์„ ์ ๊ทน์ ์œผ๋กœ ํ™œ์šฉํ•˜๋ฉด, ๊ตฌํ˜„์ด ๋๋‚˜๊ธฐ ์ „ ์กฐ์–ธ์„ ๋ฐ›์„ ์ˆ˜๋„ ์žˆ๊ณ , ํ•„์š”ํ•œ ์ •๋ณด๋“ค์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋‹ค.

how to write review comments

์ผ๊ด€์„ฑ ์žˆ๊ฒŒ ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋‹ฌ์ž. ์ผ์ •ํ•œ ๊ทœ์น™์œผ๋กœ ๋‚ด ์˜๊ฒฌ๊ณผ ์‚ฌ์‹ค์„ ๊ตฌ๋ถ„ํ•ด์ฃผ์ž.

Long Discussion

  • face to face๋กœ ๊ฐ€์ž. ์ œ์ผ ๋ช…ํ™•ํ•œ ๋ฐฉ๋ฒ•์ด๋‹ค.
  • Issue๋กœ ์˜ฎ๊ฒจ๋ผ. PR์—์„œ์˜ Long Discussion์€ ์ข‹์ง€ ์•Š๋‹ค.

Mob Code Review

code review๋ฅผ ํ•ด์•ผํ•˜๋Š” PR๋“ค์ด ์Œ“์—ฌ๋งŒ ๊ฐ€๊ณ  merge๋ฅผ ํ•  ์ˆ˜ ์—†์„ ๋•Œ mob programmingํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ mob code review๋ฅผ ํ•˜์ž. ์‹œ๋‹ˆ์–ด ํ”„๋กœ๊ทธ๋ž˜๋จธ๋งŒ์ด ์ฝ”๋“œ ๋ฆฌ๋ทฐํ•˜๋Š” ์‚ฌํ•ญ์„ ํ”ผํ•  ์ˆ˜ ์žˆ๊ณ (์‹œ๋‹ˆ์–ด ํ”„๋กœ๊ทธ๋ž˜๋จธ์˜ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๊ด€์ ์„ ์ฃผ๋‹ˆ์–ด๋„ ๊ฐ™์ด ๋ฐฐ์šฐ๊ฒŒ ๋˜๋ฉด์„œ), ๊ทธ ์‹œ๊ฐ„์„ ํ•œ์ •ํ•ด์„œ ๋น ๋ฅธ ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. (ํ•˜๋‚˜์˜ PR์„ ๋ณด๊ณ  ๋‹ค ๊ฐ™์ด ์•‰์Œ)

Playful Comments

ํ…์ŠคํŠธ๋งŒ์œผ๋กœ๋Š” ๋„ˆ๋ฌด ๋”ฑ๋”ฑํ•ด ๋ณด์ด๊ณ  ์„œ๋กœ๊ฐ„์˜ ๊ฐ์ •์ด ์ฐจ๋‹จ๋˜๋Š”? ๊ทธ๋Ÿฐ ์ƒํ™ฉ์„ ๋งํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

๊ทธ๋ž˜์„œ ์ด๋ชจ์ง€๊ฐ€ ๊ณผํ•ด๋ณด์ผ ์ˆ˜ ์žˆ์–ด๋„ โ€œ์ •ํ™•ํ•œโ€ ์˜์‚ฌํ‘œํ˜„์„ ์œ„ํ•ด ๋‹ฌ์•„์ฃผ์ž. ์ด๋Š” ๊ฐ์ •์„ ์„œ๋กœ ์ฃผ๊ณ ๋ฐ›๋Š” ๊ฒƒ์ด ๋ชฉ์ ์ด ์•„๋‹Œ ์ •ํ™•ํ•œ ์˜์‚ฌํ‘œํ˜„์ด ๋ชฉ์ ์ด๋‹ค.

Real World Async IO

lablup ๋ถ„์ด ๋‚˜์˜ค์…”์„œ ๋ฐœํ‘œํ•œ ๋‚ด์šฉ์ด๋‹ค.

Async IO

PEP 3156 โ€“ Asynchronous IO Support Rebooted: the โ€œasyncioโ€ Module

  • ๋ณ‘๋ ฌํ™” X, ์ด๋ฒคํŠธ ๋ฃจํ”„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ฝ”๋“œ๋ฅผ ๋Œ๋ฆด ์ˆ˜ ์žˆ๋„๋ก ํ•จ
  • coroutine function์„ ์„ ์–ธํ•ด์„œ ์‚ฌ์šฉ์„ ํ•จ
  • asyncio.run vs asycnio.create_task
  • ๋น„๋™๊ธฐ ์ฝ”๋“œ๋กœ ์ง„์ž… vs ํ๋ฆ„ ๋ถ„๊ธฐ

Cancellation

  • await์ด ์žˆ์–ด์•ผ cancel์ด ๊ฐ€๋Šฅ
  • CancelledError๊ฐ€ raising ๋  ๊ฒƒ
  • await์€ ๋ชจ๋‘ future์•„๋‹ˆ๋ฉด task์ด๋‹ค
  • what is futurue in python
    • future -> ์ฆ‰์‹œ ์ทจ์†Œ ๋ฐ ์™„๋ฃŒ, task๋Š” clean up ์ž‘์—…์„ ์œ„ํ•ด ์ถ”๊ฐ€๋กœ ๋น„๋™๊ธฐ ์ž‘์—…์„ ๋” ํ•ด์•ผ ํ•œ๋‹ค.
  • asyncio.current_task().cancel() vs raise asyncio.CancelledError ์˜ ์ฐจ์ด์ 
    • ์ „์ž๋Š” ์“ฐ์ง€ ๋ง์ž. ํ•ด๋‹น ํƒœ์Šคํฌ ์™ธ๋ถ€์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ ˆ์ด์ง•์ด ์•ˆ๋˜์–ด์„œ ์•Œ ์ˆ˜๊ฐ€ ์—†๋‹ค.
  • Cacnelled Error๋Š” ๋ช…์‹œ์ ์œผ๋กœ ์žก์•„์„œ raise๋ฅผ ๋‹ค์‹œ ํ•˜์ž
  • create task์˜ ์ตœ์ƒ์œ„ ์ฝ”๋ฃจํ‹ด์ด๋ผ๋ฉด raise๋ฅผ ์•ˆํ•ด๋„ ๋˜๊ฒ ์ง€๋งŒ, ๊ทธ๋Ÿฐ๊ฑฐ ์ž˜ ์ƒ๊ฐํ•ด์„œ ์ฒ˜๋ฆฌํ•˜์ž

Issue 32528: Change base class for futures.CancelledError - Python tracker

  • ์ด์ œ baseexception์œผ๋กœ ๋“ค์–ด๊ฐ„๋‹ค.
  • python base exception์€ keyboardinterrupt, system exit, generator exit, cancellation exception

Clean Up

  • cancelํ•˜๊ณ  ๋‚˜์„œ๋Š” ๋ฌด์กฐ๊ฑด await๋ฅผ ํ•œ๋ฒˆ ๊ฑธ์–ด์ค˜์•ผ ํ•œ๋‹ค. -> clean up
  • asyncio.wait_for ํ˜ธ์ถœํ•˜๋ฉด clean up๊นŒ์ง€ ๊ธฐ๋‹ค๋ ค์คŒ (๋Œ€์‹  TimeoutError๊ฐ€ raising๋จ)
  • clean up์—์„œ coroutine ํ˜ธ์ถœ์ด ๊ฐ€๋Šฅํ•œ ์ ์„ ๊ฐ„๊ณผํ•˜์ง€ ๋ง์ž
  • library๊ฐ€ cacnellableํ•˜์ง€ ์•Š์„๊ฒฝ์šฐ ์ฃฝ์Œ์ด๋‹ค. asyncio.shield๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์ž. cancel์•ˆํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ํ•ด์ฃผ๋Š” ๊ฒƒ์ด๋‹ค.

  • aiojobs aiohttp
  • websocket๊ฐ™์€ ๊ฒฝ์šฐ๋Š” cacnel์€ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผํ•˜๋‚˜?
  • aioredis๋Š” unsubscribe๊ฐ€ ์•ˆ๋จ. ์ปค๋„ฅ์…˜ ํ’€์ด ์†Œ์ง„๋จ. subscribe๋Š” ์ธ์Šคํ„ด์Šค๋งˆ๋‹ค ํ•˜๋‚˜ ๋šซ์–ด์„œ ๊ณต๋™ ์‚ฌ์šฉ ๋กœ์ปฌ๋กœ ๋ธŒ๋กœ๋“œ์บ์ŠคํŠธ ํ•ด์ฃผ์ž
  • partial๊ฐ™์€๊ฒŒ type ๋ณด์กด์ด ์•ˆ๋˜์–ด์„œ ๋ฒ„๊ทธ๊ฐ€ ๋‚˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค.

Structured Concurrency

  • fire and forget ํŒจํ„ด -> go์˜ go๋ž‘ ๋น„์Šทํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ž
  • happy eyeballs ์ง€์›ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด ์ •๋ง ์ข‹๋‹ค.
  • task group, supervisor -> ์ด ๊ธฐ๋Šฅ์€ ๊ตฌํ˜„์ด ๋‹ค ์•ˆ๋˜์–ด์„œ 3.8์— ๋ชป๋‚˜์˜จ๋‹คโ€ฆ

Advanced Python testing techniques

์œ„์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ดํŽด๋ณด์ž


  • Feature
    • Scenario
      • Given
      • When
      • Then
  • DSL์„ ์ž˜ ํ™œ์šฉํ•˜๋Š” ๋“ฏ ํ•จ.
  • ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ตฌ์กฐ๋Š” ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ๋ž‘ ํฌ๊ฒŒ ๋‹ค๋ฅธ ๊ฒƒ์ด๋ผ๊ธฐ ๋ณด๋‹ค๋Š” Feature๋ž‘ Scenario๊ฐ€ ์•ž์— ๋ถ™๋Š” ๊ฒƒ์ด ๋” ๊ทธ๋Ÿฐ ๋“ฏ?
  • ์กฐ๊ธˆ ๋” ๋น„์ฆˆ๋‹ˆ์Šค ์ ์ธ ์š”๊ตฌ์‚ฌํ•ญ์— ๋Œ€ํ•ด์„œ ์ง‘์ค‘ํ•˜๋Š” ๋“ฏํ•จ
  • Parameterized test๋Š” ์ผ๋ฐ˜์ ์ธ ํ…Œ์ŠคํŠธ๋ž‘ ๋น„์Šท๋น„์Šท

  • ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ๋” ์•Œ์•„๋ณด์ž -> ์–ด๋–ป๊ฒŒ ๋” ์ž˜ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋ญ๊ฐ€ ๊ดœ์ฐฎ์€์ง€. -> ๋˜ ์˜ค๋ฒ„์—”์ง€๋‹ˆ์–ด๋ง์€ ์•„๋‹Œ์ง€? -> ๊ทผ๋ฐ ์ง€๊ธˆ ๊ธ€์„ ์“ธ๋•Œ๊นŒ์ง€ ๋˜ ์•ˆํ–ˆ๋„ค?? -> ๋‚˜์ค‘์— ๋‹ค์‹œ ์ด ๊ธ€์„ ๋ณด๋ฉด์„œ bdd๋ฅผ ํ•ด๋ณผ ๋‚ ์ด ์˜ค์ง€ ์•Š์„๊นŒ?

๋‹จ์  & ํŒ

  • ์ž์—ฐ์–ด์™€ ํŒŒ์ด์ฌ ์ฝ”๋“œ์˜ ๋ถ„๋ฆฌ -> ๋””๋ฒ„๊ทธ๊ฐ€ ์‰ฌ์šธ๊นŒ?
  • ์ตœ๋Œ€ํ•œ atomicํ•˜๊ฒŒ ๋ฌธ์žฅ์„ ๊ตฌ์„ฑํ•˜์ž
  • given์—์„œ context๋ฅผ ๋งŒ๋“ค์–ด์„œ when์—์„œ ์ˆ˜ํ–‰ํ•œ ๋™์ž‘์„ context์— ์ €์žฅํ•˜๊ณ  then์—์„œ ํ™•์ธํ•˜์ž

-

  • ์™ธ๋ถ€ ์„œ๋ฒ„ ๋ถ„๋ฆฌ? -> HTTP Mocking
  • github gabrielfalcao/HTTPretty
  • ๊ทธ๋Ÿผ ์‹คํŒจํ•œ ์ƒํ™ฉ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ & timeout๊ฐ™์€ ๋„คํŠธ์›Œํฌ ์—๋Ÿฌ๋„ ์ž˜ ํ•  ์ˆ˜ ์žˆ๋‚˜?

-

  • Monkey Patching
  • module์˜ ์ผ๋ถ€๋ถ„๋งŒ mocking -> ํŒŒ์ด์ฌ๊ฐ™์€ ๋…ธ๊ทผ๋ณธ ์–ธ์–ด๋งŒ ๊ฐ€๋Šฅํ•œ ๊ฒƒ์€ ์•„๋‹Œ๊ฐ€? Java๋Š” ํ”„๋ก์‹œ ์จ์—ฌํ•  ๊ฒƒ ๊ฐ™์€๋ฐ

-

  • Hypothesis
  • test function์„ randomํ•œ input์„ ๋ฐ›๋„๋ก ๋งŒ๋“ค์–ด์คŒ
  • HypothesisWorks/hypothesis
  • (๊ทธ๋Ÿผ ์ด๊ฑธ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ํ•œ๋ฒˆ๋„ ์‹คํŒจํ•˜๋ฉด ์•ˆ๋˜๋Š” ๋“ฏ ํ•˜๋‹ค)

-

  • Benchmark testing
  • ionelmc/pytest-benchmark
  • ๊ทธ๋ž˜๋„ ๋ฒค์น˜๋งˆํฌ๋Š” ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋Š” ํ…Œ์ŠคํŠธ๋ฅผ ๋Œ๋ฆฌ๊ธฐ ์œ„ํ•จ์ด ์•„๋‹ˆ๋ผ ์งง๊ฒŒ ๊ฑธ๋ฆฌ๋Š”๋ฐ ์ตœ์ ํ™”๋ฅผ ํ•ด์•ผํ•˜๋Š” ํ…Œ์ŠคํŠธ๋ฅผ ๋Œ๋ฆฌ๋Š” ๊ฒƒ์ด ์•„๋‹Œ๊ฐ€? -> ๊ทธ๋ƒฅ ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋ฉด ๋…ธ์ด์ฆˆ ์ œ๊ฑฐ๊ฐ€ ์•ˆ๋ ๋“ฏโ€ฆ

-

  • pytest plugin ํ•„์š”ํ•˜๋‹ค๋ฉด ์ž‘์„ฑํ•ด์„œ ์“ฐ์ž

๊ทธ ์™ธ ์ž๋ฃŒ๋งŒ ๋ดค๋˜ ์ž๋ฃŒ๋“ค

September 3, 2019 ์— ์ž‘์„ฑ
Tags: conference ์ปค๋ฎค๋‹ˆํ‹ฐ