Jeremiah Lowin Claude commited on
Commit
cd7d4ca
·
1 Parent(s): 5c9c10c

Fix pyright type checking issues in tests

Browse files

Add proper null checks and type assertions for prompt argument
handling in tests to satisfy pyright strict typing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

tests/prompts/test_prompt.py CHANGED
@@ -382,25 +382,58 @@ class TestPromptArgumentDescriptions:
382
 
383
  prompt = Prompt.from_function(analyze_data)
384
 
 
385
  # Check that string parameter has no schema enhancement
386
- name_arg = next(arg for arg in prompt.arguments if arg.name == "name")
 
387
  assert name_arg.description is None # No enhancement for string types
388
 
389
  # Check that non-string parameters have schema enhancements
390
- numbers_arg = next(arg for arg in prompt.arguments if arg.name == "numbers")
391
- assert "Provide as a JSON string matching the following schema:" in numbers_arg.description
 
 
 
 
 
 
 
392
  assert '{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
393
 
394
- metadata_arg = next(arg for arg in prompt.arguments if arg.name == "metadata")
395
- assert "Provide as a JSON string matching the following schema:" in metadata_arg.description
396
- assert '{"additionalProperties":{"type":"string"},"type":"object"}' in metadata_arg.description
 
 
 
 
 
 
 
 
 
 
397
 
398
- threshold_arg = next(arg for arg in prompt.arguments if arg.name == "threshold")
399
- assert "Provide as a JSON string matching the following schema:" in threshold_arg.description
 
 
 
 
 
 
 
400
  assert '{"type":"number"}' in threshold_arg.description
401
 
402
- active_arg = next(arg for arg in prompt.arguments if arg.name == "active")
403
- assert "Provide as a JSON string matching the following schema:" in active_arg.description
 
 
 
 
 
 
 
404
  assert '{"type":"boolean"}' in active_arg.description
405
 
406
  def test_enhanced_descriptions_with_existing_descriptions(self):
@@ -419,12 +452,19 @@ class TestPromptArgumentDescriptions:
419
 
420
  prompt = Prompt.from_function(documented_prompt)
421
 
422
- numbers_arg = next(arg for arg in prompt.arguments if arg.name == "numbers")
 
 
 
 
423
  # Should have both the original description and the schema
424
  assert numbers_arg.description is not None
425
  assert "A list of integers to process" in numbers_arg.description
426
  assert "\n\n" in numbers_arg.description # Should have newline separator
427
- assert "Provide as a JSON string matching the following schema:" in numbers_arg.description
 
 
 
428
 
429
  def test_string_parameters_no_enhancement(self):
430
  """Test that string parameters don't get schema enhancement."""
@@ -434,7 +474,11 @@ class TestPromptArgumentDescriptions:
434
 
435
  prompt = Prompt.from_function(string_only_prompt)
436
 
 
437
  for arg in prompt.arguments:
438
  # String parameters should not have schema enhancement
439
- if arg.description:
440
- assert "Provide as a JSON string matching the following schema:" not in arg.description
 
 
 
 
382
 
383
  prompt = Prompt.from_function(analyze_data)
384
 
385
+ assert prompt.arguments is not None
386
  # Check that string parameter has no schema enhancement
387
+ name_arg = next((arg for arg in prompt.arguments if arg.name == "name"), None)
388
+ assert name_arg is not None
389
  assert name_arg.description is None # No enhancement for string types
390
 
391
  # Check that non-string parameters have schema enhancements
392
+ numbers_arg = next(
393
+ (arg for arg in prompt.arguments if arg.name == "numbers"), None
394
+ )
395
+ assert numbers_arg is not None
396
+ assert numbers_arg.description is not None
397
+ assert (
398
+ "Provide as a JSON string matching the following schema:"
399
+ in numbers_arg.description
400
+ )
401
  assert '{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
402
 
403
+ metadata_arg = next(
404
+ (arg for arg in prompt.arguments if arg.name == "metadata"), None
405
+ )
406
+ assert metadata_arg is not None
407
+ assert metadata_arg.description is not None
408
+ assert (
409
+ "Provide as a JSON string matching the following schema:"
410
+ in metadata_arg.description
411
+ )
412
+ assert (
413
+ '{"additionalProperties":{"type":"string"},"type":"object"}'
414
+ in metadata_arg.description
415
+ )
416
 
417
+ threshold_arg = next(
418
+ (arg for arg in prompt.arguments if arg.name == "threshold"), None
419
+ )
420
+ assert threshold_arg is not None
421
+ assert threshold_arg.description is not None
422
+ assert (
423
+ "Provide as a JSON string matching the following schema:"
424
+ in threshold_arg.description
425
+ )
426
  assert '{"type":"number"}' in threshold_arg.description
