You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Janome, I expected Token class returned from Tokenizer.tokenize method has some attributes like surface, and they are str. But static analyzers like mypy cannot recognize the existence of these attributes and assume them as Any.
fromjanome.tokenizerimportTokenizert=Tokenizer()
tokens=t.tokenize("メロスは激怒した")
fortokenintokens:
print(token.surface) # <- Any
I think it comes from Token class defining dynamic attributes using __getattr__ method here:
And I think Python builtin @property can do the same thing with current __getattr__ implementation and is more type friendly and more auto completion friendly. The code example is like below:
When using Janome, I expected
Token
class returned fromTokenizer.tokenize
method has some attributes likesurface
, and they are str. But static analyzers like mypy cannot recognize the existence of these attributes and assume them as Any.I think it comes from
Token
class defining dynamic attributes using__getattr__
method here:janome/janome/tokenizer.py
Lines 121 to 139 in 9d82248
And I think Python builtin
@property
can do the same thing with current__getattr__
implementation and is more type friendly and more auto completion friendly. The code example is like below:Do you think that makes sense?
The text was updated successfully, but these errors were encountered: