Check for python content was too broad#2949
Check for python content was too broad#2949rkoumis wants to merge 3 commits intokevoreilly:masterfrom
Conversation
rkoumis
commented
Mar 18, 2026
- too many files can contain 'import', for example .eml files
- reverts part of baa0f5f
- too many files can contain 'import', for example .eml files - reverts part of baa0f5f
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the file type detection mechanism was incorrectly classifying various files as Python scripts due to an overly broad check for the presence of the 'import' keyword. By removing this generic content check, the system will now rely on more specific indicators like file extensions (.py, .pyc) or explicit 'Python script' type identification, leading to more accurate file categorization within the analyzer. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where the check for Python content was too broad, leading to incorrect file type classifications. The change removes the problematic b"import" in file_content condition, which is a valid fix. I am suggesting an improvement to this change by replacing the removed condition with a more specific content-based check for a shebang line. This would allow for the detection of Python scripts that lack a standard file extension, but in a more reliable manner that avoids the original issue of false positives.
| ) | ||
|
|
||
| if sys.platform == "win32": | ||
| from ctypes import windll |
There was a problem hiding this comment.
Tried to run some of these windows tests under linux, which isn't really a thing, but this helped (a bit)
| elif "Macromedia Flash" in file_type or file_name.endswith((".swf", ".fws")): | ||
| return "swf" | ||
| elif file_name.endswith((".py", ".pyc")) or "Python script" in file_type: | ||
| elif file_name.endswith((".py", ".pyc")) or "Python script" in file_type or (file_content.startswith(b'#!/') and b'python' in file_content.split(b'\n', 1)[0]): |
There was a problem hiding this comment.
As suggested by copilot
|
|
||
| How's it going? | ||
|
|
||
| Did you import that file I sent you last week? |
There was a problem hiding this comment.
I made sure to include the word "import" in this email
- slight tweaks to make it easier to run the tests under Linux
4ad0682 to
8e9520f
Compare
|
@doomedraven FYI, this was causing problems for users who were submitting |