Closed r-priyam closed 3 years ago
Thanks for the bug report. This was already reported in the pyright issue tracker, and I've implemented a fix. It will be included in the next release of pylance.
Thanks for the bug report. This was already reported in the pyright issue tracker, and I've implemented a fix. It will be included in the next release of pylance.
Cheers Eric, Thank you!
This issue has been fixed in version 2021.10.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2021102-20-october-2021
Pylance version :v2021.12.2 "module cannot be used as a type" appears in List element type.
@Heroyuki, datetime
is a module. I think you mean to reference the class, which is datetime.datetime
.
@erictraut Thanks, it solved. m( )m
from PIL import Image
from torchvision.transforms.functional import to_tensor
import torch
def process_PIL(pil_img: Image) -> torch.Tensor:
pil_img = pil_img.resize((224, 224))
pil_img = pil_img.convert("RGB") # needed to avoid grayscale
return to_tensor(pil_img)
I get Module cannot be used as a typePylance[reportGeneralTypeIssues](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportGeneralTypeIssues) (module) Image
the quick fix isn't useful, how do I solve this?
@franchesoni, PIL.Image
is a module, not a class. If you change your first line of code to from PIL.Image import Image
, it will work fine.
import os
import sys
class HousingException(Exception):
def __init__(self,error_message:Exception,error_detail:sys):
super().__init__(error_message)
self.error_message=self.get_detailed_error_message(error_message=error_message,error_detail=error_detail)
@staticmethod
def get_detailed_error_message(error_message:Exception,error_detail:sys)->str:
"""
error_message :Exception OBJECT
error_details : object of sys module
"""
_,_,exec_tb = error_detail.exc_info()
line_number=exec_tb.tb_frame.f_lineno
file_name= exec_tb.tb_frame.f_code.co_filename
error_message = f"Error occured in scrip : [{file_name}] at line number : [{line_number}] error message :[{error_message }]"
return error_message
def __str__(self):
return self.error_message
def __repr__(self) ->str:
return HousingException.__name__.str()
How to solve this
![Uploading custom exception.png…]()
Current version -
2021.10.1
This used to work fine on version -2021.10.0