Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add major language support, update boolean_attributes, and add dynami…
…c attribute tests
  • Loading branch information
HasTheDev committed Apr 11, 2026
commit 4b01bd179aeac43e0011d4bfa283bc8267315760
38 changes: 37 additions & 1 deletion src/typecode/contenttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ class Type(object):
"is_filesystem",
"is_java_class",
"is_java_source",
"is_julia_source",
"is_python_source",
"is_javascript_source",
"is_cpp_source",
"is_rust_source",
"is_go_source",
"is_media",
"is_media_with_meta",
"is_office_doc",
Expand Down Expand Up @@ -743,7 +749,17 @@ def is_source(self):
return False

# Recognize "known-by-extension" source types
elif self.is_java_source or self.is_c_source or self.is_julia_source:
elif (
self.is_java_source or
self.is_c_source or
self.is_julia_source or
self.is_python_source or
self.is_javascript_source or
self.is_cpp_source or
self.is_rust_source or
self.is_go_source

):
return True

elif self.filetype_pygment or self.is_script is True:
Expand Down Expand Up @@ -772,6 +788,26 @@ def is_julia_source(self):
"""
return self.is_file and self.location.lower().endswith(".jl")

@property
def is_python_source(self):
return self.is_file and self.file_name.lower().endswith(('.py', '.pyw'))

@property
def is_javascript_source(self):
return self.is_file and self.file_name.lower().endswith(('.js', '.mjs'))

@property
def is_cpp_source(self):
return self.is_file and self.file_name.lower().endswith(('.cpp', '.cc', '.cxx', '.hpp'))

@property
def is_rust_source(self):
return self.is_file and self.file_name.lower().endswith('.rs')

@property
def is_go_source(self):
return self.is_file and self.file_name.lower().endswith('.go')

@property
def is_c_source(self):
C_EXTENSIONS = set(
Expand Down
20 changes: 20 additions & 0 deletions tests/test_contenttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,23 @@ def test_size(self):
test_dir = self.get_test_loc("contenttype/size")
result = size(test_dir)
assert result == 18

def test_contenttype_language_attributes_exist(self):
from typecode.contenttype import get_type

# Get a Type object to test against using a dummy file extension
test_type = get_type('dummy.txt')

expected_language_attributes = [
'is_c_source',
'is_java_source',
'is_julia_source',
'is_python_source',
'is_javascript_source',
'is_cpp_source',
'is_rust_source',
'is_go_source'
]

for attr_name in expected_language_attributes:
assert hasattr(test_type, attr_name), f"ContentType is missing the expected attribute: {attr_name}"
Loading