11#!/usr/bin/python3
22
33import logging
4- from typing import Any , Deque , Final
4+ from typing import Any , Deque , Final , cast
55
66import semantic_version
77import solcast
6060_BINOPS_PARAMS : Final = {"nodeType" : "BinaryOperation" , "typeDescriptions.typeString" : "bool" }
6161
6262
63+ def _to_brownie_version (version : Any ) -> semantic_version .Version :
64+ if isinstance (version , Version ):
65+ return version
66+ return Version (str (version ))
67+
68+
6369def get_version () -> semantic_version .Version :
64- return solcx .get_solc_version (with_commit_hash = True )
70+ return _to_brownie_version ( solcx .get_solc_version (with_commit_hash = True ) )
6571
6672
6773def compile_from_input_json (
@@ -96,7 +102,7 @@ def compile_from_input_json(
96102 print (f" EVM Version: { settings ['evmVersion' ].capitalize ()} " )
97103
98104 try :
99- return solcx .compile_standard (input_json , allow_paths = allow_paths )
105+ return solcx .compile_standard (cast ( dict [ Any , Any ], input_json ) , allow_paths = allow_paths )
100106 except solcx .exceptions .SolcError as e :
101107 raise CompilerError (e , "solc" )
102108
@@ -108,22 +114,22 @@ def set_solc_version(version: VersionSpec) -> str:
108114 if version < Version ("0.4.22" ):
109115 raise IncompatibleSolcVersion ("Brownie only supports Solidity versions >=0.4.22" )
110116 try :
111- solcx .set_solc_version (version , silent = True )
117+ solcx .set_solc_version (str ( version ) , silent = True )
112118 except solcx .exceptions .SolcNotInstalled :
113119 if version not in _get_solc_version_list ()[0 ]:
114120 raise IncompatibleSolcVersion (
115121 f"Cannot install Solidity v{ version } on this OS. You may be able to "
116122 f"manually compile from source with `solcx.compile_solc('{ version } ')`"
117123 )
118124 install_solc (version )
119- solcx .set_solc_version (version , silent = True )
125+ solcx .set_solc_version (str ( version ) , silent = True )
120126 return str (solcx .get_solc_version ())
121127
122128
123129def install_solc (* versions : VersionSpec ) -> None :
124130 """Installs solc versions."""
125131 for version in versions :
126- solcx .install_solc (version , show_progress = False )
132+ solcx .install_solc (str ( version ) , show_progress = False )
127133
128134
129135def get_abi (contract_source : str , allow_paths : str | None = None ) -> dict [str , list [ABIElement ]]:
@@ -192,7 +198,7 @@ def find_solc_versions(
192198 # install new versions if needed
193199 if to_install :
194200 install_solc (* to_install )
195- installed_versions = solcx .get_installed_solc_versions ()
201+ installed_versions = [ _to_brownie_version ( i ) for i in solcx .get_installed_solc_versions ()]
196202 elif new_versions and not silent :
197203 print (
198204 f"New compatible solc version{ 's' if len (new_versions ) > 1 else '' } "
@@ -255,10 +261,14 @@ def find_best_solc_version(
255261
256262def _get_solc_version_list () -> tuple [VersionList , VersionList ]:
257263 global AVAILABLE_SOLC_VERSIONS
258- installed_versions : VersionList = solcx .get_installed_solc_versions ()
264+ installed_versions : VersionList = [
265+ _to_brownie_version (i ) for i in solcx .get_installed_solc_versions ()
266+ ]
259267 if AVAILABLE_SOLC_VERSIONS is None :
260268 try :
261- AVAILABLE_SOLC_VERSIONS = solcx .get_installable_solc_versions ()
269+ AVAILABLE_SOLC_VERSIONS = [
270+ _to_brownie_version (i ) for i in solcx .get_installable_solc_versions ()
271+ ]
262272 except ConnectionError :
263273 if not installed_versions :
264274 raise ConnectionError ("Solc not installed and cannot connect to GitHub" )
0 commit comments