9
9
import shutil
10
10
import sys
11
11
import time
12
- from typing import Any , List , Optional , TextIO , Tuple , cast
12
+ from typing import Any , List , TextIO , cast
13
13
14
14
import pyinstrument
15
15
from pyinstrument import Profiler , renderers
@@ -410,7 +410,10 @@ def store_and_consume_remaining(
410
410
411
411
412
412
def compute_render_options (
413
- options : CommandLineOptions , renderer_class : type [renderers .Renderer ], output_file : TextIO
413
+ options : CommandLineOptions ,
414
+ renderer_class : type [renderers .Renderer ],
415
+ unicode_support : bool ,
416
+ color_support : bool ,
414
417
) -> dict [str , Any ]:
415
418
"""
416
419
Given a list of CommandLineOptions, compute the
@@ -420,33 +423,9 @@ def compute_render_options(
420
423
421
424
"""
422
425
423
- unicode_support : bool = file_supports_unicode (output_file )
424
- color_support : bool = file_supports_color (output_file )
425
-
426
- error , render_options = _compute_render_options (
427
- options , renderer_class , unicode_support , color_support
428
- )
429
- if error is not None :
430
- raise OptionsParseError (error )
431
- assert render_options is not None
432
- return render_options
433
-
434
-
435
- def _compute_render_options (
436
- options : CommandLineOptions ,
437
- renderer_class : type [renderers .Renderer ],
438
- unicode_support : bool ,
439
- color_support : bool ,
440
- ) -> Tuple [Optional [str ], Optional [dict [str , Any ]]]:
441
- """
442
- Similar as compute_render_options, but return a tuple (error message, data)
443
- if there is an error; this will let us reuse _compute_render_options in magics.
444
-
445
- output_file, has been replaced by unicode_support:bool, color_support:bool
446
- """
447
426
# parse show/hide options
448
427
if options .hide_fnmatch is not None and options .hide_regex is not None :
449
- return ("You can‘t specify both --hide and --hide-regex" , None )
428
+ raise OptionsParseError ("You can‘t specify both --hide and --hide-regex" )
450
429
451
430
hide_regex : str | None
452
431
show_regex : str | None
@@ -461,7 +440,7 @@ def _compute_render_options(
461
440
options .show_all ,
462
441
]
463
442
if show_options_used .count (True ) > 1 :
464
- return ("You can only specify one of --show, --show-regex and --show-all" , None )
443
+ raise OptionsParseError ("You can only specify one of --show, --show-regex and --show-all" )
465
444
466
445
if options .show_fnmatch is not None :
467
446
show_regex = fnmatch .translate (options .show_fnmatch )
@@ -510,7 +489,7 @@ def _compute_render_options(
510
489
511
490
keypath .set_value_at_keypath (render_options , key , parsed_value )
512
491
513
- return None , render_options
492
+ return render_options
514
493
515
494
516
495
class OptionsParseError (Exception ):
@@ -521,7 +500,10 @@ def create_renderer(
521
500
renderer_class : type [renderers .Renderer ], options : CommandLineOptions , output_file : TextIO
522
501
) -> renderers .Renderer :
523
502
render_options = compute_render_options (
524
- options , renderer_class = renderer_class , output_file = output_file
503
+ options ,
504
+ renderer_class = renderer_class ,
505
+ unicode_support = file_supports_unicode (output_file ),
506
+ color_support = file_supports_color (output_file ),
525
507
)
526
508
527
509
try :
0 commit comments