@@ -101,7 +101,9 @@ int _PyOS_GetOpt(Py_ssize_t argc, wchar_t * const *argv, int *longindex)
101101 if (option == L'- ') {
102102 // Parse long option.
103103 if (* opt_ptr == L'\0' ) {
104- fprintf (stderr , "expected long option\n" );
104+ if (_PyOS_opterr ) {
105+ fprintf (stderr , "expected long option\n" );
106+ }
105107 return -1 ;
106108 }
107109 * longindex = 0 ;
@@ -111,31 +113,37 @@ int _PyOS_GetOpt(Py_ssize_t argc, wchar_t * const *argv, int *longindex)
111113 break ;
112114 }
113115 if (!opt -> name ) {
114- fprintf (stderr , "unknown option %ls\n" , argv [_PyOS_optind - 1 ]);
116+ if (_PyOS_opterr ) {
117+ fprintf (stderr , "unknown option %ls\n" , argv [_PyOS_optind - 1 ]);
118+ }
115119 return '_' ;
116120 }
117121 opt_ptr = L"" ;
118122 if (!opt -> has_arg ) {
119123 return opt -> val ;
120124 }
121125 if (_PyOS_optind >= argc ) {
122- fprintf (stderr , "Argument expected for the %ls options\n" ,
123- argv [_PyOS_optind - 1 ]);
126+ if (_PyOS_opterr ) {
127+ fprintf (stderr , "Argument expected for the %ls options\n" ,
128+ argv [_PyOS_optind - 1 ]);
129+ }
124130 return '_' ;
125131 }
126132 _PyOS_optarg = argv [_PyOS_optind ++ ];
127133 return opt -> val ;
128134 }
129135
130136 if (option == 'J ') {
131- if (_PyOS_opterr )
137+ if (_PyOS_opterr ) {
132138 fprintf (stderr , "-J is reserved for Jython\n" );
139+ }
133140 return '_ ';
134141 }
135142
136143 if ((ptr = wcschr (SHORT_OPTS , option )) == NULL) {
137- if (_PyOS_opterr )
144+ if (_PyOS_opterr ) {
138145 fprintf (stderr , "Unknown option: -%c\n" , (char )option );
146+ }
139147 return '_' ;
140148 }
141149
@@ -147,9 +155,10 @@ int _PyOS_GetOpt(Py_ssize_t argc, wchar_t * const *argv, int *longindex)
147155
148156 else {
149157 if (_PyOS_optind >= argc ) {
150- if (_PyOS_opterr )
158+ if (_PyOS_opterr ) {
151159 fprintf (stderr ,
152160 "Argument expected for the -%c option\n" , (char )option );
161+ }
153162 return '_' ;
154163 }
155164
0 commit comments