본문 바로가기

Type10

Slack Bolt에서 view Dict를 View 객체로 변경해보자 Slack 앱을 개발하면서, 모달을 띄우는 view dict 대신 View 객체를 사용하도록 리팩토링을 진행했습니다. 사실 저는 얼마전까지만 해도 slack sdk 가 View 객체를 제공하는지 모르고 있었습니다. 그래서 매번 view 를 dict 로 작성했었는데요. 이번 글에서는 view Dict 를 View 객체로 바꾸는 과정을 공유하고, View 객체를 사용함으로써 얻은 이점에 대해 이야기하려고 합니다.   Dict 를 사용한 기존 코드처음 Slack 앱을 개발할 때는, Slack의 모달이나 메시지 레이아웃을 정의할 때 주로 딕셔너리(dict)를 사용했습니다. 예를 들어, 유저의 예치금 상태를 보여주는 모달을 열 때 다음과 같이 작성했습니다.await client.views_open( trig.. 2024. 8. 20.
0201. Who ate the cookie? For this problem you must create a program that says who ate the last cookie. If the input is a string then "Zach" ate the cookie. If the input is a float or an int then "Monica" ate the cookie. If the input is anything else "the dog" ate the cookie. The way to return the statement is: "Who ate the last cookie? It was (name)!" Ex: Input = "hi" --> Output = "Who ate the last cookie? It was Zach! .. 2023. 2. 1.
Python _ Protocol로 인터페이스 만드는 방법 Python에서 인터페이스를 구현하는 방법에는 여러 가지가 있지만 이번 글에서는 Protocol을 이용한 방법을 소개한다. 인터페이스란? 쉽게 말해 외부와 소통하기 위해 필요한 메서드를 정의한것이다. 하위 모듈들은 해당 인터페이스에 맞춰 기능을 구현한다. Protocol 사용법 아래 코드를 보자. from typing import Protocol class 감정(Protocol): def 기쁘다(self) -> str: ... def 슬프다(self) -> str: ... class 사람: def 기쁘다(self) -> str: return "기뻐!" def 화나다(self) -> str: return "화나!" class 사회생활: def 시작(self, 사람: 감정) -> None: self.사람 =.. 2022. 8. 16.
GROCERY STORE: Real Price! You are the owner of the Grocery Store. All your products are in the database, that you have created after CodeWars SQL exercises! :) Customer often need to now how much really they pay for the products. Manufacturers make different sizes of same product so it is hard to compare prices, sometimes they make packages look big, but the weight of the product is small. Make a SELECT query which will .. 2022. 7. 8.
Python _ TypedDict를 사용하는 이유(feat. mypy) Python도 Type을 확인한다구! 파이썬은 타입 힌트를 제공함으로써 해당 데이터가 어떤 타입을 갖고 있는지 알 수 있다. 다만 파이썬은 타입을 강제하지 않기 때문에 일반 런타임 환경에서는 타입의 정상여부를 알기 어렵다. 때문에 타입이 정상인지 확인하기 위해 mypy 나 pyright 같은 정적 검사 도구를 이용한다. 하지만 그럼에도 애매한 경우가 있는데 바로 dict와 같은 value들이 다양한 타입을 가질 경우이다. dict value들의 타입을 일일이 확인하고 명시하기란 매우 귀찮은 일이다. 때문에 Dict[str, Any] 처럼 value에 해당되는 타입을 Any로 넘기는 경우가 많다. 하지만 이는 바람직하지 않다. Any가 어떤 문제를 일으키는지 먼저 살펴보고, 이에 대한 해결책으로서 Type.. 2022. 6. 22.
Easy SQL: Moving Values You have access to a table of monsters as follows: ** monsters table schema ** id name legs arms characteristics Your task is to make a new table where each column should contain the length of the string in the column to its right (last column should contain length of string in the first column). Remember some column values are not currently strings. Column order and titles should remain unchang.. 2022. 5. 29.