427
 
428
+ active_arg = next(
429
+ (arg for arg in prompt.arguments if arg.name == "active"), None
430
+ )
431
+ assert active_arg is not None
432
+ assert active_arg.description is not None
433
+ assert (
434
+ "Provide as a JSON string matching the following schema:"
435
+ in active_arg.description
436
+ )
437
  assert '{"type":"boolean"}' in active_arg.description
438
 
439
  def test_enhanced_descriptions_with_existing_descriptions(self):
 
452
 
453
  prompt = Prompt.from_function(documented_prompt)
454
 
455
+ assert prompt.arguments is not None
456
+ numbers_arg = next(
457
+ (arg for arg in prompt.arguments if arg.name == "numbers"), None
458
+ )
459
+ assert numbers_arg is not None
460
  # Should have both the original description and the schema
461
  assert numbers_arg.description is not None
462
  assert "A list of integers to process" in numbers_arg.description
463
  assert "\n\n" in numbers_arg.description # Should have newline separator
464
+ assert (
465
+ "Provide as a JSON string matching the following schema:"
466
+ in numbers_arg.description
467
+ )
468
 
469
  def test_string_parameters_no_enhancement(self):
470
  """Test that string parameters don't get schema enhancement."""
 
474
 
475
  prompt = Prompt.from_function(string_only_prompt)
476
 
477
+ assert prompt.arguments is not None
478
  for arg in prompt.arguments:
479
  # String parameters should not have schema enhancement
480
+ if arg.description is not None:
481
+ assert (
482
+ "Provide as a JSON string matching the following schema:"
483
+ not in arg.description
484
+ )
tests/server/test_server_interactions.py CHANGED
@@ -1804,6 +1804,7 @@ class TestPrompts:
1804
  assert prompt.description == "Analyze some data."
1805
 
1806
  # Find each argument and verify schema enhancements
 
1807
  args_by_name = {arg.name: arg for arg in prompt.arguments}
1808
 
1809
  # String parameter should not have schema enhancement
@@ -1812,15 +1813,32 @@ class TestPrompts:
1812
 
1813
  # Non-string parameters should have schema enhancements
1814
  numbers_arg = args_by_name["numbers"]
1815
- assert "Provide as a JSON string matching the following schema:" in numbers_arg.description
1816
- assert '{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
 
 
 
 
 
 
1817
 
1818
  metadata_arg = args_by_name["metadata"]
1819
- assert "Provide as a JSON string matching the following schema:" in metadata_arg.description
1820
- assert '{"additionalProperties":{"type":"string"},"type":"object"}' in metadata_arg.description
 
 
 
 
 
 
 
1821
 
1822
  threshold_arg = args_by_name["threshold"]
1823
- assert "Provide as a JSON string matching the following schema:" in threshold_arg.description
 
 
 
 
1824
  assert '{"type":"number"}' in threshold_arg.description
1825
 
1826
  async def test_get_prompt(self):
 
1804
  assert prompt.description == "Analyze some data."
1805
 
1806
  # Find each argument and verify schema enhancements
1807
+ assert prompt.arguments is not None
1808
  args_by_name = {arg.name: arg for arg in prompt.arguments}
1809
 
1810
  # String parameter should not have schema enhancement
 
1813
 
1814
  # Non-string parameters should have schema enhancements
1815
  numbers_arg = args_by_name["numbers"]
1816
+ assert numbers_arg.description is not None
1817
+ assert (
1818
+ "Provide as a JSON string matching the following schema:"
1819
+ in numbers_arg.description
1820
+ )
1821
+ assert (
1822
+ '{"items":{"type":"integer"},"type":"array"}' in numbers_arg.description
1823
+ )
1824
 
1825
  metadata_arg = args_by_name["metadata"]
1826
+ assert metadata_arg.description is not None
1827
+ assert (
1828
+ "Provide as a JSON string matching the following schema:"
1829
+ in metadata_arg.description
1830
+ )
1831
+ assert (
1832
+ '{"additionalProperties":{"type":"string"},"type":"object"}'
1833
+ in metadata_arg.description
1834
+ )
1835
 
1836
  threshold_arg = args_by_name["threshold"]
1837
+ assert threshold_arg.description is not None
1838
+ assert (
1839
+ "Provide as a JSON string matching the following schema:"
1840
+ in threshold_arg.description
1841
+ )
1842
  assert '{"type":"number"}' in threshold_arg.description
1843
 
1844
  async def test_get_prompt(self):