@@ -121,18 +121,17 @@ msgstr ""
121121"노출합니다."
122122
123123#: ../../library/weakref.rst:68
124- #, fuzzy
125124msgid ""
126125"Not all objects can be weakly referenced. Objects which support weak "
127126"references include class instances, functions written in Python (but not "
128127"in C), instance methods, sets, frozensets, some :term:`file objects <file"
129128" object>`, :term:`generators <generator>`, type objects, sockets, arrays,"
130129" deques, regular expression pattern objects, and code objects."
131130msgstr ""
132- "모든 객체를 약하게 참조할 수 있는 것은 아닙니다; 가능한 객체에는 클래스 인스턴스, 파이썬으로 작성된 함수 (C로 작성된 함수는 "
133- "아닙니다), 인스턴스 메서드, 집합, 불변 집합(frozenset), 일부 :term:`파일 객체 <file object>`, "
134- ":term:`제너레이터 <generator>`, 형 객체, 소켓, 배열, 데크(deque), 정규식 패턴 객체 및 코드 객체가 "
135- "포함됩니다."
131+ "모든 객체를 약하게 참조할 수 있는 것은 아닙니다. 약한 참조를 지원하는 객체에는 클래스 인스턴스, 파이썬으로 작성된 함수 (C로 "
132+ "작성된 함수는 아닙니다), 인스턴스 메서드, 집합, 불변 집합(frozenset), 일부 :term:`파일 객체 <file "
133+ "object>`, :term:`제너레이터 <generator>`, 형 객체, 소켓, 배열, 데크(deque), 정규식 패턴 객체 및"
134+ " 코드 객체가 포함됩니다."
136135
137136#: ../../library/weakref.rst:74
138137msgid "Added support for thread.lock, threading.Lock, and code objects."
@@ -154,6 +153,10 @@ msgid ""
154153"\n"
155154"obj = Dict(red=1, green=2, blue=3) # this object is weak referenceable"
156155msgstr ""
156+ "class Dict(dict):\n"
157+ " pass\n"
158+ "\n"
159+ "obj = Dict(red=1, green=2, blue=3) # 이 객체는 약한 참조할 수 있습니다"
157160
158161#: ../../library/weakref.rst:87
159162msgid ""
@@ -201,14 +204,13 @@ msgstr ""
201204"오래전에 등록된 콜백 순으로 호출됩니다."
202205
203206#: ../../library/weakref.rst:112
204- #, fuzzy
205207msgid ""
206208"Exceptions raised by the callback will be noted on the standard error "
207209"output, but cannot be propagated; they are handled in exactly the same "
208210"way as exceptions raised from an object's :meth:`~object.__del__` method."
209211msgstr ""
210- "콜백에 의해 발생한 예외는 표준 에러 출력에 표시되지만, 전파될 수는 없습니다; 객체의 :meth:`__del__` 메서드에서 "
211- "발생한 예외와 정확히 같은 방식으로 처리됩니다."
212+ "콜백에 의해 발생한 예외는 표준 에러 출력에 표시되지만, 전파될 수는 없습니다; 객체의 :meth:`~object. __del__` "
213+ "메서드에서 발생한 예외와 정확히 같은 방식으로 처리됩니다."
212214
213215#: ../../library/weakref.rst:116
214216msgid ""
@@ -251,7 +253,6 @@ msgid "Added the :attr:`__callback__` attribute."
251253msgstr ":attr:`__callback__` 어트리뷰트를 추가했습니다."
252254
253255#: ../../library/weakref.rst:140
254- #, fuzzy
255256msgid ""
256257"Return a proxy to *object* which uses a weak reference. This supports "
257258"use of the proxy in most contexts instead of requiring the explicit "
@@ -323,6 +324,13 @@ msgid ""
323324">>> d[k2] = 2 # d = {k1: 2}\n"
324325">>> del k1 # d = {}"
325326msgstr ""
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 = {}"
326334
327335#: ../../library/weakref.rst:188
328336msgid "A workaround would be to remove the key prior to reassignment::"
@@ -340,6 +348,14 @@ msgid ""
340348">>> d[k2] = 2 # d = {k2: 2}\n"
341349">>> del k1 # d = {k2: 2}"
342350msgstr ""
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}"
343359
344360#: ../../library/weakref.rst:199 ../../library/weakref.rst:220
345361msgid "Added support for ``|`` and ``|=`` operators, as specified in :pep:`584`."
@@ -369,13 +385,12 @@ msgid ""
369385msgstr "값을 약하게 참조하는 매핑 클래스. 값에 대한 강한 참조가 더는 존재하지 않을 때 딕셔너리의 항목이 삭제됩니다."
370386
371387#: ../../library/weakref.rst:223
372- #, fuzzy
373388msgid ""
374389":class:`WeakValueDictionary` objects have an additional method that has "
375390"the same issues as the :meth:`WeakKeyDictionary.keyrefs` method."
376391msgstr ""
377- ":class:`WeakValueDictionary` 객체에는 :class:`WeakKeyDictionary` 객체의 "
378- ":meth:`keyrefs` 메서드와 같은 문제가 있는 추가 메서드가 있습니다."
392+ ":class:`WeakValueDictionary` 객체에는 :class:`WeakKeyDictionary.keyrefs` 메서드와 "
393+ " 같은 문제가 있는 추가 메서드가 있습니다."
379394
380395#: ../../library/weakref.rst:229
381396msgid "Return an iterable of the weak references to the values."
@@ -419,6 +434,23 @@ msgid ""
419434">>> r()\n"
420435">>>"
421436msgstr ""
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+ ">>>"
422454
423455#: ../../library/weakref.rst:264
424456msgid ""
@@ -448,15 +480,14 @@ msgstr ""
448480":const:`None`\\ 이 반환됩니다."
449481
450482#: ../../library/weakref.rst:280
451- #, fuzzy
452483msgid ""
453484"Exceptions raised by finalizer callbacks during garbage collection will "
454485"be shown on the standard error output, but cannot be propagated. They "
455486"are handled in the same way as exceptions raised from an object's "
456487":meth:`~object.__del__` method or a weak reference's callback."
457488msgstr ""
458489"가비지 수거 중에 파이널라이저 콜백에서 발생한 예외는 표준 에러 출력에 표시되지만, 전파할 수는 없습니다. 객체의 "
459- ":meth:`__del__` 메서드나 약한 참조의 콜백에서 발생하는 예외와 같은 방식으로 처리됩니다."
490+ ":meth:`~object. __del__` 메서드나 약한 참조의 콜백에서 발생하는 예외와 같은 방식으로 처리됩니다."
460491
461492#: ../../library/weakref.rst:286
462493msgid ""
@@ -595,6 +626,14 @@ msgid ""
595626" print(\" Object is still live!\" )\n"
596627" o.do_something_useful()"
597628msgstr ""
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()"
598637
599638#: ../../library/weakref.rst:400
600639msgid ""
@@ -652,6 +691,23 @@ msgid ""
652691" ob = (ob, self.__counter)\n"
653692" return ob"
654693msgstr ""
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"
655711
656712#: ../../library/weakref.rst:438
657713msgid "Example"
@@ -681,6 +737,17 @@ msgid ""
681737"def id2obj(oid):\n"
682738" return _id2obj_dict[oid]"
683739msgstr ""
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]"
684751
685752#: ../../library/weakref.rst:465
686753msgid "Finalizer Objects"
@@ -727,11 +794,15 @@ msgid ""
727794">>> exit()\n"
728795"obj dead or exiting"
729796msgstr ""
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"
730802
731803#: ../../library/weakref.rst:526
732- #, fuzzy
733804msgid "Comparing finalizers with :meth:`~object.__del__` methods"
734- msgstr "파이널라이저와 :meth:`__del__` 메서드의 비교"
805+ msgstr "파이널라이저와 :meth:`~object. __del__` 메서드의 비교"
735806
736807#: ../../library/weakref.rst:528
737808msgid ""
@@ -747,20 +818,18 @@ msgid "the object is garbage collected,"
747818msgstr "객체가 가비지 수거됩니다,"
748819
749820#: ../../library/weakref.rst:533
750- #, fuzzy
751821msgid "the object's :meth:`!remove` method is called, or"
752- msgstr "객체의 :meth:`remove` 메서드가 호출됩니다, 또는"
822+ msgstr "객체의 :meth:`! remove` 메서드가 호출됩니다, 또는"
753823
754824#: ../../library/weakref.rst:534
755825msgid "the program exits."
756826msgstr "프로그램이 종료합니다."
757827
758828#: ../../library/weakref.rst:536
759- #, fuzzy
760829msgid ""
761830"We might try to implement the class using a :meth:`~object.__del__` "
762831"method as follows::"
763- msgstr "다음과 같이 :meth:`__del__` 메서드를 사용하여 클래스를 구현하려고 시도할 수 있습니다::"
832+ msgstr "다음과 같이 :meth:`~object. __del__` 메서드를 사용하여 클래스를 구현하려고 시도할 수 있습니다::"
764833
765834#: ../../library/weakref.rst:539
766835msgid ""
@@ -780,28 +849,41 @@ msgid ""
780849" def __del__(self):\n"
781850" self.remove()"
782851msgstr ""
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()"
783867
784868#: ../../library/weakref.rst:555
785- #, fuzzy
786869msgid ""
787870"Starting with Python 3.4, :meth:`~object.__del__` methods no longer "
788871"prevent reference cycles from being garbage collected, and module globals"
789872" are no longer forced to :const:`None` during :term:`interpreter "
790873"shutdown`. So this code should work without any issues on CPython."
791874msgstr ""
792- "파이썬 3.4부터, :meth:`__del__` 메서드는 더는 참조 순환이 가비지 수거되는 것을 막지 않으며, "
875+ "파이썬 3.4부터, :meth:`~object. __del__` 메서드는 더는 참조 순환이 가비지 수거되는 것을 막지 않으며, "
793876":term:`인터프리터 종료 <interpreter shutdown>` 중에 모듈 전역이 더는 :const:`None`\\ 으로 "
794877"강제되지 않습니다. 따라서 이 코드는 CPython에서 아무런 문제 없이 작동해야 합니다."
795878
796879#: ../../library/weakref.rst:560
797- #, fuzzy
798880msgid ""
799881"However, handling of :meth:`~object.__del__` methods is notoriously "
800882"implementation specific, since it depends on internal details of the "
801883"interpreter's garbage collector implementation."
802884msgstr ""
803- "그러나, :meth:`__del__` 메서드의 처리는 인터프리터의 가비지 수거기 구현에 대한 내부 세부 사항에 의존하기 때문에 "
804- "구현에 따라 다르기로 악명 높습니다."
885+ "그러나, :meth:`~object. __del__` 메서드의 처리는 인터프리터의 가비지 수거기 구현에 대한 내부 세부 사항에 "
886+ "의존하기 때문에 구현에 따라 다르기로 악명 높습니다."
805887
806888#: ../../library/weakref.rst:564
807889msgid ""
@@ -825,6 +907,18 @@ msgid ""
825907" def removed(self):\n"
826908" return not self._finalizer.alive"
827909msgstr ""
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"
828922
829923#: ../../library/weakref.rst:580
830924msgid ""
@@ -851,6 +945,10 @@ msgid ""
851945" # implicit reference to the module globals from the function body\n"
852946"weakref.finalize(sys.modules[__name__], unloading_module)"
853947msgstr ""
948+ "import weakref, sys\n"
949+ "def unloading_module():\n"
950+ " # 함수 바디에서 모듈 전역으로의 묵시적 참조\n"
951+ "weakref.finalize(sys.modules[__name__], unloading_module)"
854952
855953#: ../../library/weakref.rst:596
856954msgid ""
0 commit comments