Closed adrian-herscu closed 2 weeks ago
Could you give me an example?
Could you give me an example?
from objprint import *
@add_objprint
class Goo:
f1: int = 2
f2: str = "kuku"
# ISSUE: pylance error: "Expected 1 more positional argument"
o = Goo()
# ISSUE: f1 is not recognized as a field of o, but printed
print(o.f1)
Both issues disapear if @add_objprint
is removed.
When adding add_objprint to a class, it severely interferes with the (pylance) type checker.
@adrian-herscu This only happens when pylance
extension setting Python->Analysis: Type Checking Mode
isn't a default option (off).
@gaogaotiantian Simply check the source code find, the main reason cased by typing.Callable
for return value.
def add_objprint(
orig_class: Optional[Type] = None,
format: str = "string", **kwargs) -> Union[Type, Callable[[Type], Type]]:
pass
# change
def add_objprint(
orig_class: Optional[Type] = None,
format: str = "string", **kwargs) -> Union[Type, Callable]:
pass
Strong constraints can cause errors in pylance. It can be constraint not hint. Second, python dynamic interpretation may not be able to identify which class it is and what attribute it contains.
Thanks for the investigation, but the solution is not ideal. Removing [[Type], Type]
may fix the error temporarily but it's not the right fix. The problem is the Union
and we should overload it. I'll fix it, thanks!
Fixed in #113
When adding add_objprint to a class, it severely interferes with the (pylance) type checker.