Skip to content

Commit b459ba0

Browse files
Sotaneumdenmark1110113bernoyoun
authored
[4044bbd] 번역 요청 💬 (#22)
* merge 4044bbd 🛰 * 전체 문서 번역 업데이트 및 typo 수정 * [4044bbd] 번역 수정 * [4044bbd] 2.15, 3.9 삭제 * [4044bbd] 중복 문구 제거 * Update Google Python Style Guide/3. Python 스타일 규칙/3.10 문자열.md indent를 포함한 설명이 글의 구조를 보다 명확하게 알 수 있을것같습니다 Co-authored-by: LEE DONG GUN <gnyontu39@gmail.com> * [4044bbd] 의견 반영 * [4044bbd] 추가 번역 및 서식 수정 Co-authored-by: denmark11 <denmark1133@gmail.com> Co-authored-by: 0113bernoyoun <0113bernoyoun@gmail.com>
1 parent 3279a1b commit b459ba0

27 files changed

Lines changed: 774 additions & 631 deletions

Google Python Style Guide/2. Python 언어 규칙/2.1 Lint.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### 2.1 Lint
44

5-
- 작성한 코드에 대해 `pylint`실행시키세요.
5+
- [pylintrc](https://google.github.io/styleguide/pylintrc)를 사용하여 코드에서 `pylint`실행합니다.
66

77
<a id="s2.1.1-definition"></a>
88

@@ -62,7 +62,7 @@
6262
- 아래 예시를 참고하세요.
6363

6464
```python
65-
def viking_cafe_order(spam, beans, eggs=None):
65+
def viking_cafe_order(spam: str, beans: str, eggs: Optional[str] = None) -> str:
6666
del beans, eggs # Unused by vikings.
6767
return spam + spam + spam
6868
```

Google Python Style Guide/2. Python 언어 규칙/2.10 람다.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
### 2.10 람다 함수
44

5-
- 한 줄로 작성하세요.
5+
- 한 줄 작성에 사용하세요.
6+
- `lambda`에는 `map()` 또는 `filter()` 보다 제너레이터 구문이 더 적합합니다
67

78
<a id="s2.10.1-definition"></a>
89

910
#### 2.10.1 정의
1011

1112
- 람다는 표현에 있어 다른 `` 과는 달리 익명 함수들을 정의합니다.
12-
- 람다는 `map()`이나 `filter()`와 같은 higher-order functions(고차 함수)에 대해 콜백이나 연산자를 정의하기 위해 가끔 사용됩니다.
1313

1414
<a id="s2.10.2-pros"></a>
1515

@@ -28,7 +28,8 @@
2828

2929
#### 2.10.4 결론
3030

31-
- 람다를 한 줄로 사용하세요. 만약 코드 내부에 있는 람다 함수가 60~80글자 수 정도로 길다면 그건 아마 더 일반적인 [Lexical Scoping(렉시컬 스코핑)](#s2.16-lexical-scoping)으로 정의하는게 나을 것입니다.
31+
- 람다를 한 줄로 사용하세요. 만약 코드 내부에 있는 람다 함수가 60~80글자 수 정도로 길다면 그건 아마 더 일반적인
32+
[Lexical Scoping(렉시컬 스코핑)](#s2.16-lexical-scoping)으로 정의하는게 나을 것입니다.
3233

3334
- 곱셈 같은 일반 연산자에서는 `operator`모듈 대신에 람다 함수를 사용하세요.
3435
- 예를 들어, `operator.mul``lambda x,y : x * y` 처럼 사용하시면 됩니다.

Google Python Style Guide/2. Python 언어 규칙/2.11 조건문 표현.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@
2424

2525
<a id="s2.11.4-decision"></a>
2626

27-
#### 2.11.4
27+
#### 2.11.4 결론
2828

2929
- 간단한 상황에 좋습니다. 그 외의 경우에는 if 문을 사용하는 것이 좋습니다.
30+
- `true-false`, `if-else` 표현 등 각각의 코드가 반드시 한 줄에 표현되어야 합니다.
31+
- 보다 복잡한 구문이 필요하다면 `lambda`가 아닌 완전한 `if` 구문을 사용하세요.
32+
33+
```python
34+
35+
올바른 예:
36+
one_line = 'yes' if predicate(value) else 'no'
37+
slightly_split = ('yes' if predicate(value)
38+
else 'no, nein, nyet')
39+
the_longest_ternary_style_that_can_be_done = (
40+
'yes, true, affirmative, confirmed, correct'
41+
if predicate(value)
42+
else 'no, false, negative, nay')
43+
44+
잘못된 예:
45+
bad_line_breaking = ('yes' if predicate(value) else
46+
'no')
47+
portion_too_long = ('yes'
48+
if some_long_module.some_long_predicate_function(
49+
really_long_variable_name)
50+
else 'no, false, negative, nay')
51+
52+
```

Google Python Style Guide/2. Python 언어 규칙/2.13 Properties.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323

2424
#### 2.13.3 단점
2525

26-
- `Python 2`에서는 `object`에 상속되어있어야 합니다.
2726
- 연산자 오버 로딩(operator overloading)과 같은 부작용을 숨길 수 있습니다. 하위 클래스의 경우 혼란스러울 수 있습니다.
2827

2928
<a id="s2.13.4-decision"></a>
3029

3130
#### 2.13.4 결론
3231

33-
- 새 코드에서 속성을 사용하여 일반적으로 단순하고 가벼운 접근자 또는 `setter` 메소드를 사용했던 데이터를 접근하거나 설정합니다.
32+
- 새 코드에서 속성을 사용하여 일반적으로 가벼운 접근자 또는 `setter` 메소드를 사용했던 데이터를 접근하거나 설정합니다.
3433
- 속성은 `@property` [decorator](#s2.17-function-and-method-decorators)로 만들어야 합니다.
3534
- 속성 자체가 재정의되지 않은 경우 속성에 대한 상속은 명백하지 않을 수 있습니다. 따라서 하위 클래스에서 재정의 된 메서드가 속성에 의해 호출되도록하려면 접근자 메서드를 간접적으로 호출해야합니다([template method design pattern](https://en.wikipedia.org/wiki/Template_method_pattern)를 사용합니다.).
3635
- 올바른 예
@@ -53,27 +52,27 @@
5352
16
5453
"""
5554

56-
def __init__(self, side):
55+
def __init__(self, side: float):
5756
self.side = side
5857

5958
@property
60-
def area(self):
59+
def area(self) -> float:
6160
"""사각형의 면적을 가져오거나 설정합니다."""
6261
return self._get_area()
6362

6463
@area.setter
65-
def area(self, area):
66-
return self._set_area(area)
64+
def area(self, area: float):
65+
self._set_area(area)
6766

68-
def _get_area(self):
67+
def _get_area(self) -> float:
6968
"""'면적'속성을 계산하기 위한 간접 접근자입니다."""
7069
return self.side ** 2
7170

72-
def _set_area(self, area):
71+
def _set_area(self, area: float):
7372
"""'면적' 속성을 설정하기 위한 간접 설정자입니다."""
7473
self.side = math.sqrt(area)
7574

7675
@property
77-
def perimeter(self):
76+
def perimeter(self) -> float:
7877
return self.side * 4
7978
```

Google Python Style Guide/2. Python 언어 규칙/2.15 사용하지 않는 언어의 기능.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

Google Python Style Guide/2. Python 언어 규칙/2.16 렉시컬 스코핑(Lexical Scoping).md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
- 이 기능에 대해 사용예는 다음과 같습니다.
1616

1717
```python
18-
def get_adder(summand1):
18+
def get_adder(summand1: float) -> Callable[[float], float]:
1919
"""주어진 숫자에 숫자를 더하는 함수를 반환합니다."""
20-
def adder(summand2):
20+
def adder(summand2: float) -> float:
2121
return summand1 + summand2
2222

2323
return adder
@@ -37,7 +37,7 @@
3737

3838
```python
3939
i = 4
40-
def foo(x):
40+
def foo(x: Iterable[int]):
4141
def bar():
4242
print(i, end='') # foo 함수 밖에 있는 i와 동일한 i를 사용합니다.
4343
# ...

Google Python Style Guide/2. Python 언어 규칙/2.17 함수와 메서드 Decorators.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### 2.17 함수와 메서드 Decorators
44

5-
- Decorators는 확실하게 이점이 있을 때에 신중하게 사용하세요. `@staticmethod`는 피하고 `@classmethod`의 사용은 제한하세요.
5+
- Decorators는 확실하게 이점이 있을 때에 신중하게 사용하세요. `staticmethod`는 피하고 `classmethod`의 사용은 제한하세요.
66

77
<a id="s2.17.1-definition"></a>
88

@@ -48,5 +48,5 @@
4848
- Decorator는 분명한 이점이 있더라도 현명하게 사용해야 합니다. Decorator는 import와 명명 지침을 따라야 합니다. Decorator pydoc는 decorator 함수 임을 분명히 명시해야합니다. dcorator를 위한 유닛 테스트(unit test)를 사용해야합니다.
4949
- Decorator(예. 파일, 소켓, 데이터베이스 연결 등) 를 실행할 때 (`pydoc` 혹은 기타 도구를 import 시간에 가져올 때) 사용 못할 수 있으므로 Decorator의 외부 의존성을 피하세요. 유효한 매개변수를 가진 Decorator은 모든 경우에 작동할 수 있도록 보장되어야 합니다.
5050
- Decorator는 "Top level code"의 특별한 경우일 때에는 [main](#s3.17-main) 항목에 자세한 내용이 있습니다.
51-
- 기존 라이브러리에 정의된 API와 통합하기 위해 강제하지 않는 한 "@static method"를 사용하지 마세요. 대신 모듈 레벨 함수를 쓰세요.
52-
- 프로세스 전체 캐시 등 필요한 global state를 수정하는 명명된 생성자 또는 클래스별 루틴을 작성할 때만 "@classmethod"를 사용하세요.
51+
- 기존 라이브러리에 정의된 API와 통합하기 위해 강제하지 않는 한 "staticmethod"를 사용하지 마세요. 대신 모듈 레벨 함수를 쓰세요.
52+
- 프로세스 전체 캐시 등 필요한 global state를 수정하는 명명된 생성자 또는 클래스별 루틴을 작성할 때만 "classmethod"를 사용하세요.

Google Python Style Guide/2. Python 언어 규칙/2.19 강한 기능.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#### 2.19.1 정의
1010

11-
- Python은 매우 유연한 언어로서 당신에게 많은 화려한 기능을 줍니다. (e.g. 사용자 정의 mtaclasses, bytecode 접근, 즉각적인 컴파일, 동적 상속, object reparenting, import hacks, reflection (`getattr()`의 일부 사용), 시스템 내부 수정 등.)
11+
- Python은 매우 유연한 언어로서 당신에게 많은 화려한 기능을 줍니다. (e.g. 사용자 정의 mtaclasses, bytecode 접근, 즉각적인 컴파일, 동적 상속, object reparenting, import hacks, reflection (`getattr()`의 일부 사용), 시스템 내부 수정, 커스텀 Cleanup을 위한 `__del__` 메소드 등.)
1212

1313
<a id="s2.19.2-pros"></a>
1414

@@ -28,4 +28,4 @@
2828
#### 2.19.4 결론
2929

3030
- 코드에서 이러한 기능은 피하세요.
31-
- 이러한 기능을 내부적으로 사용하는 표준 라이브러리 모듈과 클래스는 사용할 수 있습니다. (예를 들면, `abc.ABCMeta`, `collections.namedtuple`, `dataclasses`, `enum`)
31+
- 이러한 기능을 내부적으로 사용하는 표준 라이브러리 모듈과 클래스는 사용할 수 있습니다. (예를 들면, `abc.ABCMeta`, `dataclasses`, `enum`)

Google Python Style Guide/2. Python 언어 규칙/2.2 import.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
### 2.2 Imports
44

5-
- `import`문을 사용할때 package와 module을 대상으로만 사용해야하고 각각의 클래스나 함수에 대해 사용하면 안됩니다. 다만 [typing 모듈](#s3.19.12-imports)을 사용할때는 예외입니다.
5+
- `import`문을 사용할때 package와 module을 대상으로만 사용해야하고 각각의 클래스나 함수에 대해 사용하면 안됩니다. 다만
6+
[typing 모듈](#s3.19.12-imports),
7+
[typing_extensions module](https://github.com/python/typing/tree/master/typing_extensions),
8+
그리고 [six.moves module](https://six.readthedocs.io/#module-six.moves)
9+
을 사용할때는 예외입니다.
610

711
<a id="s2.2.1-definition"></a>
812

@@ -41,4 +45,4 @@
4145

4246
- import된것들과 관련있는 이름을 사용하지마세요.
4347
- 모듈이 같은 패키지에 있더라도 전체 패키지 이름을 사용하세요.
44-
- 이는 무심코 패키지를 두번 import 하는것을 예방하는 것에 도움이 됩니다. 다만 [typing 모듈](#s3.19.12-imports) 를 import할때는 이러한 규칙들에서 예외될 수 있습니다.
48+
- 이는 무심코 패키지를 두번 import 하는것을 예방하는 것에 도움이 됩니다.

Google Python Style Guide/2. Python 언어 규칙/2.20 현대의 파이썬.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### 2.20 Modern Python : Python 3 그리고 from, \_\_future\_\_, imports
44

5-
- Python 3 버전이 나왔습니다. 아직 프로젝트에 Python 3을 사용할 준비가 되어있는 건 아니지만 모든 코드는 호환되도록 작성되어야 합니다. (가능한 경우에 Python 3에 따라 테스트합니다.)
5+
- Python 3 버전이 나왔습니다! 아직 프로젝트에 Python 3을 사용할 준비가 되어있는 건 아니지만 모든 코드는 호환되도록 작성되어야 합니다. (가능한 경우에 Python 3에 따라 테스트합니다.)
66

77
<a id="s2.20.1-definition"></a>
88

0 commit comments

Comments
 (0)