Skip to content

Commit

Permalink
chore: updated gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
JayGhiya committed Dec 20, 2024
1 parent 994c1e4 commit 53ff5a9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ unoplat-code-confluence/unoplat_code_confluence/parser/python/function_metadata/
unoplat-code-confluence/unoplat_code_confluence/parser/tree_sitter/__pycache__
unoplat-code-confluence/unoplat_code_confluence/data_models/forge_summary/__pycache__
unoplat-code-confluence/tests/utility/__pycache__
unoplat-code-confluence/.env.dev
6 changes: 2 additions & 4 deletions unoplat-code-confluence/tests/utility/test_is_class_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ def test_is_python_class_name(name: str, expected: bool):
def test_is_python_class_name_edge_cases():
"""Test edge cases for class name validation."""
# None type
with pytest.raises(AttributeError):
IsClassName.is_python_class_name(None) # type: ignore
assert not IsClassName.is_python_class_name(None) # type: ignore

# Non-string types
with pytest.raises(AttributeError):
IsClassName.is_python_class_name(123) # type: ignore
assert not IsClassName.is_python_class_name(123) # type: ignore

# Empty string
assert not IsClassName.is_python_class_name("")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from loguru import logger
import re

class IsClassName:
# Class-level regex pattern for valid Python class names
_valid_class_pattern = re.compile(r'^[A-Z][a-zA-Z0-9]*$')

@staticmethod
def is_python_class_name(name: str) -> bool:
"""Check if a name follows Python class naming convention (CamelCase).
Expand All @@ -7,22 +13,46 @@ def is_python_class_name(name: str) -> bool:
name: Name to check
Returns:
bool: True if name follows Python class naming convention
bool: True if name follows Python class naming convention.
Returns False for invalid inputs after logging error.
"""
# Handle empty string
if not name:
return False
try:
# Handle None or non-string types
if not isinstance(name, str):
logger.error(
"Invalid input type for class name check: {}\n"
"Expected str, got {}",
name, type(name).__name__
)
return False

# Handle empty string
if not name:
logger.debug("Empty string provided for class name check")
return False

# Class names should:
# 1. Start with uppercase letter
# 2. Not contain underscores (CamelCase not snake_case)
# 3. Not be all uppercase (to exclude constants)
# 4. Allow single uppercase letter (e.g., A, B, T for generics)
# 5. Not contain special characters

# Class names should:
# 1. Start with uppercase letter
# 2. Not contain underscores (CamelCase not snake_case)
# 3. Not be all uppercase (to exclude constants)
# 4. Allow single uppercase letter (e.g., A, B, T for generics)
if len(name) == 1:
return name.isupper() # Single character should be uppercase
# Handle single character case
if len(name) == 1:
return name.isupper()

# Check if name matches valid pattern and is not all uppercase
return bool(
IsClassName._valid_class_pattern.match(name) and
not name.isupper()
)

return (
name[0].isupper() and # Starts with uppercase
'_' not in name and # No underscores
not name.isupper() # Not all uppercase
)
except Exception as e:
logger.error(
"Unexpected error checking class name: {}\n"
"Input: {}\n"
"Error: {}",
name, type(name).__name__, str(e)
)
return False

0 comments on commit 53ff5a9

Please sign in to comment.