suite du dossier extending (#174)

Reviewed-on: AFPy/python-docs-fr#174
Reviewed-by: Julien Palard <julien@palard.fr>
Co-authored-by: Christophe Nanteuil <christophe.nanteuil@gmail.com>
Co-committed-by: Christophe Nanteuil <christophe.nanteuil@gmail.com>
This commit is contained in:
Christophe Nanteuil 2023-11-25 10:54:49 +00:00 committed by Julien Palard
parent 141c4ad19f
commit 4afdbf71c5
2 changed files with 333 additions and 31 deletions

View File

@ -613,6 +613,7 @@ roughly approximativement, à peu près (on ne traduit pas
« roughly equivalent » par « sensiblement équivalent ») « roughly equivalent » par « sensiblement équivalent »)
setter mutateur setter mutateur
simple quote guillemet simple simple quote guillemet simple
slot emplacement
socket connecteur ou interface de connexion socket connecteur ou interface de connexion
sort trier (préféré), ordonner, classer sort trier (préféré), ordonner, classer
specify définir, préciser (plutôt que « spécifier ») specify définir, préciser (plutôt que « spécifier »)

View File

@ -5,14 +5,15 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Python 3\n" "Project-Id-Version: Python 3\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-23 14:38+0200\n" "POT-Creation-Date: 2023-07-22 15:34+0200\n"
"PO-Revision-Date: 2022-10-18 12:22+0200\n" "PO-Revision-Date: 2023-07-27 23:20+0200\n"
"Last-Translator: Julien Palard <julien@palard.fr>\n" "Last-Translator: Christophe Nanteuil <christophe.nanteuil@gmail.com>\n"
"Language-Team: FRENCH <traductions@lists.afpy.org>\n" "Language-Team: FRENCH <traductions@lists.afpy.org>\n"
"Language: fr\n" "Language: fr\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.2.2\n"
#: extending/newtypes_tutorial.rst:7 #: extending/newtypes_tutorial.rst:7
msgid "Defining Extension Types: Tutorial" msgid "Defining Extension Types: Tutorial"
@ -37,7 +38,6 @@ msgid "The Basics"
msgstr "Les bases" msgstr "Les bases"
#: extending/newtypes_tutorial.rst:26 #: extending/newtypes_tutorial.rst:26
#, fuzzy
msgid "" msgid ""
"The :term:`CPython` runtime sees all Python objects as variables of type :c:" "The :term:`CPython` runtime sees all Python objects as variables of type :c:"
"expr:`PyObject*`, which serves as a \"base type\" for all Python objects. " "expr:`PyObject*`, which serves as a \"base type\" for all Python objects. "
@ -49,7 +49,7 @@ msgid ""
"functions are called \"type methods\"." "functions are called \"type methods\"."
msgstr "" msgstr ""
":term:`CPython` considère que tous les objets Python sont des variables de " ":term:`CPython` considère que tous les objets Python sont des variables de "
"type :c:type:`PyObject\\*`, qui sert de type de base pour tous les objets " "type :c:expr:`PyObject*`, qui sert de type de base pour tous les objets "
"Python. La structure de :c:type:`PyObject` ne contient que le :term:" "Python. La structure de :c:type:`PyObject` ne contient que le :term:"
"`compteur de références <reference count>` et un pointeur vers un objet de " "`compteur de références <reference count>` et un pointeur vers un objet de "
"type « type de l'objet ». C'est ici que tout se joue : l'objet type " "type « type de l'objet ». C'est ici que tout se joue : l'objet type "
@ -76,6 +76,7 @@ msgstr ""
"donc un module minimaliste mais suffisant qui définit un nouveau type nommé :" "donc un module minimaliste mais suffisant qui définit un nouveau type nommé :"
"class:`Custom` dans le module d'extension :mod:`custom` :" "class:`Custom` dans le module d'extension :mod:`custom` :"
# suit un :
#: extending/newtypes_tutorial.rst:43 #: extending/newtypes_tutorial.rst:43
msgid "" msgid ""
"What we're showing here is the traditional way of defining *static* " "What we're showing here is the traditional way of defining *static* "
@ -83,7 +84,7 @@ msgid ""
"allows defining heap-allocated extension types using the :c:func:" "allows defining heap-allocated extension types using the :c:func:"
"`PyType_FromSpec` function, which isn't covered in this tutorial." "`PyType_FromSpec` function, which isn't covered in this tutorial."
msgstr "" msgstr ""
"Ce qui est montré ici est la manière traditionnelle de définir des types " "ce qui est montré ici est la manière traditionnelle de définir des types "
"d'extension *statiques*, et cela convient dans la majorité des cas. L'API C " "d'extension *statiques*, et cela convient dans la majorité des cas. L'API C "
"permet aussi de définir des types alloués sur le tas, via la fonction :c:" "permet aussi de définir des types alloués sur le tas, via la fonction :c:"
"func:`PyType_FromSpec`, mais ce n'est pas couvert par ce tutoriel." "func:`PyType_FromSpec`, mais ce n'est pas couvert par ce tutoriel."
@ -128,7 +129,6 @@ msgid "The first bit is::"
msgstr "Commençons par ::" msgstr "Commençons par ::"
#: extending/newtypes_tutorial.rst:67 #: extending/newtypes_tutorial.rst:67
#, fuzzy
msgid "" msgid ""
"This is what a Custom object will contain. ``PyObject_HEAD`` is mandatory " "This is what a Custom object will contain. ``PyObject_HEAD`` is mandatory "
"at the start of each object struct and defines a field called ``ob_base`` of " "at the start of each object struct and defines a field called ``ob_base`` of "
@ -146,12 +146,13 @@ msgstr ""
"raison d'être de ces macros est d'abstraire l'agencement de la structure, et " "raison d'être de ces macros est d'abstraire l'agencement de la structure, et "
"ainsi de permettre l'ajout de champs en :ref:`mode débogage <debug-build>`." "ainsi de permettre l'ajout de champs en :ref:`mode débogage <debug-build>`."
# suit un :
#: extending/newtypes_tutorial.rst:76 #: extending/newtypes_tutorial.rst:76
msgid "" msgid ""
"There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be " "There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be "
"wary of adding one by accident: some compilers will complain." "wary of adding one by accident: some compilers will complain."
msgstr "" msgstr ""
"Il n'y a pas de point-virgule après la macro :c:macro:`PyObject_HEAD`. " "il n'y a pas de point-virgule après la macro :c:macro:`PyObject_HEAD`. "
"Attention à ne pas l'ajouter par accident : certains compilateurs pourraient " "Attention à ne pas l'ajouter par accident : certains compilateurs pourraient "
"s'en plaindre." "s'en plaindre."
@ -169,13 +170,14 @@ msgstr ""
msgid "The second bit is the definition of the type object. ::" msgid "The second bit is the definition of the type object. ::"
msgstr "La deuxième partie est la définition de l'objet type ::" msgstr "La deuxième partie est la définition de l'objet type ::"
# suit un :
#: extending/newtypes_tutorial.rst:101 #: extending/newtypes_tutorial.rst:101
msgid "" msgid ""
"We recommend using C99-style designated initializers as above, to avoid " "We recommend using C99-style designated initializers as above, to avoid "
"listing all the :c:type:`PyTypeObject` fields that you don't care about and " "listing all the :c:type:`PyTypeObject` fields that you don't care about and "
"also to avoid caring about the fields' declaration order." "also to avoid caring about the fields' declaration order."
msgstr "" msgstr ""
"Nous recommandons d'utiliser la syntaxe d'initialisation nommée (C99) pour " "nous recommandons d'utiliser la syntaxe d'initialisation nommée (C99) pour "
"remplir la structure, comme ci-dessus, afin d'éviter d'avoir à lister les " "remplir la structure, comme ci-dessus, afin d'éviter d'avoir à lister les "
"champs de :c:type:`PyTypeObject` dont vous n'avez pas besoin, et de ne pas " "champs de :c:type:`PyTypeObject` dont vous n'avez pas besoin, et de ne pas "
"vous soucier de leur ordre." "vous soucier de leur ordre."
@ -222,7 +224,7 @@ msgid ""
"type compatible with the :mod:`pydoc` and :mod:`pickle` modules. ::" "type compatible with the :mod:`pydoc` and :mod:`pickle` modules. ::"
msgstr "" msgstr ""
"Notez que le nom comporte un point : il inclut le nom du module et le nom du " "Notez que le nom comporte un point : il inclut le nom du module et le nom du "
"type. Dans ce cas le module est :mod:`custom`, et le type est :class:" "type. Dans ce cas le module est :mod:`custom` et le type est :class:"
"`Custom`, donc nous donnons comme nom :class:`custom.Custom`. Nommer " "`Custom`, donc nous donnons comme nom :class:`custom.Custom`. Nommer "
"correctement son type, avec le point, est important pour le rendre " "correctement son type, avec le point, est important pour le rendre "
"compatible avec :mod:`pydoc` et :mod:`pickle`. ::" "compatible avec :mod:`pydoc` et :mod:`pickle`. ::"
@ -238,6 +240,7 @@ msgstr ""
"n'est utilisé que pour les objets de taille variable, sinon il doit rester à " "n'est utilisé que pour les objets de taille variable, sinon il doit rester à "
"zéro." "zéro."
# suit un :
#: extending/newtypes_tutorial.rst:144 #: extending/newtypes_tutorial.rst:144
msgid "" msgid ""
"If you want your type to be subclassable from Python, and your type has the " "If you want your type to be subclassable from Python, and your type has the "
@ -251,7 +254,7 @@ msgid ""
"type will be :class:`object`, or else you will be adding data members to " "type will be :class:`object`, or else you will be adding data members to "
"your base type, and therefore increasing its size." "your base type, and therefore increasing its size."
msgstr "" msgstr ""
"Si vous voulez qu'une classe en Python puisse hériter de votre type, et que " "si vous voulez qu'une classe en Python puisse hériter de votre type, et que "
"votre type a le même :c:member:`~PyTypeObject.tp_basicsize` que son parent, " "votre type a le même :c:member:`~PyTypeObject.tp_basicsize` que son parent, "
"vous rencontrerez des problèmes avec l'héritage multiple. Une sous-classe " "vous rencontrerez des problèmes avec l'héritage multiple. Une sous-classe "
"Python de votre type devra lister votre type en premier dans son :attr:" "Python de votre type devra lister votre type en premier dans son :attr:"
@ -263,11 +266,9 @@ msgstr ""
"augmentant ainsi sa taille)." "augmentant ainsi sa taille)."
#: extending/newtypes_tutorial.rst:154 #: extending/newtypes_tutorial.rst:154
#, fuzzy
msgid "We set the class flags to :c:macro:`Py_TPFLAGS_DEFAULT`. ::" msgid "We set the class flags to :c:macro:`Py_TPFLAGS_DEFAULT`. ::"
msgstr "" msgstr ""
"On utilise la constante :const:`Py_TPFLAGS_DEFAULT` comme seule option de " "Nous définissons les drapeaux de la classe à :c:macro:`Py_TPFLAGS_DEFAULT` ::"
"type. ::"
#: extending/newtypes_tutorial.rst:158 #: extending/newtypes_tutorial.rst:158
msgid "" msgid ""
@ -277,14 +278,14 @@ msgid ""
msgstr "" msgstr ""
"Chaque type doit inclure cette constante dans ses options : elle active tous " "Chaque type doit inclure cette constante dans ses options : elle active tous "
"les membres définis jusqu'à au moins Python 3.3. Si vous avez besoin de plus " "les membres définis jusqu'à au moins Python 3.3. Si vous avez besoin de plus "
"de membres, vous pouvez la combiner à d'autres constantes avec un *ou* " "de membres, vous pouvez la combiner à d'autres constantes avec un *OU* "
"binaire." "binaire."
#: extending/newtypes_tutorial.rst:162 #: extending/newtypes_tutorial.rst:162
msgid "" msgid ""
"We provide a doc string for the type in :c:member:`~PyTypeObject.tp_doc`. ::" "We provide a doc string for the type in :c:member:`~PyTypeObject.tp_doc`. ::"
msgstr "" msgstr ""
"On fournit une *docstring* pour ce type via le membre :c:member:" "Nous fournissons une *docstring* pour ce type via le membre :c:member:"
"`~PyTypeObject.tp_doc`. ::" "`~PyTypeObject.tp_doc`. ::"
#: extending/newtypes_tutorial.rst:166 #: extending/newtypes_tutorial.rst:166
@ -337,7 +338,7 @@ msgstr ""
#: extending/newtypes_tutorial.rst:207 #: extending/newtypes_tutorial.rst:207
msgid "in a file called :file:`setup.py`; then typing" msgid "in a file called :file:`setup.py`; then typing"
msgstr "" msgstr "dans un fichier appelé :file:`setup.py` ; puis en tapant"
#: extending/newtypes_tutorial.rst:213 #: extending/newtypes_tutorial.rst:213
msgid "" msgid ""
@ -345,16 +346,22 @@ msgid ""
"to that directory and fire up Python --- you should be able to ``import " "to that directory and fire up Python --- you should be able to ``import "
"custom`` and play around with Custom objects." "custom`` and play around with Custom objects."
msgstr "" msgstr ""
"à un shell doit produire un fichier :file:`custom.so` dans un sous-"
"répertoire ; déplacez-vous dans ce répertoire et lancez Python — vous "
"devriez pouvoir faire ``import custom`` et jouer avec des objets "
"personnalisés."
#: extending/newtypes_tutorial.rst:217 #: extending/newtypes_tutorial.rst:217
msgid "That wasn't so hard, was it?" msgid "That wasn't so hard, was it?"
msgstr "" msgstr "Ce n'était pas si difficile, n'est-ce pas ?"
#: extending/newtypes_tutorial.rst:219 #: extending/newtypes_tutorial.rst:219
msgid "" msgid ""
"Of course, the current Custom type is pretty uninteresting. It has no data " "Of course, the current Custom type is pretty uninteresting. It has no data "
"and doesn't do anything. It can't even be subclassed." "and doesn't do anything. It can't even be subclassed."
msgstr "" msgstr ""
"Bien sûr, le type personnalisé actuel est assez inintéressant. Il n'a pas de "
"données et ne fait rien. Il ne peut même pas être sous-classé."
#: extending/newtypes_tutorial.rst:223 #: extending/newtypes_tutorial.rst:223
msgid "" msgid ""
@ -365,10 +372,17 @@ msgid ""
"Packaging User's Guide <https://packaging.python.org/tutorials/distributing-" "Packaging User's Guide <https://packaging.python.org/tutorials/distributing-"
"packages/>`_." "packages/>`_."
msgstr "" msgstr ""
"Bien que cette documentation présente le module standard :mod:`distutils` "
"pour la construction d'extensions C, il est recommandé dans les cas "
"d'utilisation réels d'utiliser la bibliothèque ``setuptools`` plus récente "
"et mieux entretenue. La documentation sur la façon de procéder est hors de "
"portée de ce document et peut être trouvée dans le `Python Packaging User's "
"Guide <https://packaging.python.org/tutorials/distributing-packages/>`_."
# suit un :
#: extending/newtypes_tutorial.rst:231 #: extending/newtypes_tutorial.rst:231
msgid "Adding data and methods to the Basic example" msgid "Adding data and methods to the Basic example"
msgstr "" msgstr "ajout de données et de méthodes à l'exemple basique"
#: extending/newtypes_tutorial.rst:233 #: extending/newtypes_tutorial.rst:233
msgid "" msgid ""
@ -376,20 +390,25 @@ msgid ""
"make the type usable as a base class. We'll create a new module, :mod:" "make the type usable as a base class. We'll create a new module, :mod:"
"`custom2` that adds these capabilities:" "`custom2` that adds these capabilities:"
msgstr "" msgstr ""
"Étendons l'exemple de base pour ajouter des données et des méthodes. Rendons "
"également le type utilisable comme classe de base. Nous allons créer un "
"nouveau module, :mod:`custom2` qui ajoute ces fonctionnalités :"
#: extending/newtypes_tutorial.rst:240 #: extending/newtypes_tutorial.rst:240
msgid "This version of the module has a number of changes." msgid "This version of the module has a number of changes."
msgstr "" msgstr "Cette version du module comporte un certain nombre de modifications."
#: extending/newtypes_tutorial.rst:242 #: extending/newtypes_tutorial.rst:242
msgid "We've added an extra include::" msgid "We've added an extra include::"
msgstr "" msgstr "Nous avons ajouté un nouvel *include* ::"
#: extending/newtypes_tutorial.rst:246 #: extending/newtypes_tutorial.rst:246
msgid "" msgid ""
"This include provides declarations that we use to handle attributes, as " "This include provides declarations that we use to handle attributes, as "
"described a bit later." "described a bit later."
msgstr "" msgstr ""
"Cet *include* fournit des déclarations que nous utilisons pour gérer les "
"attributs, comme décrit un peu plus loin."
#: extending/newtypes_tutorial.rst:249 #: extending/newtypes_tutorial.rst:249
msgid "" msgid ""
@ -398,20 +417,27 @@ msgid ""
"strings containing first and last names. The *number* attribute is a C " "strings containing first and last names. The *number* attribute is a C "
"integer." "integer."
msgstr "" msgstr ""
"Le type :class:`Custom` a maintenant trois attributs de données dans sa "
"structure C, *first*, *last* et *number*. Les variables *first* et *last* "
"sont des chaînes Python contenant les noms et prénoms. L'attribut *number* "
"est un entier C."
#: extending/newtypes_tutorial.rst:253 #: extending/newtypes_tutorial.rst:253
msgid "The object structure is updated accordingly::" msgid "The object structure is updated accordingly::"
msgstr "" msgstr "La structure de l'objet est mise à jour en conséquence ::"
#: extending/newtypes_tutorial.rst:262 #: extending/newtypes_tutorial.rst:262
msgid "" msgid ""
"Because we now have data to manage, we have to be more careful about object " "Because we now have data to manage, we have to be more careful about object "
"allocation and deallocation. At a minimum, we need a deallocation method::" "allocation and deallocation. At a minimum, we need a deallocation method::"
msgstr "" msgstr ""
"Comme nous avons maintenant des données à gérer, nous devons faire plus "
"attention à l'allocation et à la libération d'objets. Au minimum, nous avons "
"besoin d'une méthode de dés-allocation ::"
#: extending/newtypes_tutorial.rst:273 #: extending/newtypes_tutorial.rst:273
msgid "which is assigned to the :c:member:`~PyTypeObject.tp_dealloc` member::" msgid "which is assigned to the :c:member:`~PyTypeObject.tp_dealloc` member::"
msgstr "" msgstr "qui est assignée au membre :c:member:`~PyTypeObject.tp_dealloc` ::"
#: extending/newtypes_tutorial.rst:277 #: extending/newtypes_tutorial.rst:277
msgid "" msgid ""
@ -423,6 +449,13 @@ msgid ""
"object's type might not be :class:`CustomType`, because the object may be an " "object's type might not be :class:`CustomType`, because the object may be an "
"instance of a subclass." "instance of a subclass."
msgstr "" msgstr ""
"Cette méthode efface d'abord le nombre de références des deux attributs "
"Python. :c:func:`Py_XDECREF` gère correctement le cas où son argument est "
"``NULL`` (ce qui peut arriver ici si ``tp_new`` échoue à mi-chemin). Elle "
"appelle ensuite le membre :c:member:`~PyTypeObject.tp_free` du type de "
"l'objet (calculé par ``Py_TYPE(self)``) pour libérer la mémoire de l'objet. "
"Notez que le type de l'objet peut ne pas être :class:`CustomType`, car "
"l'objet peut être une instance d'une sous-classe."
#: extending/newtypes_tutorial.rst:286 #: extending/newtypes_tutorial.rst:286
msgid "" msgid ""
@ -432,16 +465,23 @@ msgid ""
"argument. Otherwise, the compiler will emit a warning. This is object-" "argument. Otherwise, the compiler will emit a warning. This is object-"
"oriented polymorphism, in C!" "oriented polymorphism, in C!"
msgstr "" msgstr ""
"La conversion explicite en ``destructor`` ci-dessus est nécessaire car nous "
"avons défini ``Custom_dealloc`` pour prendre un argument ``CustomObject *``, "
"mais le pointeur de fonction ``tp_dealloc`` s'attend à recevoir un argument "
"``PyObject *``. Sinon, le compilateur émet un avertissement. C'est du "
"polymorphisme orienté objet, en C !"
#: extending/newtypes_tutorial.rst:292 #: extending/newtypes_tutorial.rst:292
msgid "" msgid ""
"We want to make sure that the first and last names are initialized to empty " "We want to make sure that the first and last names are initialized to empty "
"strings, so we provide a ``tp_new`` implementation::" "strings, so we provide a ``tp_new`` implementation::"
msgstr "" msgstr ""
"Nous voulons nous assurer que le prénom et le nom sont initialisés avec des "
"chaînes vides, nous fournissons donc une implémentation ``tp_new`` ::"
#: extending/newtypes_tutorial.rst:316 #: extending/newtypes_tutorial.rst:316
msgid "and install it in the :c:member:`~PyTypeObject.tp_new` member::" msgid "and install it in the :c:member:`~PyTypeObject.tp_new` member::"
msgstr "" msgstr "et installez-le dans le membre :c:member:`~PyTypeObject.tp_new` ::"
#: extending/newtypes_tutorial.rst:320 #: extending/newtypes_tutorial.rst:320
msgid "" msgid ""
@ -453,6 +493,14 @@ msgid ""
"use the ``tp_new`` handler to initialize the ``first`` and ``last`` " "use the ``tp_new`` handler to initialize the ``first`` and ``last`` "
"attributes to non-``NULL`` default values." "attributes to non-``NULL`` default values."
msgstr "" msgstr ""
"Le gestionnaire ``tp_new`` est responsable de la création (par opposition à "
"l'initialisation) des objets du type. Il est exposé en Python en tant que "
"méthode :meth:`__new__`. Il n'est pas nécessaire de définir un membre "
"``tp_new``, et en effet de nombreux types d'extension réutiliseront "
"simplement :c:func:`PyType_GenericNew` comme cela a été fait dans la "
"première version du type ``Custom`` ci-dessus. Dans ce cas, nous utilisons "
"le gestionnaire ``tp_new`` pour initialiser les attributs ``first`` et "
"``last`` à des valeurs par défaut non ``NULL``."
#: extending/newtypes_tutorial.rst:328 #: extending/newtypes_tutorial.rst:328
msgid "" msgid ""
@ -463,24 +511,38 @@ msgid ""
"often ignore the arguments, leaving the argument handling to initializer (a." "often ignore the arguments, leaving the argument handling to initializer (a."
"k.a. ``tp_init`` in C or ``__init__`` in Python) methods." "k.a. ``tp_init`` in C or ``__init__`` in Python) methods."
msgstr "" msgstr ""
"``tp_new`` reçoit le type en cours d'instanciation (pas nécessairement "
"``CustomType``, si une sous-classe est instanciée) et tous les arguments "
"passés lorsque le type a été appelé, et devrait renvoyer l'instance créée. "
"Les gestionnaires ``tp_new`` acceptent toujours les arguments positionnels "
"et nommés, mais ils ignorent souvent les arguments, laissant la gestion des "
"arguments aux méthodes d'initialisation (alias ``tp_init`` en C ou "
"``__init__`` en Python)."
#: extending/newtypes_tutorial.rst:336 #: extending/newtypes_tutorial.rst:336
msgid "" msgid ""
"``tp_new`` shouldn't call ``tp_init`` explicitly, as the interpreter will do " "``tp_new`` shouldn't call ``tp_init`` explicitly, as the interpreter will do "
"it itself." "it itself."
msgstr "" msgstr ""
"``tp_new`` ne doit pas appeler ``tp_init`` explicitement, car l'interpréteur "
"le fera lui-même."
#: extending/newtypes_tutorial.rst:339 #: extending/newtypes_tutorial.rst:339
msgid "" msgid ""
"The ``tp_new`` implementation calls the :c:member:`~PyTypeObject.tp_alloc` " "The ``tp_new`` implementation calls the :c:member:`~PyTypeObject.tp_alloc` "
"slot to allocate memory::" "slot to allocate memory::"
msgstr "" msgstr ""
"L'implémentation ``tp_new`` appelle l'emplacement :c:member:`~PyTypeObject."
"tp_alloc` pour allouer de la mémoire ::"
#: extending/newtypes_tutorial.rst:344 #: extending/newtypes_tutorial.rst:344
msgid "" msgid ""
"Since memory allocation may fail, we must check the :c:member:`~PyTypeObject." "Since memory allocation may fail, we must check the :c:member:`~PyTypeObject."
"tp_alloc` result against ``NULL`` before proceeding." "tp_alloc` result against ``NULL`` before proceeding."
msgstr "" msgstr ""
"Puisque l'allocation de mémoire peut échouer, nous devons vérifier le "
"résultat :c:member:`~PyTypeObject.tp_alloc` par rapport à ``NULL`` avant de "
"continuer."
#: extending/newtypes_tutorial.rst:348 #: extending/newtypes_tutorial.rst:348
msgid "" msgid ""
@ -489,6 +551,10 @@ msgid ""
"class, which is :class:`object` by default. Most types use the default " "class, which is :class:`object` by default. Most types use the default "
"allocation strategy." "allocation strategy."
msgstr "" msgstr ""
"Nous n'avons pas rempli l'emplacement :c:member:`~PyTypeObject.tp_alloc` "
"nous-mêmes. C'est :c:func:`PyType_Ready` qui le remplit pour nous car il en "
"hérite de notre classe mère, qui est :class:`object` par défaut. La plupart "
"des types utilisent la stratégie d'allocation par défaut."
#: extending/newtypes_tutorial.rst:354 #: extending/newtypes_tutorial.rst:354
msgid "" msgid ""
@ -502,16 +568,28 @@ msgid ""
"correctly. (Specifically, you may not be able to create instances of such " "correctly. (Specifically, you may not be able to create instances of such "
"subclasses without getting a :exc:`TypeError`.)" "subclasses without getting a :exc:`TypeError`.)"
msgstr "" msgstr ""
"Si vous créez une :c:member:`~PyTypeObject.tp_new` coopérative (qui appelle :"
"c:member:`~PyTypeObject.tp_new` ou :meth:`__new__` d'un type de base), vous "
"ne devez *pas* essayer de déterminer quelle méthode appeler en utilisant "
"l'ordre de résolution des méthodes au moment de l'exécution. Déterminez "
"toujours statiquement quel type vous allez appeler, et appelez son :c:member:"
"`~PyTypeObject.tp_new` directement, ou via ``type->tp_base->tp_new``. Si "
"vous ne le faites pas, les sous-classes Python de votre type qui héritent "
"également d'autres classes définies par Python risquent de ne pas "
"fonctionner correctement. (Plus précisément, vous ne pourrez peut-être pas "
"créer d'instances de telles sous-classes sans obtenir une :exc:`TypeError`.)"
#: extending/newtypes_tutorial.rst:364 #: extending/newtypes_tutorial.rst:364
msgid "" msgid ""
"We also define an initialization function which accepts arguments to provide " "We also define an initialization function which accepts arguments to provide "
"initial values for our instance::" "initial values for our instance::"
msgstr "" msgstr ""
"Nous définissons également une fonction d'initialisation qui accepte des "
"arguments pour fournir des valeurs initiales pour notre instance ::"
#: extending/newtypes_tutorial.rst:393 #: extending/newtypes_tutorial.rst:393
msgid "by filling the :c:member:`~PyTypeObject.tp_init` slot. ::" msgid "by filling the :c:member:`~PyTypeObject.tp_init` slot. ::"
msgstr "" msgstr "en remplissant l'emplacement :c:member:`~PyTypeObject.tp_init`. ::"
#: extending/newtypes_tutorial.rst:397 #: extending/newtypes_tutorial.rst:397
msgid "" msgid ""
@ -520,6 +598,11 @@ msgid ""
"Initializers always accept positional and keyword arguments, and they should " "Initializers always accept positional and keyword arguments, and they should "
"return either ``0`` on success or ``-1`` on error." "return either ``0`` on success or ``-1`` on error."
msgstr "" msgstr ""
"L'emplacement :c:member:`~PyTypeObject.tp_init` est exposé en Python en tant "
"que méthode :meth:`__init__`. Il est utilisé pour initialiser un objet après "
"sa création. Les constructeurs acceptent toujours les arguments positionnels "
"et nommés, et ils doivent renvoyer soit ``0`` en cas de succès, soit ``-1`` "
"en cas d'erreur."
#: extending/newtypes_tutorial.rst:402 #: extending/newtypes_tutorial.rst:402
msgid "" msgid ""
@ -531,6 +614,13 @@ msgid ""
"new attribute values. We might be tempted, for example to assign the " "new attribute values. We might be tempted, for example to assign the "
"``first`` member like this::" "``first`` member like this::"
msgstr "" msgstr ""
"Contrairement au gestionnaire ``tp_new``, il n'y a aucune garantie que "
"``tp_init`` soit appelé (par exemple, le module :mod:`pickle` par défaut "
"n'appelle pas :meth:`__init__` sur les instances *unpickled*). Il peut "
"également être appelé plusieurs fois. N'importe qui peut appeler la méthode :"
"meth:`__init__` sur nos objets. Pour cette raison, nous devons être très "
"prudents lors de l'attribution des nouvelles valeurs d'attribut. On pourrait "
"être tenté, par exemple, d'affecter le membre ``first`` comme ceci ::"
#: extending/newtypes_tutorial.rst:416 #: extending/newtypes_tutorial.rst:416
msgid "" msgid ""
@ -541,6 +631,12 @@ msgid ""
"interpreter Lock <GIL>` and let arbitrary code run in other threads that " "interpreter Lock <GIL>` and let arbitrary code run in other threads that "
"accesses and modifies our object." "accesses and modifies our object."
msgstr "" msgstr ""
"Mais ce serait risqué. Notre type ne limite pas le type du membre ``first``, "
"il peut donc s'agir de n'importe quel type d'objet. Il pourrait avoir un "
"destructeur qui provoque l'exécution de code essayant d'accéder au membre "
"``first`` ; ou ce destructeur pourrait libérer le :term:`Global interpreter "
"Lock <GIL>` et laisser du code arbitraire s'exécuter dans d'autres threads "
"qui accèdent et modifient notre objet."
#: extending/newtypes_tutorial.rst:423 #: extending/newtypes_tutorial.rst:423
msgid "" msgid ""
@ -548,16 +644,22 @@ msgid ""
"always reassign members before decrementing their reference counts. When " "always reassign members before decrementing their reference counts. When "
"don't we have to do this?" "don't we have to do this?"
msgstr "" msgstr ""
"Dans une optique paranoïaque et se prémunir contre cette éventualité, on "
"réaffecte presque toujours les membres avant de décrémenter leur compteur de "
"références. Quand ne devons-nous pas faire cela ?"
#: extending/newtypes_tutorial.rst:427 #: extending/newtypes_tutorial.rst:427
msgid "when we absolutely know that the reference count is greater than 1;" msgid "when we absolutely know that the reference count is greater than 1;"
msgstr "" msgstr "lorsque l'on est sûr que le compteur de références est supérieur à 1 ;"
#: extending/newtypes_tutorial.rst:429 #: extending/newtypes_tutorial.rst:429
msgid "" msgid ""
"when we know that deallocation of the object [#]_ will neither release the :" "when we know that deallocation of the object [#]_ will neither release the :"
"term:`GIL` nor cause any calls back into our type's code;" "term:`GIL` nor cause any calls back into our type's code;"
msgstr "" msgstr ""
"lorsque nous savons que la libération de la mémoire de l'objet [#]_ ne "
"libérera pas le :term:`GIL` ni ne provoquera de rappel dans le code de notre "
"type ;"
#: extending/newtypes_tutorial.rst:432 #: extending/newtypes_tutorial.rst:432
msgid "" msgid ""
@ -565,17 +667,25 @@ msgid ""
"tp_dealloc` handler on a type which doesn't support cyclic garbage " "tp_dealloc` handler on a type which doesn't support cyclic garbage "
"collection [#]_." "collection [#]_."
msgstr "" msgstr ""
"lors de la décrémentation d'un compteur de références dans un gestionnaire :"
"c:member:`~PyTypeObject.tp_dealloc` sur un type qui ne prend pas en charge "
"le ramasse-miettes cyclique [#]_."
#: extending/newtypes_tutorial.rst:435 #: extending/newtypes_tutorial.rst:435
msgid "" msgid ""
"We want to expose our instance variables as attributes. There are a number " "We want to expose our instance variables as attributes. There are a number "
"of ways to do that. The simplest way is to define member definitions::" "of ways to do that. The simplest way is to define member definitions::"
msgstr "" msgstr ""
"Nous voulons exposer nos variables d'instance en tant qu'attributs. Il "
"existe plusieurs façons de le faire. Le moyen le plus simple consiste à "
"définir des définitions de membres ::"
#: extending/newtypes_tutorial.rst:448 #: extending/newtypes_tutorial.rst:448
msgid "" msgid ""
"and put the definitions in the :c:member:`~PyTypeObject.tp_members` slot::" "and put the definitions in the :c:member:`~PyTypeObject.tp_members` slot::"
msgstr "" msgstr ""
"et placer les définitions dans l'emplacement :c:member:`~PyTypeObject."
"tp_members` ::"
#: extending/newtypes_tutorial.rst:452 #: extending/newtypes_tutorial.rst:452
msgid "" msgid ""
@ -583,6 +693,9 @@ msgid ""
"documentation string. See the :ref:`Generic-Attribute-Management` section " "documentation string. See the :ref:`Generic-Attribute-Management` section "
"below for details." "below for details."
msgstr "" msgstr ""
"Chaque définition de membre possède un nom, un type, un décalage, des "
"indicateurs d'accès et une chaîne de documentation. Voir la section :ref:"
"`Generic-Attribute-Management` ci-dessous pour plus de détails."
#: extending/newtypes_tutorial.rst:456 #: extending/newtypes_tutorial.rst:456
msgid "" msgid ""
@ -594,12 +707,22 @@ msgid ""
"``NULL`` values, the members can be set to ``NULL`` if the attributes are " "``NULL`` values, the members can be set to ``NULL`` if the attributes are "
"deleted." "deleted."
msgstr "" msgstr ""
"Un inconvénient de cette approche est qu'elle ne permet pas de restreindre "
"les types d'objets pouvant être affectés aux attributs Python. Nous nous "
"attendons à ce que le prénom et le nom soient des chaînes, mais tous les "
"objets Python peuvent être affectés. De plus, les attributs peuvent être "
"supprimés, en définissant les pointeurs C sur ``NULL``. Même si nous pouvons "
"nous assurer que les membres sont initialisés avec des valeurs non ``NULL``, "
"les membres peuvent être définis sur ``NULL`` si les attributs sont "
"supprimés."
#: extending/newtypes_tutorial.rst:463 #: extending/newtypes_tutorial.rst:463
msgid "" msgid ""
"We define a single method, :meth:`Custom.name()`, that outputs the objects " "We define a single method, :meth:`Custom.name()`, that outputs the objects "
"name as the concatenation of the first and last names. ::" "name as the concatenation of the first and last names. ::"
msgstr "" msgstr ""
"Nous définissons une seule méthode, :meth:`Custom.name()`, qui génère le nom "
"des objets sous la forme de la concaténation des prénom et nom. ::"
#: extending/newtypes_tutorial.rst:480 #: extending/newtypes_tutorial.rst:480
msgid "" msgid ""
@ -610,6 +733,13 @@ msgid ""
"to accept a positional argument tuple or keyword argument dictionary. This " "to accept a positional argument tuple or keyword argument dictionary. This "
"method is equivalent to the Python method:" "method is equivalent to the Python method:"
msgstr "" msgstr ""
"La méthode est implémentée comme une fonction C qui prend une instance :"
"class:`Custom` (ou une sous-classe de :class:`Custom`) comme premier "
"argument. Les méthodes prennent toujours une instance comme premier "
"argument. Les méthodes prennent souvent aussi des arguments positionnels et "
"nommés, mais dans ce cas nous n'en prenons aucun et n'avons pas besoin "
"d'accepter un *n*-uplet d'arguments positionnels ou un dictionnaire en "
"argument nommé. Cette méthode est équivalente à la méthode Python :"
#: extending/newtypes_tutorial.rst:492 #: extending/newtypes_tutorial.rst:492
msgid "" msgid ""
@ -619,22 +749,32 @@ msgid ""
"of these attributes and to restrict the attribute values to be strings. " "of these attributes and to restrict the attribute values to be strings. "
"We'll see how to do that in the next section." "We'll see how to do that in the next section."
msgstr "" msgstr ""
"Notez que nous devons vérifier la possibilité que nos membres :attr:`first` "
"et :attr:`last` soient ``NULL``. En effet, ils peuvent être supprimés, "
"auquel cas ils sont définis sur ``NULL``. Il serait préférable d'empêcher la "
"suppression de ces attributs et de limiter les valeurs d'attribut à des "
"chaînes. Nous verrons comment procéder dans la section suivante."
#: extending/newtypes_tutorial.rst:498 #: extending/newtypes_tutorial.rst:498
msgid "" msgid ""
"Now that we've defined the method, we need to create an array of method " "Now that we've defined the method, we need to create an array of method "
"definitions::" "definitions::"
msgstr "" msgstr ""
"Maintenant que nous avons défini la méthode, nous devons créer un tableau de "
"définitions de méthode ::"
#: extending/newtypes_tutorial.rst:508 #: extending/newtypes_tutorial.rst:508
msgid "" msgid ""
"(note that we used the :c:macro:`METH_NOARGS` flag to indicate that the " "(note that we used the :c:macro:`METH_NOARGS` flag to indicate that the "
"method is expecting no arguments other than *self*)" "method is expecting no arguments other than *self*)"
msgstr "" msgstr ""
"(notez que nous avons utilisé le drapeau :c:macro:`METH_NOARGS` pour "
"indiquer que la méthode n'attend aucun argument autre que *self*)"
#: extending/newtypes_tutorial.rst:511 #: extending/newtypes_tutorial.rst:511
msgid "and assign it to the :c:member:`~PyTypeObject.tp_methods` slot::" msgid "and assign it to the :c:member:`~PyTypeObject.tp_methods` slot::"
msgstr "" msgstr ""
"et assignons-le à l'emplacement :c:member:`~PyTypeObject.tp_methods` ::"
#: extending/newtypes_tutorial.rst:515 #: extending/newtypes_tutorial.rst:515
msgid "" msgid ""
@ -643,6 +783,11 @@ msgid ""
"about the type of the object being created or used, so all we need to do is " "about the type of the object being created or used, so all we need to do is "
"to add the :c:macro:`Py_TPFLAGS_BASETYPE` to our class flag definition::" "to add the :c:macro:`Py_TPFLAGS_BASETYPE` to our class flag definition::"
msgstr "" msgstr ""
"Enfin, nous rendons notre type utilisable comme classe de base pour le sous-"
"classement. Nous avons écrit nos méthodes avec soin jusqu'à présent afin "
"qu'elles ne fassent aucune hypothèse sur le type de l'objet créé ou utilisé, "
"donc tout ce que nous avons à faire est d'ajouter la macro :c:macro:"
"`Py_TPFLAGS_BASETYPE` à notre définition d'indicateur de classe ::"
#: extending/newtypes_tutorial.rst:522 #: extending/newtypes_tutorial.rst:522
msgid "" msgid ""
@ -650,14 +795,19 @@ msgid ""
"module name in the :c:type:`PyModuleDef` struct, and update the full class " "module name in the :c:type:`PyModuleDef` struct, and update the full class "
"name in the :c:type:`PyTypeObject` struct." "name in the :c:type:`PyTypeObject` struct."
msgstr "" msgstr ""
"Nous renommons :c:func:`PyInit_custom` en :c:func:`PyInit_custom2`, mettons "
"à jour le nom du module dans la structure :c:type:`PyModuleDef` et mettons à "
"jour le nom complet de la classe dans la structure :c:type:`PyTypeObject`."
#: extending/newtypes_tutorial.rst:526 #: extending/newtypes_tutorial.rst:526
msgid "Finally, we update our :file:`setup.py` file to build the new module:" msgid "Finally, we update our :file:`setup.py` file to build the new module:"
msgstr "" msgstr ""
"Enfin, nous mettons à jour notre fichier :file:`setup.py` pour construire le "
"nouveau module :"
#: extending/newtypes_tutorial.rst:539 #: extending/newtypes_tutorial.rst:539
msgid "Providing finer control over data attributes" msgid "Providing finer control over data attributes"
msgstr "" msgstr "Contrôle précis sur les attributs de données"
#: extending/newtypes_tutorial.rst:541 #: extending/newtypes_tutorial.rst:541
msgid "" msgid ""
@ -667,6 +817,12 @@ msgid ""
"attr:`last` could be set to non-string values or even deleted. We want to " "attr:`last` could be set to non-string values or even deleted. We want to "
"make sure that these attributes always contain strings." "make sure that these attributes always contain strings."
msgstr "" msgstr ""
"Dans cette section, nous assurons un contrôle plus précis sur la façon dont "
"les attributs :attr:`first` et :attr:`last` sont définis dans l'exemple :"
"class:`Custom`. Dans la version précédente de notre module, les variables "
"d'instance :attr:`first` et :attr:`last` pouvaient être définies sur des "
"valeurs autres que des chaînes ou même supprimées. Nous voulons nous assurer "
"que ces attributs contiennent toujours des chaînes."
#: extending/newtypes_tutorial.rst:550 #: extending/newtypes_tutorial.rst:550
msgid "" msgid ""
@ -674,6 +830,10 @@ msgid ""
"attributes, we'll use custom getter and setter functions. Here are the " "attributes, we'll use custom getter and setter functions. Here are the "
"functions for getting and setting the :attr:`first` attribute::" "functions for getting and setting the :attr:`first` attribute::"
msgstr "" msgstr ""
"Pour avoir un meilleur contrôle sur les attributs :attr:`first` et :attr:"
"`last`, nous utilisons des fonctions accesseur (*getter*) et mutateur "
"(*setter*) personnalisées. Voici les fonctions pour obtenir et définir "
"l'attribut :attr:`first` ::"
#: extending/newtypes_tutorial.rst:581 #: extending/newtypes_tutorial.rst:581
msgid "" msgid ""
@ -684,6 +844,13 @@ msgid ""
"getter and setter functions that decide the attribute to get or set based on " "getter and setter functions that decide the attribute to get or set based on "
"data in the closure.)" "data in the closure.)"
msgstr "" msgstr ""
"L'accesseur reçoit un objet :class:`Custom` et une fermeture qui est un "
"pointeur vide. Dans ce cas, la fermeture est ignorée. (La fermeture prend en "
"charge une utilisation avancée dans laquelle les données de définition sont "
"transmises à l'accesseur et au mutateur. Cela pourrait, par exemple, être "
"utilisé pour autoriser un seul ensemble de fonctions accesseur et mutateur "
"qui décident de l'attribut à obtenir ou à définir en fonction des données "
"dans la fermeture.)"
#: extending/newtypes_tutorial.rst:587 #: extending/newtypes_tutorial.rst:587
msgid "" msgid ""
@ -692,14 +859,19 @@ msgid ""
"being deleted. In our setter, we raise an error if the attribute is deleted " "being deleted. In our setter, we raise an error if the attribute is deleted "
"or if its new value is not a string." "or if its new value is not a string."
msgstr "" msgstr ""
"Le mutateur reçoit l'objet :class:`Custom`, la nouvelle valeur et la "
"fermeture. La nouvelle valeur peut être ``NULL``, auquel cas l'attribut est "
"supprimé. Dans notre mutateur, nous levons une erreur si l'attribut est "
"supprimé ou si sa nouvelle valeur n'est pas une chaîne."
#: extending/newtypes_tutorial.rst:592 #: extending/newtypes_tutorial.rst:592
msgid "We create an array of :c:type:`PyGetSetDef` structures::" msgid "We create an array of :c:type:`PyGetSetDef` structures::"
msgstr "" msgstr "Nous créons un tableau de structures :c:type:`PyGetSetDef` ::"
#: extending/newtypes_tutorial.rst:602 #: extending/newtypes_tutorial.rst:602
msgid "and register it in the :c:member:`~PyTypeObject.tp_getset` slot::" msgid "and register it in the :c:member:`~PyTypeObject.tp_getset` slot::"
msgstr "" msgstr ""
"et l'enregistrons dans l'emplacement :c:member:`~PyTypeObject.tp_getset` ::"
#: extending/newtypes_tutorial.rst:606 #: extending/newtypes_tutorial.rst:606
msgid "" msgid ""
@ -707,16 +879,22 @@ msgid ""
"mentioned above. In this case, we aren't using a closure, so we just pass " "mentioned above. In this case, we aren't using a closure, so we just pass "
"``NULL``." "``NULL``."
msgstr "" msgstr ""
"Le dernier élément d'une structure :c:type:`PyGetSetDef` est la fermeture "
"mentionnée ci-dessus. Dans ce cas, nous n'utilisons pas de fermeture, nous "
"passons donc simplement ``NULL``."
#: extending/newtypes_tutorial.rst:609 #: extending/newtypes_tutorial.rst:609
msgid "We also remove the member definitions for these attributes::" msgid "We also remove the member definitions for these attributes::"
msgstr "" msgstr ""
"Nous supprimons également les définitions de membre pour ces attributs :"
#: extending/newtypes_tutorial.rst:617 #: extending/newtypes_tutorial.rst:617
msgid "" msgid ""
"We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only " "We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only "
"allow strings [#]_ to be passed::" "allow strings [#]_ to be passed::"
msgstr "" msgstr ""
"Nous devons également mettre à jour le gestionnaire :c:member:`~PyTypeObject."
"tp_init` pour autoriser uniquement le passage des chaînes [#]_ ::"
#: extending/newtypes_tutorial.rst:646 #: extending/newtypes_tutorial.rst:646
msgid "" msgid ""
@ -727,6 +905,13 @@ msgid ""
"these calls is in the ``tp_dealloc`` implementation, where there is the " "these calls is in the ``tp_dealloc`` implementation, where there is the "
"possibility that the initialization of these members failed in ``tp_new``." "possibility that the initialization of these members failed in ``tp_new``."
msgstr "" msgstr ""
"Avec ces modifications, nous pouvons garantir que les membres ``first`` et "
"``last`` ne sont jamais ``NULL``, nous pouvons donc supprimer les "
"vérifications des valeurs ``NULL`` dans presque tous les cas. Cela signifie "
"que la plupart des appels :c:func:`Py_XDECREF` peuvent être convertis en "
"appels :c:func:`Py_DECREF`. Le seul endroit où nous ne pouvons pas modifier "
"ces appels est dans l'implémentation de ``tp_dealloc``, où il est possible "
"que l'initialisation de ces membres ait échoué dans ``tp_new``."
#: extending/newtypes_tutorial.rst:653 #: extending/newtypes_tutorial.rst:653
msgid "" msgid ""
@ -734,10 +919,14 @@ msgid ""
"initialization function, as we did before, and we add an extra definition to " "initialization function, as we did before, and we add an extra definition to "
"the :file:`setup.py` file." "the :file:`setup.py` file."
msgstr "" msgstr ""
"Nous renommons également la fonction d'initialisation du module et le nom du "
"module dans la fonction d'initialisation, comme nous l'avons fait "
"précédemment, et nous ajoutons une définition supplémentaire au fichier :"
"file:`setup.py`."
#: extending/newtypes_tutorial.rst:659 #: extending/newtypes_tutorial.rst:659
msgid "Supporting cyclic garbage collection" msgid "Supporting cyclic garbage collection"
msgstr "" msgstr "Prise en charge du ramasse-miettes cyclique"
#: extending/newtypes_tutorial.rst:661 #: extending/newtypes_tutorial.rst:661
msgid "" msgid ""
@ -745,6 +934,10 @@ msgid ""
"can identify unneeded objects even when their reference counts are not zero. " "can identify unneeded objects even when their reference counts are not zero. "
"This can happen when objects are involved in cycles. For example, consider:" "This can happen when objects are involved in cycles. For example, consider:"
msgstr "" msgstr ""
"Python a un :term:`ramasse-miettes cyclique <garbage collection>` qui peut "
"identifier les objets inutiles même lorsque leur compteur de références "
"n'est pas nul. Cela peut se produire lorsque des objets sont impliqués dans "
"des cycles. Par exemple, considérons :"
#: extending/newtypes_tutorial.rst:671 #: extending/newtypes_tutorial.rst:671
msgid "" msgid ""
@ -753,6 +946,11 @@ msgid ""
"zero. Fortunately, Python's cyclic garbage collector will eventually figure " "zero. Fortunately, Python's cyclic garbage collector will eventually figure "
"out that the list is garbage and free it." "out that the list is garbage and free it."
msgstr "" msgstr ""
"Dans cet exemple, nous créons une liste qui se contient elle-même. Lorsque "
"nous la supprimons, il existe toujours une référence à elle-même. Son "
"compteur de références ne tombe pas à zéro. Heureusement, le ramasse-miettes "
"cyclique de Python finira par comprendre que la liste est un déchet et la "
"libérera."
#: extending/newtypes_tutorial.rst:676 #: extending/newtypes_tutorial.rst:676
msgid "" msgid ""
@ -762,6 +960,12 @@ msgid ""
"`Custom`, and subclasses may add arbitrary attributes. For any of those two " "`Custom`, and subclasses may add arbitrary attributes. For any of those two "
"reasons, :class:`Custom` objects can participate in cycles:" "reasons, :class:`Custom` objects can participate in cycles:"
msgstr "" msgstr ""
"Dans la seconde version de l'exemple :class:`Custom`, nous avons autorisé le "
"stockage de n'importe quel type d'objet dans les attributs :attr:`first` ou :"
"attr:`last` [#]_. De plus, dans les deuxième et troisième versions, nous "
"avons autorisé le sous-classement de :class:`Custom`, et les sous-classes "
"peuvent ajouter des attributs arbitraires. Pour l'une de ces deux raisons, "
"les objets :class:`Custom` peuvent produire des cycles :"
#: extending/newtypes_tutorial.rst:690 #: extending/newtypes_tutorial.rst:690
msgid "" msgid ""
@ -770,12 +974,19 @@ msgid ""
"needs to fill two additional slots and to enable a flag that enables these " "needs to fill two additional slots and to enable a flag that enables these "
"slots:" "slots:"
msgstr "" msgstr ""
"Pour permettre à une instance :class:`Custom` participant à des références "
"cycliques d'être correctement détectée et collectée par le ramasse-miettes "
"cyclique, notre type :class:`Custom` doit définir deux emplacements "
"supplémentaires et activer un drapeau qui active ces emplacements :"
#: extending/newtypes_tutorial.rst:697 #: extending/newtypes_tutorial.rst:697
msgid "" msgid ""
"First, the traversal method lets the cyclic GC know about subobjects that " "First, the traversal method lets the cyclic GC know about subobjects that "
"could participate in cycles::" "could participate in cycles::"
msgstr "" msgstr ""
"Tout d'abord, la méthode de parcours (*Custom_traverse*) permet au ramasse-"
"miettes cyclique de connaître les sous-objets qui pourraient conduire à des "
"cycles ::"
#: extending/newtypes_tutorial.rst:717 #: extending/newtypes_tutorial.rst:717
msgid "" msgid ""
@ -785,6 +996,11 @@ msgid ""
"*arg* passed to the traversal method. It returns an integer value that must " "*arg* passed to the traversal method. It returns an integer value that must "
"be returned if it is non-zero." "be returned if it is non-zero."
msgstr "" msgstr ""
"Pour chaque sous-objet pouvant conduire à des cycles, nous devons appeler la "
"fonction :c:func:`visit`, qui est passée à la méthode de parcours. La "
"fonction :c:func:`visit` prend comme arguments le sous-objet et l'argument "
"supplémentaire *arg* passé à la méthode de parcours. Elle renvoie une valeur "
"entière qui doit être renvoyée si elle est différente de zéro."
#: extending/newtypes_tutorial.rst:723 #: extending/newtypes_tutorial.rst:723
msgid "" msgid ""
@ -792,18 +1008,26 @@ msgid ""
"functions. With :c:func:`Py_VISIT`, we can minimize the amount of " "functions. With :c:func:`Py_VISIT`, we can minimize the amount of "
"boilerplate in ``Custom_traverse``::" "boilerplate in ``Custom_traverse``::"
msgstr "" msgstr ""
"Python fournit une macro :c:func:`Py_VISIT` qui automatise l'appel des "
"fonctions de visite. Avec :c:func:`Py_VISIT`, nous pouvons minimiser la "
"quantité de code générique dans ``Custom_traverse`` ::"
# suit un :
#: extending/newtypes_tutorial.rst:736 #: extending/newtypes_tutorial.rst:736
msgid "" msgid ""
"The :c:member:`~PyTypeObject.tp_traverse` implementation must name its " "The :c:member:`~PyTypeObject.tp_traverse` implementation must name its "
"arguments exactly *visit* and *arg* in order to use :c:func:`Py_VISIT`." "arguments exactly *visit* and *arg* in order to use :c:func:`Py_VISIT`."
msgstr "" msgstr ""
"l'implémentation :c:member:`~PyTypeObject.tp_traverse` doit nommer ses "
"arguments exactement *visit* et *arg* afin d'utiliser :c:func:`Py_VISIT`."
#: extending/newtypes_tutorial.rst:739 #: extending/newtypes_tutorial.rst:739
msgid "" msgid ""
"Second, we need to provide a method for clearing any subobjects that can " "Second, we need to provide a method for clearing any subobjects that can "
"participate in cycles::" "participate in cycles::"
msgstr "" msgstr ""
"Deuxièmement, nous devons fournir une méthode pour effacer tous les sous-"
"objets qui peuvent conduire à des cycles ::"
#: extending/newtypes_tutorial.rst:750 #: extending/newtypes_tutorial.rst:750
msgid "" msgid ""
@ -814,10 +1038,17 @@ msgid ""
"attribute's destructor would call back into code that reads the attribute " "attribute's destructor would call back into code that reads the attribute "
"again (*especially* if there is a reference cycle)." "again (*especially* if there is a reference cycle)."
msgstr "" msgstr ""
"Notez l'utilisation de la macro :c:func:`Py_CLEAR`. C'est le moyen "
"recommandé et sûr d'effacer les attributs de données de types arbitraires "
"tout en décrémentant leur compteur de références. Si vous deviez appeler :c:"
"func:`Py_XDECREF` à la place sur l'attribut avant de le définir sur "
"``NULL``, il est possible que le destructeur de l'attribut appelle du code "
"qui lit à nouveau l'attribut (*surtout* s'il existe un cycle de références)."
# suit un :
#: extending/newtypes_tutorial.rst:758 #: extending/newtypes_tutorial.rst:758
msgid "You could emulate :c:func:`Py_CLEAR` by writing::" msgid "You could emulate :c:func:`Py_CLEAR` by writing::"
msgstr "" msgstr "vous pouvez émuler :c:func:`Py_CLEAR` en écrivant ::"
#: extending/newtypes_tutorial.rst:765 #: extending/newtypes_tutorial.rst:765
msgid "" msgid ""
@ -825,6 +1056,9 @@ msgid ""
"`Py_CLEAR` when deleting an attribute. Don't try to micro-optimize at the " "`Py_CLEAR` when deleting an attribute. Don't try to micro-optimize at the "
"expense of robustness!" "expense of robustness!"
msgstr "" msgstr ""
"Néanmoins, il est beaucoup plus facile et moins sujet aux erreurs de "
"toujours utiliser :c:func:`Py_CLEAR` lors de la suppression d'un attribut. "
"N'essayez pas de micro-optimiser au détriment de la robustesse !"
#: extending/newtypes_tutorial.rst:769 #: extending/newtypes_tutorial.rst:769
msgid "" msgid ""
@ -835,11 +1069,21 @@ msgid ""
"members. Here is our reimplemented deallocator using :c:func:" "members. Here is our reimplemented deallocator using :c:func:"
"`PyObject_GC_UnTrack` and ``Custom_clear``::" "`PyObject_GC_UnTrack` and ``Custom_clear``::"
msgstr "" msgstr ""
"La fonction de libération de la mémoire ``Custom_dealloc`` peut appeler du "
"code arbitraire lors de la suppression des attributs. Cela signifie que le "
"ramasse-miettes cyclique peut être déclenché à l'intérieur de la fonction. "
"Étant donné que le ramasse-miettes suppose que le nombre de références n'est "
"pas nul, nous devons annuler le suivi de l'objet par le ramasse-miettes en "
"appelant :c:func:`PyObject_GC_UnTrack` avant d'effacer les membres. Voici "
"notre fonction de libération de la mémoire réimplémentée en utilisant :c:"
"func:`PyObject_GC_UnTrack` et ``Custom_clear`` ::"
#: extending/newtypes_tutorial.rst:784 #: extending/newtypes_tutorial.rst:784
msgid "" msgid ""
"Finally, we add the :c:macro:`Py_TPFLAGS_HAVE_GC` flag to the class flags::" "Finally, we add the :c:macro:`Py_TPFLAGS_HAVE_GC` flag to the class flags::"
msgstr "" msgstr ""
"Enfin, nous ajoutons le drapeau :c:macro:`Py_TPFLAGS_HAVE_GC` aux drapeaux "
"de la classe ::"
#: extending/newtypes_tutorial.rst:788 #: extending/newtypes_tutorial.rst:788
msgid "" msgid ""
@ -848,10 +1092,14 @@ msgid ""
"them for cyclic garbage collection. Most extensions will use the versions " "them for cyclic garbage collection. Most extensions will use the versions "
"automatically provided." "automatically provided."
msgstr "" msgstr ""
"C'est à peu près tout. Si nous avions écrit des gestionnaires personnalisés :"
"c:member:`~PyTypeObject.tp_alloc` ou :c:member:`~PyTypeObject.tp_free`, nous "
"aurions besoin de les modifier pour le ramasse-miettes cyclique. La plupart "
"des extensions utilisent les versions fournies automatiquement."
#: extending/newtypes_tutorial.rst:794 #: extending/newtypes_tutorial.rst:794
msgid "Subclassing other types" msgid "Subclassing other types"
msgstr "" msgstr "Sous-classement d'autres types"
#: extending/newtypes_tutorial.rst:796 #: extending/newtypes_tutorial.rst:796
msgid "" msgid ""
@ -860,6 +1108,11 @@ msgid ""
"can easily use the :c:type:`PyTypeObject` it needs. It can be difficult to " "can easily use the :c:type:`PyTypeObject` it needs. It can be difficult to "
"share these :c:type:`PyTypeObject` structures between extension modules." "share these :c:type:`PyTypeObject` structures between extension modules."
msgstr "" msgstr ""
"Il est possible de créer de nouveaux types d'extension dérivés de types "
"existants. Il est plus facile d'hériter des types natifs, car une extension "
"peut facilement utiliser le :c:type:`PyTypeObject` dont elle a besoin. Il "
"peut être difficile de partager ces structures :c:type:`PyTypeObject` entre "
"modules d'extension."
#: extending/newtypes_tutorial.rst:801 #: extending/newtypes_tutorial.rst:801
msgid "" msgid ""
@ -868,6 +1121,10 @@ msgid ""
"with regular lists, but will have an additional :meth:`increment` method " "with regular lists, but will have an additional :meth:`increment` method "
"that increases an internal counter:" "that increases an internal counter:"
msgstr "" msgstr ""
"Dans cet exemple, nous allons créer un type :class:`SubList` qui hérite du "
"type intégré :class:`list`. Le nouveau type sera complètement compatible "
"avec les listes natives, mais aura une méthode supplémentaire :meth:"
"`increment` qui augmente un compteur interne :"
#: extending/newtypes_tutorial.rst:821 #: extending/newtypes_tutorial.rst:821
msgid "" msgid ""
@ -875,6 +1132,9 @@ msgid ""
"examples in previous sections. We will break down the main differences " "examples in previous sections. We will break down the main differences "
"between them. ::" "between them. ::"
msgstr "" msgstr ""
"Comme vous pouvez le voir, le code source ressemble beaucoup aux exemples :"
"class:`Custom` des sections précédentes. Analysons les principales "
"différences ::"
#: extending/newtypes_tutorial.rst:829 #: extending/newtypes_tutorial.rst:829
msgid "" msgid ""
@ -882,6 +1142,9 @@ msgid ""
"object structure must be the first value. The base type will already " "object structure must be the first value. The base type will already "
"include the :c:func:`PyObject_HEAD` at the beginning of its structure." "include the :c:func:`PyObject_HEAD` at the beginning of its structure."
msgstr "" msgstr ""
"La principale différence pour les objets d'un type dérivé est que la "
"structure d'objet du type père doit être la première valeur. Le type père "
"inclut déjà le :c:func:`PyObject_HEAD` au début de sa structure."
#: extending/newtypes_tutorial.rst:833 #: extending/newtypes_tutorial.rst:833
msgid "" msgid ""
@ -889,12 +1152,17 @@ msgid ""
"pointer can be safely cast to both ``PyListObject *`` and ``SubListObject " "pointer can be safely cast to both ``PyListObject *`` and ``SubListObject "
"*``::" "*``::"
msgstr "" msgstr ""
"Lorsqu'un objet Python est une instance de :class:`SubList`, son pointeur "
"``PyObject *`` peut être trans-typé en toute sécurité vers ``PyListObject "
"*`` et ``SubListObject *`` ::"
#: extending/newtypes_tutorial.rst:845 #: extending/newtypes_tutorial.rst:845
msgid "" msgid ""
"We see above how to call through to the :attr:`__init__` method of the base " "We see above how to call through to the :attr:`__init__` method of the base "
"type." "type."
msgstr "" msgstr ""
"Nous voyons ci-dessus comment appeler la méthode :attr:`__init__` du type "
"père."
#: extending/newtypes_tutorial.rst:848 #: extending/newtypes_tutorial.rst:848
msgid "" msgid ""
@ -904,6 +1172,12 @@ msgid ""
"memory for the object with its :c:member:`~PyTypeObject.tp_alloc`, but let " "memory for the object with its :c:member:`~PyTypeObject.tp_alloc`, but let "
"the base class handle it by calling its own :c:member:`~PyTypeObject.tp_new`." "the base class handle it by calling its own :c:member:`~PyTypeObject.tp_new`."
msgstr "" msgstr ""
"Ce modèle est important lors de l'écriture d'un type avec des membres "
"personnalisés :c:member:`~PyTypeObject.tp_new` et :c:member:`~PyTypeObject."
"tp_dealloc`. Le gestionnaire :c:member:`~PyTypeObject.tp_new` ne doit pas "
"réellement allouer la mémoire pour l'objet avec son :c:member:`~PyTypeObject."
"tp_alloc`, mais laisser la classe mère gérer ça en appelant sa propre :c:"
"member:`~PyTypeObject.tp_new`."
#: extending/newtypes_tutorial.rst:854 #: extending/newtypes_tutorial.rst:854
msgid "" msgid ""
@ -913,6 +1187,11 @@ msgid ""
"type:`PyList_Type`; it should be done later in the module initialization " "type:`PyList_Type`; it should be done later in the module initialization "
"function::" "function::"
msgstr "" msgstr ""
"La structure :c:type:`PyTypeObject` prend en charge un :c:member:"
"`~PyTypeObject.tp_base` spécifiant la classe mère concrète du type. En "
"raison de problèmes de compilateur multiplateformes, vous ne pouvez pas "
"remplir ce champ directement avec une référence à :c:type:`PyList_Type` ; "
"cela doit être fait plus tard dans la fonction d'initialisation du module ::"
#: extending/newtypes_tutorial.rst:882 #: extending/newtypes_tutorial.rst:882
msgid "" msgid ""
@ -922,12 +1201,19 @@ msgid ""
"tp_alloc` slot with :c:func:`PyType_GenericNew` -- the allocation function " "tp_alloc` slot with :c:func:`PyType_GenericNew` -- the allocation function "
"from the base type will be inherited." "from the base type will be inherited."
msgstr "" msgstr ""
"Avant d'appeler :c:func:`PyType_Ready`, la structure de type doit avoir "
"l'emplacement :c:member:`~PyTypeObject.tp_base` rempli. Lorsque nous "
"dérivons un type existant, il n'est pas nécessaire de remplir l'emplacement :"
"c:member:`~PyTypeObject.tp_alloc` avec :c:func:`PyType_GenericNew` la "
"fonction d'allocation du type père sera héritée."
#: extending/newtypes_tutorial.rst:888 #: extending/newtypes_tutorial.rst:888
msgid "" msgid ""
"After that, calling :c:func:`PyType_Ready` and adding the type object to the " "After that, calling :c:func:`PyType_Ready` and adding the type object to the "
"module is the same as with the basic :class:`Custom` examples." "module is the same as with the basic :class:`Custom` examples."
msgstr "" msgstr ""
"Ensuite, appeler :c:func:`PyType_Ready` et ajouter l'objet type au module se "
"fait de la même manière qu'avec les exemples de base :class:`Custom`."
#: extending/newtypes_tutorial.rst:893 #: extending/newtypes_tutorial.rst:893
msgid "Footnotes" msgid "Footnotes"
@ -938,12 +1224,17 @@ msgid ""
"This is true when we know that the object is a basic type, like a string or " "This is true when we know that the object is a basic type, like a string or "
"a float." "a float."
msgstr "" msgstr ""
"C'est vrai lorsque nous savons que l'objet est un type de base, comme une "
"chaîne ou un flottant."
#: extending/newtypes_tutorial.rst:897 #: extending/newtypes_tutorial.rst:897
msgid "" msgid ""
"We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler in " "We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler in "
"this example, because our type doesn't support garbage collection." "this example, because our type doesn't support garbage collection."
msgstr "" msgstr ""
"Nous nous sommes appuyés sur le gestionnaire :c:member:`~PyTypeObject."
"tp_dealloc` dans cet exemple, car notre type ne prend pas en charge le "
"ramasse-miettes."
#: extending/newtypes_tutorial.rst:900 #: extending/newtypes_tutorial.rst:900
msgid "" msgid ""
@ -954,6 +1245,13 @@ msgid ""
"deallocating an instance of a string subclass won't call back into our " "deallocating an instance of a string subclass won't call back into our "
"objects." "objects."
msgstr "" msgstr ""
"Nous savons maintenant que les premier et dernier membres sont des chaînes, "
"nous pourrions donc peut-être être moins prudents quant à la décrémentation "
"de leur nombre de références, cependant, nous acceptons les instances de "
"sous-classes de chaînes. Même si la libération de la mémoire des chaînes "
"normales ne rappellera pas nos objets, nous ne pouvons pas garantir que la "
"libération de mémoire d'une instance d'une sous-classe de chaîne ne "
"rappellera pas nos objets."
#: extending/newtypes_tutorial.rst:906 #: extending/newtypes_tutorial.rst:906
msgid "" msgid ""
@ -961,3 +1259,6 @@ msgid ""
"could pass arbitrary :class:`str` subclasses and therefore still create " "could pass arbitrary :class:`str` subclasses and therefore still create "
"reference cycles." "reference cycles."
msgstr "" msgstr ""
"De plus, même avec nos attributs limités aux instances de chaînes, "
"l'utilisateur pourrait passer des sous-classes arbitraires :class:`str` et "
"donc encore créer des références cycliques."