misc: Proper type check and import for PortRef
misc: Proper type check and import for PortRef

Rewriting the type checking around PortRef, which was interacting strangely
with other Python scripts.

Tested-by: 8f2da5ceb94d8d84a6f30868a6e1cd1ab8c9fd9e@arm.com

qizenguf/MLC-STT,powerjg/gem5-ci-test,sobercoder/gem5,briancoutinho0905/2dsampling,sobercoder/gem5,Weil0ng/gem5,gedare/gem5,gem5/gem5,markoshorro/gem5,kaiyuanl/gem5,qizenguf/MLC-STT,kaiyuanl/gem5,TUD-OS/gem5-dtu,austinharris/gem5-riscv,Weil0ng/gem5,powerjg/gem5-ci-test,gem5/gem5,sobercoder/gem5,HwisooSo/gemV-update,zlfben/gem5,markoshorro/gem5,powerjg/gem5-ci-test,qizenguf/MLC-STT,austinharris/gem5-riscv,briancoutinho0905/2dsampling,zlfben/gem5,austinharris/gem5-riscv,sobercoder/gem5,austinharris/gem5-riscv,rallylee/gem5,qizenguf/MLC-STT,TUD-OS/gem5-dtu,briancoutinho0905/2dsampling,rallylee/gem5,gedare/gem5,HwisooSo/gemV-update,austinharris/gem5-riscv,cancro7/gem5,KuroeKurose/gem5,sobercoder/gem5,KuroeKurose/gem5,rjschof/gem5,aclifton/cpeg853-gem5,powerjg/gem5-ci-test,briancoutinho0905/2dsampling,gedare/gem5,briancoutinho0905/2dsampling,zlfben/gem5,TUD-OS/gem5-dtu,kaiyuanl/gem5,cancro7/gem5,KuroeKurose/gem5,HwisooSo/gemV-update,kaiyuanl/gem5,cancro7/gem5,SanchayanMaity/gem5,gem5/gem5,rallylee/gem5,TUD-OS/gem5-dtu,HwisooSo/gemV-update,TUD-OS/gem5-dtu,sobercoder/gem5,HwisooSo/gemV-update,gedare/gem5,markoshorro/gem5,powerjg/gem5-ci-test,powerjg/gem5-ci-test,aclifton/cpeg853-gem5,SanchayanMaity/gem5,zlfben/gem5,zlfben/gem5,cancro7/gem5,zlfben/gem5,SanchayanMaity/gem5,HwisooSo/gemV-update,briancoutinho0905/2dsampling,HwisooSo/gemV-update,rjschof/gem5,qizenguf/MLC-STT,aclifton/cpeg853-gem5,TUD-OS/gem5-dtu,rjschof/gem5,aclifton/cpeg853-gem5,Weil0ng/gem5,Weil0ng/gem5,kaiyuanl/gem5,KuroeKurose/gem5,rallylee/gem5,cancro7/gem5,markoshorro/gem5,aclifton/cpeg853-gem5,KuroeKurose/gem5,kaiyuanl/gem5,gedare/gem5,austinharris/gem5-riscv,rallylee/gem5,gem5/gem5,rjschof/gem5,SanchayanMaity/gem5,markoshorro/gem5,rallylee/gem5,qizenguf/MLC-STT,sobercoder/gem5,rjschof/gem5,gem5/gem5,gem5/gem5,Weil0ng/gem5,zlfben/gem5,austinharris/gem5-riscv,SanchayanMaity/gem5,qizenguf/MLC-STT,kaiyuanl/gem5,cancro7/gem5,rallylee/gem5,Weil0ng/gem5,KuroeKurose/gem5,aclifton/cpeg853-gem5,aclifton/cpeg853-gem5,cancro7/gem5,markoshorro/gem5,SanchayanMaity/gem5,KuroeKurose/gem5,gedare/gem5,briancoutinho0905/2dsampling,TUD-OS/gem5-dtu,rjschof/gem5,markoshorro/gem5,powerjg/gem5-ci-test,rjschof/gem5,SanchayanMaity/gem5,gem5/gem5,Weil0ng/gem5,gedare/gem5