@@ -976,9 +976,9 @@ See the section on the default_ keyword argument for information on when the
976976``type `` argument is applied to default arguments.
977977
978978To ease the use of various types of files, the argparse module provides the
979- factory FileType which takes the ``mode= `` and ``bufsize= `` arguments of the
980- :func: `open ` function. For example, `` FileType('w') `` can be used to create a
981- writable file::
979+ factory FileType which takes the ``mode= ``, ``bufsize= ``, `` encoding= `` and
980+ `` errors= `` arguments of the :func: `open ` function. For example,
981+ `` FileType('w') `` can be used to create a writable file::
982982
983983 >>> parser = argparse.ArgumentParser()
984984 >>> parser.add_argument('bar', type=argparse.FileType('w'))
@@ -1618,17 +1618,19 @@ Sub-commands
16181618FileType objects
16191619^^^^^^^^^^^^^^^^
16201620
1621- .. class :: FileType(mode='r', bufsize=None)
1621+ .. class :: FileType(mode='r', bufsize=-1, encoding=None, errors= None)
16221622
16231623 The :class: `FileType ` factory creates objects that can be passed to the type
16241624 argument of :meth: `ArgumentParser.add_argument `. Arguments that have
1625- :class: `FileType ` objects as their type will open command-line arguments as files
1626- with the requested modes and buffer sizes::
1625+ :class: `FileType ` objects as their type will open command-line arguments as
1626+ files with the requested modes, buffer sizes, encodings and error handling
1627+ (see the :func: `open ` function for more details)::
16271628
16281629 >>> parser = argparse.ArgumentParser()
1629- >>> parser.add_argument('--output', type=argparse.FileType('wb', 0))
1630- >>> parser.parse_args(['--output', 'out'])
1631- Namespace(output=<_io.BufferedWriter name='out'>)
1630+ >>> parser.add_argument('--raw', type=argparse.FileType('wb', 0))
1631+ >>> parser.add_argument('out', type=argparse.FileType('w', encoding='UTF-8'))
1632+ >>> parser.parse_args(['--raw', 'raw.dat', 'file.txt'])
1633+ Namespace(out=<_io.TextIOWrapper name='file.txt' mode='w' encoding='UTF-8'>, raw=<_io.FileIO name='raw.dat' mode='wb'>)
16321634
16331635 FileType objects understand the pseudo-argument ``'-' `` and automatically
16341636 convert this into ``sys.stdin `` for readable :class: `FileType ` objects and
0 commit comments