internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: d2l-ai/d2l-en

Issue:
ModuleNotFoundError when running the official pytorch colab notebook
![image](https://user-images.githubusercontent.com/33608782/184685789-951935c7-1725-4a23-944d-8d48b32bf76c.png)

I can replicate the error at multiple official pytorch colab notebooks, e.g. 

https://colab.research.google.com/github/d2l-ai/d2l-pytorch-colab/blob/master/chapter_linear-classification/image-classification-dataset.ipynb#scrollTo=ee445cce





Discussion:
As a result, all of the following code cells cannot run because the the name 'd2l' is not defined. 

For example,

![image](https://user-images.githubusercontent.com/33608782/184687484-f918a909-6bf4-4640-920f-84aea2c5cb1e.png)

Thanks for the report @gab-chen. This is quite weird. I was able to reproduce the problem on all the frameworks. 

Just two days ago, I was testing the same notebook on colab to fix #2247. It seems like colab has dropped `matplotlib_inline` package support or I'm missing something here. This will then need a manual install or adding it as a dep in d2l.

cc @astonzhang 
> Thanks for the report @gab-chen. This is quite weird. I was able to reproduce the problem on all the frameworks.
> 
> Just two days ago, I was testing the same notebook on colab to fix #2247. It seems like colab has dropped `matplotlib_inline` package support or I'm missing something here. This will then need a manual install or adding it as a dep in d2l.
> 
> cc @astonzhang

Thanks for your prompt response. 
I confirm that yesterday I could import `d2l` and run the official pytorch notebooks without any error. 
For anyone who is blocked by the error, 
you can manually install like below to avoid the error. 
`!pip install matplotlib-inline`
![image](https://user-images.githubusercontent.com/33608782/184924270-b1cfd6b1-c48e-4120-bb91-7a077d990388.png)


But it is time-consuming and error-prone to update all of the D2L pytorch notebooks on reader side. 
@AnirudhDagar Please consider adding it as a dep in d2l ASAP.
@gab-chen we'll try to fix this in our next release, maybe we can create a patch release this week to fix this problem. @astonzhang WDYT?

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -2,10 +2,10 @@
 import d2l
 
 requirements = [
-    'ipython>=7.23',
     'jupyter',
     'numpy',
     'matplotlib',
+    'matplotlib-inline',
     'requests',
     'pandas',
     'gym'


Test patch:
Repository: browniebroke/django-codemod

Issue:
Extra trailing comma when import removed is the last one
### Description

If the import to be removed is the last one of the line, but the new import already exists, and extra tariling comma is left at the end:

```
from django.utils.translation import ngettext_lazy, ungettext_lazy
```

Run `UNGetTextLazyToNGetTextLazyCommand` will give:

```
from django.utils.translation import ngettext_lazy,
```

We should not have the comma hanging at the end.


Discussion:

Resolving patch:
diff --git a/django_codemod/visitors/base.py b/django_codemod/visitors/base.py
--- a/django_codemod/visitors/base.py
+++ b/django_codemod/visitors/base.py
@@ -11,6 +11,7 @@
     Name,
     RemoveFromParent,
     Arg,
+    MaybeSentinel,
 )
 from libcst._nodes.statement import ImportFrom, BaseSmallStatement
 from libcst.codemod import ContextAwareTransformer
@@ -61,7 +62,7 @@ def leave_ImportFrom(
     ) -> Union[BaseSmallStatement, RemovalSentinel]:
         if self._test_import_from(updated_node):
             new_names = []
-            for import_alias in original_node.names:
+            for import_alias in updated_node.names:
                 if import_alias.evaluated_name == self.old_name:
                     as_name = (
                         import_alias.asname.name.value if import_alias.asname else None
@@ -76,8 +77,13 @@ def leave_ImportFrom(
                     new_names.append(import_alias)
             if not new_names:
                 return RemoveFromParent()
-            new_names = list(sorted(new_names, key=lambda n: n.evaluated_name))
-            return ImportFrom(module=updated_node.module, names=new_names)
+            # sort imports
+            new_names = sorted(new_names, key=lambda n: n.evaluated_name)
+            # remove any trailing commas
+            last_name = new_names[-1]
+            if last_name.comma != MaybeSentinel.DEFAULT:
+                new_names[-1] = last_name.with_changes(comma=MaybeSentinel.DEFAULT)
+            return updated_node.with_changes(names=new_names)
         return super().leave_ImportFrom(original_node, updated_node)
 
     def leave_Call(self, original_node: Call, updated_node: Call) -> BaseExpression:


Test patch:
diff --git a/tests/commands/test_django_40.py b/tests/commands/test_django_40.py
--- a/tests/commands/test_django_40.py
+++ b/tests/commands/test_django_40.py
@@ -82,6 +82,20 @@ def test_lambda_no_value(self) -> None:
         """
         self.assertCodemod(before, after)
 
+    def test_extra_trailing_comma_when_last(self) -> None:
+        """Extra trailing comma when removed import is the last one."""
+        before = """
+            from django.utils.encoding import force_str, force_text
+
+            result = force_text(content)
+        """
+        after = """
+            from django.utils.encoding import force_str
+
+            result = force_str(content)
+        """
+        self.assertCodemod(before, after)
+
 
 class TestSmartTextToForceStrCommand(CodemodTest):
Repository: crytic/slither

Issue:
Handle multiple files
Would be nice to run batch analyses

```bash
$ slither contracts/*.sol
usage: slither.py contract.sol [flag]
slither: error: unrecognized arguments: contracts/B.sol contracts/C.sol ...
```


Discussion:
Ah, noted it can take a single directory e.g. `slither contracts/`

This however doesn't work if the directories are heirarchical. Slither does not recurse down to see if there are any files below it.

I prefer globbing in bash (`slither **/*.sol`) over handling it inside Python, but that's a personal preference

Resolving patch:
diff --git a/slither/__main__.py b/slither/__main__.py
--- a/slither/__main__.py
+++ b/slither/__main__.py
@@ -184,12 +184,16 @@ def main_impl(all_detector_classes, all_printer_classes):
     try:
         filename = args.filename
 
+        globbed_filenames = glob.glob(filename, recursive=True)
+
         if os.path.isfile(filename):
             (results, number_contracts) = process(filename, args, detector_classes, printer_classes)
 
-        elif os.path.isdir(filename):
+        elif os.path.isdir(filename) or len(globbed_filenames) > 0:
             extension = "*.sol" if not args.solc_ast else "*.json"
             filenames = glob.glob(os.path.join(filename, extension))
+            if len(filenames) == 0:
+                filenames = globbed_filenames
             number_contracts = 0
             results = []
             for filename in filenames:


Test patch:
Repository: crytic/slither

Issue:
Add local truffle compile alternative
Currently slither does runs `truffle compile` before running.
If there is no system or global truffle installed, it fails:
```
matt@delleite:audit/ (master*) $ slither . 
INFO:Slither:truffle compile running...
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/slither_analyzer-0.3.1-py3.7.egg/slither/__main__.py", line 229, in main_impl                                                          
    (results, number_contracts) = process_truffle(filename, args, detector_classes, printer_classes)                                                                            
  File "/usr/lib/python3.7/site-packages/slither_analyzer-0.3.1-py3.7.egg/slither/__main__.py", line 64, in process_truffle                                                     
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/usr/lib/python3.7/subprocess.py", line 769, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.7/subprocess.py", line 1516, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'truffle': 'truffle'
```
Add the option to run `npx truffle compile` instead of just `truffle compile`.


Discussion:

Resolving patch:
diff --git a/slither/__main__.py b/slither/__main__.py
--- a/slither/__main__.py
+++ b/slither/__main__.py
@@ -59,7 +59,7 @@ def _process(slither, detector_classes, printer_classes):
     return results, analyzed_contracts_count
 
 def process_truffle(dirname, args, detector_classes, printer_classes):
-    cmd = ['truffle','compile']
+    cmd =  ['npx','truffle','compile'] if args.truffle_local else ['truffle','compile']
     logger.info('truffle compile running...')
     process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
@@ -356,6 +356,10 @@ def parse_args(detector_classes, printer_classes):
                             help='Export results as JSON',
                             action='store',
                             default=None)
+    group_misc.add_argument('--truffle-local',
+                            help='Truffle local execution with npx',
+                            action='store_true',
+                            default=False)
 
 
 


Test patch:
Repository: crytic/slither

Issue:
Slither crashes when parsing hexadecimal unit denominations
The following contract will crash slither:
```
contract C {
	function f() public {
		uint x = 0x07 ether;
	}
}
```

Stack trace:
```
ERROR:root:Traceback (most recent call last):
  File "c:\users\vyper\documents\github\slither\slither\__main__.py", line 250, in main_impl
    (results, number_contracts) = process(filename, args, detector_classes, printer_classes)
  File "c:\users\vyper\documents\github\slither\slither\__main__.py", line 35, in process
    slither = Slither(filename, args.solc, args.disable_solc_warnings, args.solc_args, ast)
  File "c:\users\vyper\documents\github\slither\slither\slither.py", line 41, in __init__
    self._analyze_contracts()
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 206, in _analyze_contracts
    self._analyze_third_part(contracts_to_be_analyzed, libraries)
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 290, in _analyze_third_part
    self._analyze_variables_modifiers_functions(contract)
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\slitherSolc.py", line 330, in _analyze_variables_modifiers_functions
    contract.analyze_content_functions()
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\declarations\contract.py", line 360, in analyze_content_functions
    function.analyze_content()
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\declarations\function.py", line 827, in analyze_content
    local_vars.analyze(self)
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\variables\variable_declaration.py", line 157, in analyze
    self._initial_expression = parse_expression(self._initializedNotParsed, caller_context)
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\expressions\expression_parsing.py", line 421, in parse_expression
    value = str(convert_subdenomination(value, expression['attributes']['subdenomination']))
  File "c:\users\vyper\documents\github\slither\slither\solc_parsing\expressions\expression_parsing.py", line 244, in convert_subdenomination
    value = float(value)
ValueError: could not convert string to float: '0x07'
```


Discussion:

Resolving patch:
diff --git a/slither/solc_parsing/expressions/expression_parsing.py b/slither/solc_parsing/expressions/expression_parsing.py
--- a/slither/solc_parsing/expressions/expression_parsing.py
+++ b/slither/solc_parsing/expressions/expression_parsing.py
@@ -241,7 +241,10 @@ def convert_subdenomination(value, sub):
     if sub is None:
         return value
     # to allow 0.1 ether conversion
-    value = float(value)
+    if value[0:2] == "0x":
+        value = float(int(value, 16))
+    else:
+        value = float(value)
     if sub == 'wei':
         return int(value)
     if sub == 'szabo':


Test patch:
Repository: crytic/slither

Issue:
Error when parsing type which refers to an aliased import
The following contracts will cause slither to error:

Main.sol:
```
import {Dependency as x} from "./Dependency.sol";

contract Main {
    x y;
}
```

Dependency.sol:
```
contract Dependency {
    uint y;
}
```

Error:
```
ERROR:TypeParsing:Type not found x
```


Discussion:

Resolving patch:
diff --git a/slither/solc_parsing/solidity_types/type_parsing.py b/slither/solc_parsing/solidity_types/type_parsing.py
--- a/slither/solc_parsing/solidity_types/type_parsing.py
+++ b/slither/solc_parsing/solidity_types/type_parsing.py
@@ -160,7 +160,10 @@ def parse_type(t, caller_context):
     elif t[key] == 'UserDefinedTypeName':
         if is_compact_ast:
             return _find_from_type_name(t['typeDescriptions']['typeString'], contract, contracts, structures, enums)
-        return _find_from_type_name(t['attributes'][key], contract, contracts, structures, enums)
+
+        # Determine if we have a type node (otherwise we use the name node, as some older solc did not have 'type').
+        type_name_key = 'type' if 'type' in t['attributes'] else key
+        return _find_from_type_name(t['attributes'][type_name_key], contract, contracts, structures, enums)
 
     elif t[key] == 'ArrayTypeName':
         length = None


Test patch:
Repository: crytic/slither

Issue:
Slither errors when parsing for loop without initialization and condition
The following contract will cause slither to throw an error:
```
contract C {
    function f() public {
        uint x; 
        for (;; x++) {

        }
    }
}
```
Adding either initialization or condition will not cause slither to error.

Note: The variable `x` and the iteration operation `x++` is not required to recreate this issue. 

Error:
```
ERROR:ExpressionParsing:Expression not parsed Block
```


Discussion:

Resolving patch:
diff --git a/slither/solc_parsing/declarations/function.py b/slither/solc_parsing/declarations/function.py
--- a/slither/solc_parsing/declarations/function.py
+++ b/slither/solc_parsing/declarations/function.py
@@ -257,15 +257,27 @@ def _parse_for(self, statement, node):
         # if the loop has a init value /condition or expression
         # There is no way to determine that for(a;;) and for(;a;) are different with old solc
         if 'attributes' in statement:
+            attributes = statement['attributes']
             if 'initializationExpression' in statement:
                 if not statement['initializationExpression']:
                     hasInitExession = False
+            elif 'initializationExpression' in attributes:
+                if not attributes['initializationExpression']:
+                    hasInitExession = False
+
             if 'condition' in statement:
                 if not statement['condition']:
                     hasCondition = False
+            elif 'condition' in attributes:
+                if not attributes['condition']:
+                    hasCondition = False
+
             if 'loopExpression' in statement:
                 if not statement['loopExpression']:
                     hasLoopExpression = False
+            elif 'loopExpression' in attributes:
+                if not attributes['loopExpression']:
+                    hasLoopExpression = False
 
 
         node_startLoop = self._new_node(NodeType.STARTLOOP, statement['src'])


Test patch:
Repository: crytic/slither

Issue:
Truffle compile interop fails on Windows
Slither fails to run `truffle compile` on Windows:

Command: 
```
slither .
```
Output:
```
INFO:Slither:'truffle compile' running (use --truffle-version truffle@x.x.x to use specific version)
ERROR:root:Error in .
ERROR:root:Traceback (most recent call last):
  File "c:\users\vyper\documents\github\slither\slither\__main__.py", line 471, in main_impl
    (results, number_contracts) = process_truffle(filename, args, detector_classes, printer_classes)
  File "c:\users\vyper\documents\github\slither\slither\__main__.py", line 87, in process_truffle
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\Users\Vyper\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 769, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Vyper\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1172, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
```

If `truffle compile` is run manually, and the `truffle compile` code is disabled in slither, analysis will succeed, so it can probably be assumed that the `subprocess.Popen` command is only blocking issue.

NOTE: `truffle` is in the Windows path.


Discussion:

Resolving patch:
diff --git a/slither/__main__.py b/slither/__main__.py
--- a/slither/__main__.py
+++ b/slither/__main__.py
@@ -6,6 +6,7 @@
 import json
 import logging
 import os
+import platform
 import subprocess
 import sys
 import traceback
@@ -76,8 +77,13 @@ def _process(slither, detector_classes, printer_classes):
     return results, analyzed_contracts_count
 
 def process_truffle(dirname, args, detector_classes, printer_classes):
+    # Truffle on windows has naming conflicts where it will invoke truffle.js directly instead
+    # of truffle.cmd (unless in powershell or git bash). The cleanest solution is to explicitly call
+    # truffle.cmd. Reference:
+    # https://truffleframework.com/docs/truffle/reference/configuration#resolving-naming-conflicts-on-windows
     if not args.ignore_truffle_compile:
-        cmd = ['truffle', 'compile']
+        truffle_base_command = "truffle" if platform.system() != 'Windows' else "truffle.cmd"
+        cmd = [truffle_base_command, 'compile']
         if args.truffle_version:
             cmd = ['npx',args.truffle_version,'compile']
         elif os.path.isfile('package.json'):


Test patch:
Repository: crytic/slither

Issue:
Bug in function-id printer
Hi there! There is an issue connected to `function-id` printer that I faced:

when you create a dynamic array with `public` visibility modifier compiler automatically generates a getter-function with `uint256` input parameter. However, Slither thinks that the getter has no input parameters. Thus, the wrong function signature is printed in the output.

Here is a small example.

```
pragma solidity 0.5.7;

contract Example {
    uint256[] public example;
}
```

Slither outputs the following table: 

```
+-----------+------------+
|    Name   |     ID     |
+-----------+------------+
| example() | 0x54353f2f |
+-----------+------------+
```

However, the real `example()` function's signature is `0x477e4a02` in the example.


Discussion:
Thank you @sobolev-igor for reporting the issue. We are going to fix the printer

Resolving patch:
diff --git a/slither/printers/summary/function_ids.py b/slither/printers/summary/function_ids.py
--- a/slither/printers/summary/function_ids.py
+++ b/slither/printers/summary/function_ids.py
@@ -3,6 +3,8 @@
 """
 import collections
 from prettytable import PrettyTable
+
+from slither.core.solidity_types import ArrayType, MappingType
 from slither.printers.abstract_printer import AbstractPrinter
 from slither.utils.colors import blue, green, magenta
 from slither.utils.function import get_function_id
@@ -30,7 +32,18 @@ def output(self, _filename):
                     table.add_row([function.full_name, hex(get_function_id(function.full_name))])
             for variable in contract.state_variables:
                 if variable.visibility in ['public']:
-                    table.add_row([variable.name+'()', hex(get_function_id(variable.name+'()'))])
+                    variable_getter_args = ""
+                    if type(variable.type) is ArrayType:
+                        length = 0
+                        v = variable
+                        while type(v.type) is ArrayType:
+                            length += 1
+                            v = v.type
+                        variable_getter_args = ','.join(["uint256"]*length)
+                    elif type(variable.type) is MappingType:
+                        variable_getter_args = variable.type.type_from
+
+                    table.add_row([f"{variable.name}({variable_getter_args})", hex(get_function_id(f"{variable.name}({variable_getter_args})"))])
             txt += str(table) + '\n'
 
         self.info(txt)


Test patch:
Repository: crytic/slither

Issue:
solc-version detector: Missing 0.5.11 
`0.5.11` is incorrectly reported as an old version. 


Discussion:

Resolving patch:
diff --git a/slither/detectors/attributes/incorrect_solc.py b/slither/detectors/attributes/incorrect_solc.py
--- a/slither/detectors/attributes/incorrect_solc.py
+++ b/slither/detectors/attributes/incorrect_solc.py
@@ -43,7 +43,7 @@ class IncorrectSolc(AbstractDetector):
     # Indicates the allowed versions.
     ALLOWED_VERSIONS = ["0.4.25", "0.4.26", "0.5.3"]
     # Indicates the versions too recent.
-    TOO_RECENT_VERSIONS = ["0.5.4", "0.5.7", "0.5.8", "0.5.9", "0.5.10"]
+    TOO_RECENT_VERSIONS = ["0.5.4", "0.5.7", "0.5.8", "0.5.9", "0.5.10", "0.5.11"]
     # Indicates the versions that should not be used.
     BUGGY_VERSIONS = ["0.4.22", "0.5.5", "0.5.6", "^0.4.22", "^0.5.5", "^0.5.6"]
 


Test patch:
Repository: crytic/slither

Issue:
slither-flat does not handle cycle 
Example:
```
$ echo a.sol
import './b.sol';

contract A{

    B b;

}
$ echo b.sol
import './a.sol';

contract B{

    A a;

}
```
slither-flat does not handle cycle 
Example:
```
$ echo a.sol
import './b.sol';

contract A{

    B b;

}
$ echo b.sol
import './a.sol';

contract B{

    A a;

}
```


Discussion:

Resolving patch:
diff --git a/slither/tools/flattening/flattening.py b/slither/tools/flattening/flattening.py
--- a/slither/tools/flattening/flattening.py
+++ b/slither/tools/flattening/flattening.py
@@ -93,6 +93,7 @@ def _export_from_type(self, t, contract, exported, list_contract):
     def _export_contract(self, contract, exported, list_contract):
         if contract.name in exported:
             return
+        exported.add(contract.name)
         for inherited in contract.inheritance:
             self._export_contract(inherited, exported, list_contract)
 
@@ -121,9 +122,6 @@ def _export_contract(self, contract, exported, list_contract):
                         self._export_contract(ir.contract_created, exported, list_contract)
                 if isinstance(ir, TypeConversion):
                     self._export_from_type(ir.type, contract, exported, list_contract)
-        if contract.name in exported:
-            return
-        exported.add(contract.name)
         list_contract.append(self._source_codes[contract])
 
     def _export(self, contract, ret):


Test patch: