@@ -121,18 +121,17 @@ msgstr ""
121
121
"노출합니다."
122
122
123
123
#: ../../library/weakref.rst:68
124
- #, fuzzy
125
124
msgid ""
126
125
"Not all objects can be weakly referenced. Objects which support weak "
127
126
"references include class instances, functions written in Python (but not "
128
127
"in C), instance methods, sets, frozensets, some :term:`file objects <file"
129
128
" object>`, :term:`generators <generator>`, type objects, sockets, arrays,"
130
129
" deques, regular expression pattern objects, and code objects."
131
130
msgstr ""
132
- "모든 객체를 약하게 참조할 수 있는 것은 아닙니다; 가능한 객체에는 클래스 인스턴스, 파이썬으로 작성된 함수 (C로 작성된 함수는 "
133
- "아닙니다), 인스턴스 메서드, 집합, 불변 집합(frozenset), 일부 :term:`파일 객체 <file object>`, "
134
- ":term:`제너레이터 <generator>`, 형 객체, 소켓, 배열, 데크(deque), 정규식 패턴 객체 및 코드 객체가 "
135
- "포함됩니다."
131
+ "모든 객체를 약하게 참조할 수 있는 것은 아닙니다. 약한 참조를 지원하는 객체에는 클래스 인스턴스, 파이썬으로 작성된 함수 (C로 "
132
+ "작성된 함수는 아닙니다), 인스턴스 메서드, 집합, 불변 집합(frozenset), 일부 :term:`파일 객체 <file "
133
+ "object>`, :term:`제너레이터 <generator>`, 형 객체, 소켓, 배열, 데크(deque), 정규식 패턴 객체 및"
134
+ " 코드 객체가 포함됩니다."
136
135
137
136
#: ../../library/weakref.rst:74
138
137
msgid "Added support for thread.lock, threading.Lock, and code objects."
@@ -154,6 +153,10 @@ msgid ""
154
153
"\n"
155
154
"obj = Dict(red=1, green=2, blue=3) # this object is weak referenceable"
156
155
msgstr ""
156
+ "class Dict(dict):\n"
157
+ " pass\n"
158
+ "\n"
159
+ "obj = Dict(red=1, green=2, blue=3) # 이 객체는 약한 참조할 수 있습니다"
157
160
158
161
#: ../../library/weakref.rst:87
159
162
msgid ""
@@ -201,14 +204,13 @@ msgstr ""
201
204
"오래전에 등록된 콜백 순으로 호출됩니다."
202
205
203
206
#: ../../library/weakref.rst:112
204
- #, fuzzy
205
207
msgid ""
206
208
"Exceptions raised by the callback will be noted on the standard error "
207
209
"output, but cannot be propagated; they are handled in exactly the same "
208
210
"way as exceptions raised from an object's :meth:`~object.__del__` method."
209
211
msgstr ""
210
- "콜백에 의해 발생한 예외는 표준 에러 출력에 표시되지만, 전파될 수는 없습니다; 객체의 :meth:`__del__` 메서드에서 "
211
- "발생한 예외와 정확히 같은 방식으로 처리됩니다."
212
+ "콜백에 의해 발생한 예외는 표준 에러 출력에 표시되지만, 전파될 수는 없습니다; 객체의 :meth:`~object. __del__` "
213
+ "메서드에서 발생한 예외와 정확히 같은 방식으로 처리됩니다."
212
214
213
215
#: ../../library/weakref.rst:116
214
216
msgid ""
@@ -251,7 +253,6 @@ m
E30A
sgid "Added the :attr:`__callback__` attribute."
251
253
msgstr ":attr:`__callback__` 어트리뷰트를 추가했습니다."
252
254
253
255
#: ../../library/weakref.rst:140
254
- #, fuzzy
255
256
msgid ""
256
257
"Return a proxy to *object* which uses a weak reference. This supports "
257
258
"use of the proxy in most contexts instead of requiring the explicit "
@@ -323,6 +324,13 @@ msgid ""
323
324
">>> d[k2] = 2 # d = {k1: 2}\n"
324
325
">>> del k1 # d = {}"
325
326
msgstr ""
327
+ ">>> class T(str): pass\n"
328
+ "...\n"
329
+ ">>> k1, k2 = T(), T()\n"
330
+ ">>> d = weakref.WeakKeyDictionary()\n"
331
+ ">>> d[k1] = 1 # d = {k1: 1}\n"
332
+ ">>> d[k2] = 2 # d = {k1: 2}\n"
333
+ ">>> del k1 # d = {}"
326
334
327
335
#: ../../library/weakref.rst:188
328
336
msgid "A workaround would be to remove the key prior to reassignment::"
@@ -340,6 +348,14 @@ msgid ""
340
348
">>> d[k2] = 2 # d = {k2: 2}\n"
341
349
">>> del k1 # d = {k2: 2}"
342
350
msgstr ""
351
+ ">>> class T(str): pass\n"
352
+ "...\n"
353
+ ">>> k1, k2 = T(), T()\n"
354
+ ">>> d = weakref.WeakKeyDictionary()\n"
355
+ ">>> d[k1] = 1 # d = {k1: 1}\n"
356
+ ">>> del d[k1]\n"
357
+ ">>> d[k2] = 2 # d = {k2: 2}\n"
358
+ ">>> del k1 # d = {k2: 2}"
343
359
344
360
#: ../../library/weakref.rst:199 ../../library/weakref.rst:220
345
361
msgid "Added support for ``|`` and ``|=`` operators, as specified in :pep:`584`."
@@ -369,13 +385,12 @@ msgid ""
369
385
msgstr "값을 약하게 참조하는 매핑 클래스. 값에 대한 강한 참조가 더는 존재하지 않을 때 딕셔너리의 항목이 삭제됩니다."
370
386
371
387
#: ../../library/weakref.rst:223
372
- #, fuzzy
373
388
msgid ""
374
389
":class:`WeakValueDictionary` objects have an additional method that has "
375
390
"the same issues as the :meth:`WeakKeyDictionary.keyrefs` method."
376
391
msgstr ""
377
- ":class:`WeakValueDictionary` 객체에는 :class:`WeakKeyDictionary` 객체의 "
378
- ":meth:`keyrefs` 메서드와 같은 문제가 있는 추가 메서드가 있습니다."
392
+ ":class:`WeakValueDictionary` 객체에는 :class:`WeakKeyDictionary.keyrefs` 메서드와 "
393
+ " 같은 문제가 있는 추가 메서드가 있습니다."
379
394
380
395
#: ../../library/weakref.rst:229
381
396
msgid "Return an iterable of the weak references to the values."
@@ -419,6 +434,23 @@ msgid ""
419
434
">>> r()\n"
420
435
">>>"
421
436
msgstr ""
437
+ ">>> class C:\n"
438
+ "... def method(self):\n"
439
+ "... print(\" method called!\" )\n"
440
+ "...\n"
441
+ ">>> c = C()\n"
442
+ ">>> r = weakref.ref(c.method)\n"
443
+ ">>> r()\n"
444
+ ">>> r = weakref.WeakMethod(c.method)\n"
445
+ ">>> r()\n"
446
+ "<bound method C.method of <__main__.C object at 0x7fc859830220>>\n"
447
+ ">>> r()()\n"
448
+ "method called!\n"
449
+ ">>> del c\n"
450
+ ">>> gc.collect()\n"
451
+ "0\n"
452
+ ">>> r()\n"
453
+ ">>>"
422
454
423
455
#: ../../library/weakref.rst:264
424
456
msgid ""
@@ -448,15 +480,14 @@ msgstr ""
448
480
":const:`None`\\ 이 반환됩니다."
449
481
450
482
#: ../../library/weakref.rst:280
451
- #, fuzzy
452
483
msgid ""
453
484
"Exceptions raised by finalizer callbacks during garbage collection will "
454
485
"be shown on the standard error output, but cannot be propagated. They "
455
486
"are handled in the same way as exceptions raised from an object's "
456
487
":meth:`~object.__del__` method or a weak reference's callback."
457
488
msgstr ""
458
489
"가비지 수거 중에 파이널라이저 콜백에서 발생한 예외는 표준 에러 출력에 표시되지만, 전파할 수는 없습니다. 객체의 "
459
- ":meth:`__del__` 메서드나 약한 참조의 콜백에서 발생하는 예외와 같은 방식으로 처리됩니다."
490
+ ":meth:`~object. __del__` 메서드나 약한 참조의 콜백에서 발생하는 예외와 같은 방식으로 처리됩니다."
460
491
461
492
#: ../../library/weakref.rst:286
462
493
msgid ""
@@ -595,6 +626,14 @@ msgid ""
595
626
" print(\" Object is still live!\" )\n"
596
627
" o.do_something_useful()"
597
628
msgstr ""
629
+ "# r은 약한 참조 객체입니다\n"
630
+ "o = r()\n"
631
+ "if o is None:\n"
632
+ " # 참조대상이 가비지 수거되었습니다\n"
633
+ " print(\" Object has been deallocated; can't frobnicate.\" )\n"
634
+ "else:\n"
635
+ " print(\" Object is still live!\" )\n"
636
+ " o.do_something_useful()"
598
637
599
638
#: ../../library/weakref.rst:400
600
639
msgid ""
@@ -652,6 +691,23 @@ msgid ""
652
691
" ob = (ob, self.__counter)\n"
653
692
" return ob"
654
693
msgstr ""
694
+ "import weakref\n"
695
+ "\n"
696
+ "class ExtendedRef(weakref.ref):\n"
697
+ " def __init__(self, ob, callback=None, /, **annotations):\n"
698
+ " super().__init__(ob, callback)\n"
699
+ " self.__counter = 0\n"
700
+ " for k, v in annotations.items():\n"
701
+ " setattr(self, k, v)\n"
702
+ "\n"
703
+ " def __call__(self):\n"
704
+ " \"\"\" 참조대상과 참조가 호출된 횟수를 포함하는 쌍을 반환합니다.\n"
705
+ " \"\"\" \n"
706
+ " ob = super().__call__()\n"
707
+ " if ob is not None:\n"
708
+ " self.__counter += 1\n"
709
+ " ob = (ob, self.__counter)\n"
710
+ " return ob"
655
711
656
712
#: ../../library/weakref.rst:438
657
713
msgid "Example"
@@ -681,6 +737,17 @@ msgid ""
681
737
"def id2obj(oid):\n"
682
738
" return _id2obj_dict[oid]"
683
739
msgstr ""
740
+ "import weakref\n"
741
+ "\n"
742
+ "_id2obj_dict = weakref.WeakValueDictionary()\n"
743
+ "\n"
744
+ "def remember(obj):\n"
745
+ " oid = id(obj)\n"
746
+ " _id2obj_dict[oid] = obj\n"
747
+ " return oid\n"
748
+ "\n"
749
+ "def id2obj(oid):\n"
750
+ " return _id2obj_dict[oid]"
684
751
685
752
#: ../../library/weakref.rst:465
686
753
msgid "Finalizer Objects"
@@ -727,11 +794,15 @@ msgid ""
727
794
">>> exit()\n"
728
795
"obj dead or exiting"
729
796
msgstr ""
797
+ ">>> obj = Object()\n"
798
+ ">>> weakref.finalize(obj, print, \" obj dead or exiting\" )\n"
799
+ "<finalize object at ...; for 'Object' at ...>\n"
800
+ ">>> exit()\n"
801
+ "obj dead or exiting"
730
802
731
803
#: ../../library/weakref.rst:526
732
- #, fuzzy
733
804
msgid "Comparing finalizers with :meth:`~object.__del__` methods"
734
- msgstr "파이널라이저와 :meth:`__del__` 메서드의 비교"
805
+ msgstr "파이널라이저와 :meth:`~object. __del__` 메서드의 비교"
735
806
736
807
#: ../../library/weakref.rst:528
737
808
msgid ""
@@ -747,20 +818,18 @@ msgid "the object is garbage collected,"
747
818
msgstr "객체가 가비지 수거됩니다,"
748
819
749
820
#: ../../library/weakref.rst:533
750
- #, fuzzy
751
821
msgid "the object's :meth:`!remove` method is called, or"
752
- msgstr "객체의 :meth:`remove` 메서드가 호출됩니다, 또는"
822
+ msgstr "객체의 :meth:`! remove` 메서드가 호출됩니다, 또는"
753
823
754
824
#: ../../library/weakref.rst:534
755
825
msgid "the program exits."
756
826
msgstr "프로그램이 종료합니다."
757
827
758
828
#: ../../library/weakref.rst:536
759
- #, fuzzy
760
829
msgid ""
761
830
"We might try to implement the class using a :meth:`~object.__del__` "
762
831
"method as follows::"
763
- msgstr "다음과 같이 :meth:`__del__` 메서드를 사용하여 클래스를 구현하려고 시도할 수 있습니다::"
832
+ msgstr "다음과 같이 :meth:`~object. __del__` 메서드를 사용하여 클래스를 구현하려고 시도할 수 있습니다::"
764
833
765
834
#: ../../library/weakref.rst:539
766
835
msgid ""
@@ -780,28 +849,41 @@ msgid ""
780
849
" def __del__(self):\n"
781
850
" self.remove()"
782
851
msgstr ""
852
+ "class TempDir:\n"
853
+ " def __init__(self):\n"
854
+ " self.name = tempfile.mkdtemp()\n"
855
+ "\n"
856
+ " def remove(self):\n"
857
+ " if self.name is not None:\n"
858
+ " shutil.rmtree(self.name)\n"
859
+ " self.name = None\n"
860
+ "\n"
861
+ " @property\n"
862
+ " def removed(self):\n"
863
+ " return self.name is None\n"
864
+ "\n"
865
+ " def __del__(self):\n"
866
+ " self.remove()"
783
867
784
868
#: ../../library/weakref.rst:555
785
- #, fuzzy
786
869
msgid ""
787
870
"Starting with Python 3.4, :meth:`~object.__del__` methods no longer "
788
871
"prevent reference cycles from being garbage collected, and module globals"
789
872
" are no longer forced to :const:`None` during :term:`interpreter "
790
873
"shutdown`. So this code should work without any issues on CPython."
791
874
msgstr ""
792
- "파이썬 3.4부터, :meth:`__del__` 메서드는 더는 참조 순환이 가비지 수거되는 것을 막지 않으며, "
875
+ "파이썬 3.4부터, :meth:`~object. __del__` 메서드는 더는 참조 순환이 가비지 수거되는 것을 막지 않으며, "
793
876
":term:`인터프리터 종료 <interpreter shutdown>` 중에 모듈 전역이 더는 :const:`None`\\ 으로 "
794
877
"강제되지 않습니다. 따라서 이 코드는 CPython에서 아무런 문제 없이 작동해야 합니다."
795
878
796
879
#: ../../library/weakref.rst:560
797
- #, fuzzy
798
880
msgid ""
799
881
"However, handling of :meth:`~object.__del__` methods is notoriously "
800
882
"implementation specific, since it depends on internal details of the "
801
883
"interpreter's garbage collector implementation."
802
884
msgstr ""
803
- "그러나, :meth:`__del__` 메서드의 처리는 인터프리터의 가비지 수거기 구현에 대한 내부 세부 사항에 의존하기 때문에 "
804
- "구현에 따라 다르기로 악명 높습니다."
885
+ "그러나, :meth:`~object. __del__` 메서드의 처리는 인터프리터의 가비지 수거기 구현에 대한 내부 세부 사항에 "
886
+ "의존하기 때문에 구현에 따라 다르기로 악명 높습니다."
805
887
806
888
#: ../../library/weakref.rst:564
807
889
msgid ""
@@ -825,6 +907,18 @@ msgid ""
825
907
" def removed(self):\n"
826
908
" return not self._finalizer.alive"
827
909
msgstr ""
910
+ "class TempDir:\n"
911
+ " def __init__(self):\n"
912
+ " self.name = tempfile.mkdtemp()\n"
913
+ " self._finalizer = weakref.finalize(self, shutil.rmtree, "
914
+ "self.name)\n"
915
+ "\n"
916
+ " def remove(self):\n"
917
+ " self._finalizer()\n"
918
+ "\n"
919
+ " @property\n"
920
+ " def removed(self):\n"
921
+ " return not self._finalizer.alive"
828
922
829
923
#: ../../library/weakref.rst:580
830
924
msgid ""
@@ -851,6 +945,10 @@ msgid ""
851
945
" # implicit reference to the module globals from the function body\n"
852
946
"weakref.finalize(sys.modules[__name__], unloading_module)"
853
947
msgstr ""
948
+ "import weakref, sys\n"
949
+ "def unloading_module():\n"
950
+ " # 함수 바디에서 모듈 전역으로의 묵시적 참조\n"
951
+ "weakref.finalize(sys.modules[__name__], unloading_module)"
854
952
855
953
#: ../../library/weakref.rst:596
856
954
msgid ""
0 commit comments