Skip to content

Commit ef49bcc

Browse files
authored
fix: better python imports regex (#215)
1 parent 89cdfad commit ef49bcc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/kotlin/app/extractors/PythonExtractor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PythonExtractor : ExtractorInterface {
2121
val docImportRegex = Regex("""^([^\n]*#|\s*\"\"\"|\s*import|\s*from)[^\n]*""")
2222
val commentRegex = Regex("""^(.*#).*""")
2323
val extractImportRegex =
24-
Regex("""(from\s+(\w+)[.\w+]*\s+import|import\s+(\w+[,\s*\w+]*))""")
24+
Regex("""(from\s+(\w+)[.\w+]*\s+import|import\s+(\w+(,\s*\w+)*))(as\s+)*""")
2525
}
2626

2727
override fun extract(files: List<DiffFile>): List<CommitStats> {
@@ -64,7 +64,7 @@ class PythonExtractor : ExtractorInterface {
6464
fileContent.forEach {
6565
val res = extractImportRegex.find(it)
6666
if (res != null) {
67-
val lineLibs = res.groupValues.last { it != "" }
67+
val lineLibs = res.groupValues.last { it != "" && !it.startsWith(',')}
6868
.split(Regex(""",\s*"""))
6969
imports.addAll(lineLibs)
7070
}

0 commit comments

Comments
 (0)