@@ -2474,18 +2474,21 @@ def getAllCurves(self, just_legend=False, withhidden=False):
2474
2474
]
2475
2475
return [curve .getName () for curve in curves ] if just_legend else curves
2476
2476
2477
- def getCurve (self , legend = None ):
2477
+ def getCurve (self , legend : str | items . Curve | None = None ) -> items . Curve :
2478
2478
"""Get the object describing a specific curve.
2479
2479
2480
2480
It returns None in case no matching curve is found.
2481
2481
2482
- :param str legend:
2482
+ :param legend:
2483
2483
The legend identifying the curve.
2484
2484
If not provided or None (the default), the active curve is returned
2485
2485
or if there is no active curve, the latest updated curve that is
2486
2486
not hidden is returned if there are curves in the plot.
2487
2487
:return: None or :class:`.items.Curve` object
2488
2488
"""
2489
+ if isinstance (legend , items .Curve ):
2490
+ _logger .warning ("getCurve call not needed: legend is already an item" )
2491
+ return legend
2489
2492
return self ._getItem (kind = "curve" , legend = legend )
2490
2493
2491
2494
def getAllImages (self , just_legend = False ):
@@ -2506,48 +2509,57 @@ def getAllImages(self, just_legend=False):
2506
2509
images = [item for item in self .getItems () if isinstance (item , items .ImageBase )]
2507
2510
return [image .getName () for image in images ] if just_legend else images
2508
2511
2509
- def getImage (self , legend = None ):
2512
+ def getImage (self , legend : str | items . ImageBase | None = None ) -> items . ImageBase :
2510
2513
"""Get the object describing a specific image.
2511
2514
2512
2515
It returns None in case no matching image is found.
2513
2516
2514
- :param str legend:
2517
+ :param legend:
2515
2518
The legend identifying the image.
2516
2519
If not provided or None (the default), the active image is returned
2517
2520
or if there is no active image, the latest updated image
2518
2521
is returned if there are images in the plot.
2519
2522
:return: None or :class:`.items.ImageBase` object
2520
2523
"""
2524
+ if isinstance (legend , items .ImageBase ):
2525
+ _logger .warning ("getImage call not needed: legend is already an item" )
2526
+ return legend
2521
2527
return self ._getItem (kind = "image" , legend = legend )
2522
2528
2523
- def getScatter (self , legend = None ):
2529
+ def getScatter (self , legend : str | items . Scatter | None = None ) -> items . Scatter :
2524
2530
"""Get the object describing a specific scatter.
2525
2531
2526
2532
It returns None in case no matching scatter is found.
2527
2533
2528
- :param str legend:
2534
+ :param legend:
2529
2535
The legend identifying the scatter.
2530
2536
If not provided or None (the default), the active scatter is
2531
2537
returned or if there is no active scatter, the latest updated
2532
2538
scatter is returned if there are scatters in the plot.
2533
2539
:return: None or :class:`.items.Scatter` object
2534
2540
"""
2541
+ if isinstance (legend , items .Scatter ):
2542
+ _logger .warning ("getScatter call not needed: legend is already an item" )
2543
+ return legend
2535
2544
return self ._getItem (kind = "scatter" , legend = legend )
2536
2545
2537
- def getHistogram (self , legend = None ):
2546
+ def getHistogram (self , legend : str | items . Histogram | None = None ) -> items . Histogram :
2538
2547
"""Get the object describing a specific histogram.
2539
2548
2540
2549
It returns None in case no matching histogram is found.
2541
2550
2542
- :param str legend:
2551
+ :param legend:
2543
2552
The legend identifying the histogram.
2544
2553
If not provided or None (the default), the latest updated scatter
2545
2554
is returned if there are histograms in the plot.
2546
2555
:return: None or :class:`.items.Histogram` object
2547
2556
"""
2557
+ if isinstance (legend , items .Histogram ):
2558
+ _logger .warning ("getHistogram call not needed: legend is already an item" )
2559
+ return legend
2548
2560
return self ._getItem (kind = "histogram" , legend = legend )
2549
2561
2550
- def _getItem (self , kind , legend = None ):
2562
+ def _getItem (self , kind , legend = None ) -> items . Item :
2551
2563
"""Get an item from the plot: either an image or a curve.
2552
2564
2553
2565
Returns None if no match found.
@@ -2558,6 +2570,10 @@ def _getItem(self, kind, legend=None):
2558
2570
None to get active or last item
2559
2571
:return: Object describing the item or None
2560
2572
"""
2573
+ if isinstance (legend , items .Item ):
2574
+ _logger .warning ("_getItem call not needed: legend is already an item" )
2575
+ return legend
2576
+
2561
2577
assert kind in self .ITEM_KINDS
2562
2578
2563
2579
if legend is not None :
0 commit comments