onboarding_protocols: Dict[str, protocol.RawProtocol] = {
protocol_path.stem: read_protocol(protocol_path)
for protocol_path in onboarding_protocols_path.glob('*.json')
}
error:misplaced type annotationSeems like a problem in https://github.com/python/typed_ast
I cannot reproduce this. Maybe there is something else you didn't mention?
Here it is from the beginning of the file (excluding imports):
file_path = Path(__file__)
protocol_schema_path = file_path.parent / "slim_chronic_protocol.schema.json"
onboarding_protocols_path = file_path.parent / 'slim_chronic_onboarding_protocols'
preshare_protocols_path = file_path.parent / 'slim_chronic_preshare_protocols'
with protocol_schema_path.open() as file:
protocol_schema = json.load(file)
protocol_validator = Draft6Validator(protocol_schema)
def read_protocol(protocol_path: Path) -> protocol.RawProtocol:
with protocol_path.open() as file:
raw_protocol = json.load(file)
protocol_validator.validate(raw_protocol)
return raw_protocol
onboarding_protocols: Dict[str, protocol.RawProtocol] = {
protocol_path.stem: read_protocol(protocol_path)
for protocol_path in onboarding_protocols_path.glob('*.json')
}
preshare_protocols: Dict[str, protocol.RawProtocol] = {
protocol_path.stem: read_protocol(protocol_path)
for protocol_path in preshare_protocols_path.glob('*.json')
}
I just tried this, and this works perfectly. What is the version of typed_ast you have?
1.1.0
And on what line exactly do you get the error?
I get the error on the line before preshare_protocols
Are you sure you get the error in this file? Maybe you have a file with a similar name or foo.py vs foo/__init__.py confusion?
@iddan I think we're not going to get to the bottom of this until you post a completely self-contained repro, something that anybody can copy/paste into a file and run mypy over.
This is a company secret closed source.
So you cannot boil it down to something you can share? Then we have to close this issue.
It was another file. I have no idea why it wasn't reported in VSCode for the wrong location.
Discovered by running mypy from the CLI
So it seems like commented out code is failing:
# @attrs(auto_attribs=True)
# class Attribute:
# id: str
# name: str
# values: List[Value] = attrib(convert=partial(convert_, Value))
# type: str = attrib(convert=lambda t: t if isinstance(t, str) else t.name)
#
# def __contains__(self, item):
# return item in self.__dict__
#
# def __getitem__(self, item):
# return self.__dict__[item]
And this is expected, because on line 6 of your snippet there is
# type: str
which is a type comment.
You can just put two comment signs to suppress this ## type: str is a normal comment again.
It will be good if this syntax would be prohibited eventually